Skip to content

Commit

Permalink
Merge pull request #34 from navikt/packet_size_metric
Browse files Browse the repository at this point in the history
Registrer summary metric for å kunne få oversikt over pakkestørrelser
  • Loading branch information
Andreas Nygård Bergh authored Jan 3, 2020
2 parents fc5d430 + 4bf9376 commit b0d6300
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ dependencies {
testImplementation(Junit5.kotlinRunner)
testImplementation(Json.library)
testRuntimeOnly(Junit5.engine)

implementation(Prometheus.common)
}

val sourcesJar by tasks.registering(Jar::class) {
Expand Down
7 changes: 7 additions & 0 deletions src/main/kotlin/no/nav/dagpenger/events/Metrics.kt
Original file line number Diff line number Diff line change
@@ -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()
5 changes: 4 additions & 1 deletion src/main/kotlin/no/nav/dagpenger/events/Packet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
8 changes: 7 additions & 1 deletion src/test/kotlin/no/nav/dagpenger/events/PacketTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<ClassB>
Expand Down

0 comments on commit b0d6300

Please sign in to comment.