diff --git a/build.gradle.kts b/build.gradle.kts index cb35894..7521b7b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -46,6 +46,8 @@ dependencies { testImplementation(Junit5.kotlinRunner) testImplementation(Json.library) testRuntimeOnly(Junit5.engine) + + implementation(Prometheus.common) } 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..0cf0d22 --- /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 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] 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