From 6bf89f80394763ec4c82d17f76fceb8010c4332b Mon Sep 17 00:00:00 2001 From: Andreas Bergh Date: Fri, 3 Jan 2020 09:25:38 +0100 Subject: [PATCH 1/4] =?UTF-8?q?Registrer=20summary=20metric=20for=20=C3=A5?= =?UTF-8?q?=20kunne=20f=C3=A5=20oversikt=20over=20pakkest=C3=B8rrelser?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I forbindelse med navikt/dagpenger#295 --- build.gradle.kts | 4 ++++ src/main/kotlin/no/nav/dagpenger/events/Metrics.kt | 7 +++++++ 2 files changed, 11 insertions(+) create mode 100644 src/main/kotlin/no/nav/dagpenger/events/Metrics.kt diff --git a/build.gradle.kts b/build.gradle.kts index cb35894..dae22aa 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -46,6 +46,10 @@ dependencies { testImplementation(Junit5.kotlinRunner) testImplementation(Json.library) testRuntimeOnly(Junit5.engine) + + implementation(Prometheus.common) + implementation(Prometheus.hotspot) + implementation(Micrometer.prometheusRegistry) } val sourcesJar by tasks.registering(Jar::class) { diff --git a/src/main/kotlin/no/nav/dagpenger/events/Metrics.kt b/src/main/kotlin/no/nav/dagpenger/events/Metrics.kt new file mode 100644 index 0000000..4e4ef56 --- /dev/null +++ b/src/main/kotlin/no/nav/dagpenger/events/Metrics.kt @@ -0,0 +1,7 @@ +package no.nav.dagpenger.events + +import io.prometheus.client.Summary + +val packetByteSize = Summary.build() + .name("packet_size_bytes") + .help("Packet size in bytes.").register() \ No newline at end of file From 08818e81557f3492bdfaef49eab319091faef9ca Mon Sep 17 00:00:00 2001 From: Andreas Bergh Date: Fri, 3 Jan 2020 09:36:18 +0100 Subject: [PATCH 2/4] fjerner ubrukte dependencies --- build.gradle.kts | 2 -- 1 file changed, 2 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index dae22aa..7521b7b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -48,8 +48,6 @@ dependencies { testRuntimeOnly(Junit5.engine) implementation(Prometheus.common) - implementation(Prometheus.hotspot) - implementation(Micrometer.prometheusRegistry) } val sourcesJar by tasks.registering(Jar::class) { From 8ccf606444dfafab9279e2fa9e5b05960bee08c5 Mon Sep 17 00:00:00 2001 From: Andreas Bergh Date: Fri, 3 Jan 2020 10:22:54 +0100 Subject: [PATCH 3/4] =?UTF-8?q?Endrer=20teller=20til=20=C3=A5=20sjekke=20p?= =?UTF-8?q?ayloadens=20st=C3=B8rrelse?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit legger også til at den faktisk sjekker størrelsen ved opprettelse --- src/main/kotlin/no/nav/dagpenger/events/Metrics.kt | 6 +++--- src/main/kotlin/no/nav/dagpenger/events/Packet.kt | 5 ++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/no/nav/dagpenger/events/Metrics.kt b/src/main/kotlin/no/nav/dagpenger/events/Metrics.kt index 4e4ef56..0cf0d22 100644 --- a/src/main/kotlin/no/nav/dagpenger/events/Metrics.kt +++ b/src/main/kotlin/no/nav/dagpenger/events/Metrics.kt @@ -2,6 +2,6 @@ package no.nav.dagpenger.events import io.prometheus.client.Summary -val packetByteSize = Summary.build() - .name("packet_size_bytes") - .help("Packet size in bytes.").register() \ No newline at end of file +val packetPayloadByteSize = Summary.build() + .name("payload_size_bytes") + .help("Packet payload size in bytes.").register() \ No newline at end of file diff --git a/src/main/kotlin/no/nav/dagpenger/events/Packet.kt b/src/main/kotlin/no/nav/dagpenger/events/Packet.kt index 4044c2d..e444b6c 100644 --- a/src/main/kotlin/no/nav/dagpenger/events/Packet.kt +++ b/src/main/kotlin/no/nav/dagpenger/events/Packet.kt @@ -49,9 +49,12 @@ class Packet constructor(jsonString: String = "{}") { System.getenv("NAIS_APP_NAME")?.let { val breadcrumb = Breadcrumb( it, - LocalDateTime.now()) + LocalDateTime.now() + ) breadcrumbs.add(breadcrumb) } + + packetPayloadByteSize.observe(jsonString.toByteArray().size.toDouble()) } private fun getValue(key: String): Any? = json[key] From 4bf93763491c84ecfb3be0a344433e3fa379a940 Mon Sep 17 00:00:00 2001 From: Andreas Bergh Date: Fri, 3 Jan 2020 16:24:30 +0100 Subject: [PATCH 4/4] =?UTF-8?q?tester=20at=20initialisering=20av=20pakken?= =?UTF-8?q?=20=C3=B8ker=20summary-teller?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/kotlin/no/nav/dagpenger/events/PacketTest.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/test/kotlin/no/nav/dagpenger/events/PacketTest.kt b/src/test/kotlin/no/nav/dagpenger/events/PacketTest.kt index 9cfa34c..4b91797 100644 --- a/src/test/kotlin/no/nav/dagpenger/events/PacketTest.kt +++ b/src/test/kotlin/no/nav/dagpenger/events/PacketTest.kt @@ -3,7 +3,6 @@ package no.nav.dagpenger.events import com.squareup.moshi.JsonEncodingException import io.kotlintest.shouldBe import org.json.JSONObject - import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertFalse import org.junit.jupiter.api.Test @@ -391,6 +390,13 @@ class PacketTest { Packet(packet.toJson()!!).getCorrelationId() shouldBe packet.getCorrelationId() } + @Test + fun `Initialization of Packet should increment summary count`() { + packetPayloadByteSize.clear() + val packet = Packet() + packetPayloadByteSize.get().count shouldBe 1.0 + } + data class ClassA( val id: String, val list: List