Skip to content

Commit

Permalink
Chore/timestamp (#397)
Browse files Browse the repository at this point in the history
* log timestamp

* add metric
  • Loading branch information
andreasDev authored Jul 2, 2024
1 parent 999c150 commit 905dad1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package no.nav.syfo.application
import io.opentelemetry.api.trace.Span
import io.opentelemetry.instrumentation.annotations.WithSpan
import java.io.StringReader
import java.time.Instant
import java.time.LocalDateTime
import java.time.OffsetTime
import java.time.ZoneOffset
import java.util.*
import javax.jms.Message
Expand Down Expand Up @@ -40,6 +42,7 @@ import no.nav.syfo.handlestatus.handleVirksomhetssykmeldingOgFnrManglerIHPR
import no.nav.syfo.handlestatus.handleVirksomhetssykmeldingOgHprMangler
import no.nav.syfo.logger
import no.nav.syfo.metrics.INCOMING_MESSAGE_COUNTER
import no.nav.syfo.metrics.INCOMING_MESSAGE_DELAY
import no.nav.syfo.metrics.REQUEST_TIME
import no.nav.syfo.metrics.SYKMELDING_MISSNG_ORG_NUMBER_COUNTER
import no.nav.syfo.metrics.SYKMELDING_VEDLEGG_COUNTER
Expand Down Expand Up @@ -116,7 +119,10 @@ class BlockingApplicationRunner(
delay(100)
continue
}
val messageTimestamp =
OffsetTime.ofInstant(Instant.ofEpochMilli(message.jmsTimestamp), ZoneOffset.UTC)

logger.info("Received message with timestamp {}", messageTimestamp)
processMqMessage(message)
}
}
Expand All @@ -135,6 +141,10 @@ class BlockingApplicationRunner(
)
}
INCOMING_MESSAGE_COUNTER.inc()
val now = Instant.now().toEpochMilli()
val delay = now - message.jmsTimestamp
INCOMING_MESSAGE_DELAY.observe(delay / 1000.0)

val requestLatency = REQUEST_TIME.startTimer()
val fellesformat = safeUnmarshal(inputMessageText)

Expand Down
8 changes: 8 additions & 0 deletions src/main/kotlin/no/nav/syfo/metrics/MetricRegistry.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
package no.nav.syfo.metrics

import io.prometheus.client.Counter
import io.prometheus.client.Histogram
import io.prometheus.client.Summary

const val METRICS_NS = "syfosmmottak"

val INCOMING_MESSAGE_DELAY: Histogram =
Histogram.build()
.namespace(METRICS_NS)
.name("incoming_message_delay")
.help("Delay in incoming messages.")
.register()

val REQUEST_TIME: Summary =
Summary.build()
.namespace(METRICS_NS)
Expand Down

0 comments on commit 905dad1

Please sign in to comment.