Skip to content

Commit

Permalink
bumper r&r og tbd-libs
Browse files Browse the repository at this point in the history
  • Loading branch information
davidsteinsland committed Nov 12, 2024
1 parent c054674 commit b05a489
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 25 deletions.
9 changes: 5 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
val junitJupiterVersion = "5.11.3"
val testcontainersVersion = "1.19.5"
val rapidsAndRiversVersion = "2024020507581707116327.1c34df474331"
val tbdLibsVersion = "2024.05.31-08.02-2c3441c1"
val rapidsAndRiversVersion = "2024111211071731406062.648687519469"
val tbdLibsVersion = "2024.11.12-11.09-16cf2599"
val flywayVersion = "10.8.1"
val hikariCPVersion = "5.1.0"
val postgresqlVersion = "42.7.2"
Expand Down Expand Up @@ -44,10 +44,11 @@ dependencies {

testImplementation("io.mockk:mockk:$mockkVersion")

testImplementation("com.github.navikt.tbd-libs:rapids-and-rivers-test:$tbdLibsVersion")
testImplementation("org.testcontainers:postgresql:$testcontainersVersion")

testImplementation("org.junit.jupiter:junit-jupiter:$junitJupiterVersion")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")

testImplementation("org.testcontainers:postgresql:$testcontainersVersion")
}

kotlin {
Expand Down
8 changes: 4 additions & 4 deletions src/main/kotlin/no/nav/helse/spammer/App.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package no.nav.helse.spammer

import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
import com.fasterxml.jackson.module.kotlin.KotlinModule
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.github.navikt.tbd_libs.azure.AzureToken
import com.github.navikt.tbd_libs.azure.AzureTokenProvider
import com.github.navikt.tbd_libs.rapids_and_rivers_api.RapidsConnection
import com.github.navikt.tbd_libs.result_object.Result
import com.github.navikt.tbd_libs.spurtedu.SpurteDuClient
import no.nav.helse.rapids_rivers.RapidApplication
import no.nav.helse.rapids_rivers.RapidsConnection
import kotlin.time.ExperimentalTime

@ExperimentalTime
Expand All @@ -34,11 +34,11 @@ fun main() {
objectMapper = jacksonObjectMapper().registerModule(JavaTimeModule()),
tokenProvider = object : AzureTokenProvider {
// trenger egentlig ikke token provider fordi vi slår aldri opp en hemmelighet
override fun bearerToken(scope: String): AzureToken {
override fun bearerToken(scope: String): Result<AzureToken> {
TODO("Not yet implemented")
}

override fun onBehalfOfToken(scope: String, token: String): AzureToken {
override fun onBehalfOfToken(scope: String, token: String): Result<AzureToken> {
TODO("Not yet implemented")
}
}
Expand Down
12 changes: 10 additions & 2 deletions src/main/kotlin/no/nav/helse/spammer/AppStateMonitor.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
package no.nav.helse.spammer

import com.fasterxml.jackson.databind.JsonNode
import com.github.navikt.tbd_libs.rapids_and_rivers.JsonMessage
import com.github.navikt.tbd_libs.rapids_and_rivers.River
import com.github.navikt.tbd_libs.rapids_and_rivers.asLocalDateTime
import com.github.navikt.tbd_libs.rapids_and_rivers_api.MessageContext
import com.github.navikt.tbd_libs.rapids_and_rivers_api.MessageMetadata
import com.github.navikt.tbd_libs.rapids_and_rivers_api.MessageProblems
import com.github.navikt.tbd_libs.rapids_and_rivers_api.RapidsConnection
import io.micrometer.core.instrument.MeterRegistry
import no.nav.helse.rapids_rivers.*
import org.slf4j.LoggerFactory
import java.time.LocalDateTime
Expand Down Expand Up @@ -38,12 +46,12 @@ internal class AppStateMonitor(
}

private var lastReportTime = LocalDateTime.MIN
override fun onError(problems: MessageProblems, context: MessageContext) {
override fun onError(problems: MessageProblems, context: MessageContext, metadata: MessageMetadata) {
log.error(problems.toString())
sikkerLogg.error(problems.toExtendedReport())
}

override fun onPacket(packet: JsonMessage, context: MessageContext) {
override fun onPacket(packet: JsonMessage, context: MessageContext, metadata: MessageMetadata, meterRegistry: MeterRegistry) {
val now = LocalDateTime.now()
if (now.toLocalTime() in natt || lastReportTime > now.minusMinutes(15)) return // don't create alerts too eagerly
val appsDown = packet["states"]
Expand Down
14 changes: 11 additions & 3 deletions src/main/kotlin/no/nav/helse/spammer/AvstemmingMonitor.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
package no.nav.helse.spammer

import com.fasterxml.jackson.databind.JsonNode
import no.nav.helse.rapids_rivers.*
import com.github.navikt.tbd_libs.rapids_and_rivers.JsonMessage
import com.github.navikt.tbd_libs.rapids_and_rivers.River
import com.github.navikt.tbd_libs.rapids_and_rivers.asLocalDate
import com.github.navikt.tbd_libs.rapids_and_rivers.asLocalDateTime
import com.github.navikt.tbd_libs.rapids_and_rivers_api.MessageContext
import com.github.navikt.tbd_libs.rapids_and_rivers_api.MessageMetadata
import com.github.navikt.tbd_libs.rapids_and_rivers_api.MessageProblems
import com.github.navikt.tbd_libs.rapids_and_rivers_api.RapidsConnection
import io.micrometer.core.instrument.MeterRegistry
import org.slf4j.LoggerFactory
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
Expand All @@ -28,11 +36,11 @@ internal class AvstemmingMonitor(
}.register(this)
}

override fun onError(problems: MessageProblems, context: MessageContext) {
override fun onError(problems: MessageProblems, context: MessageContext, metadata: MessageMetadata) {
sikkerLog.error("forstod ikke avstemming:\n${problems.toExtendedReport()}")
}

override fun onPacket(packet: JsonMessage, context: MessageContext) {
override fun onPacket(packet: JsonMessage, context: MessageContext, metadata: MessageMetadata, meterRegistry: MeterRegistry) {
val fagområde = when (val forkortelsen = packet["fagområde"].asText()) {
"SP" -> "brukerutbetalinger ($forkortelsen)"
"SPREF" -> "arbeidsgiverrefusjoner ($forkortelsen)"
Expand Down
12 changes: 9 additions & 3 deletions src/main/kotlin/no/nav/helse/spammer/LoopMonitor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@ package no.nav.helse.spammer
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.github.navikt.tbd_libs.rapids_and_rivers.JsonMessage
import com.github.navikt.tbd_libs.rapids_and_rivers.River
import com.github.navikt.tbd_libs.rapids_and_rivers_api.MessageContext
import com.github.navikt.tbd_libs.rapids_and_rivers_api.MessageMetadata
import com.github.navikt.tbd_libs.rapids_and_rivers_api.MessageProblems
import com.github.navikt.tbd_libs.rapids_and_rivers_api.RapidsConnection
import com.github.navikt.tbd_libs.spurtedu.SkjulRequest
import com.github.navikt.tbd_libs.spurtedu.SpurteDuClient
import no.nav.helse.rapids_rivers.*
import io.micrometer.core.instrument.MeterRegistry
import org.slf4j.LoggerFactory
import java.time.LocalDateTime

Expand All @@ -25,11 +31,11 @@ internal class LoopMonitor(
}.register(this)
}

override fun onError(problems: MessageProblems, context: MessageContext) {
override fun onError(problems: MessageProblems, context: MessageContext, metadata: MessageMetadata) {
sikkerLog.error("forstod ikke vedtaksperiode_i_loop:\n${problems.toExtendedReport()}")
}

override fun onPacket(packet: JsonMessage, context: MessageContext) {
override fun onPacket(packet: JsonMessage, context: MessageContext, metadata: MessageMetadata, meterRegistry: MeterRegistry) {
val vedtaksperiodeId = packet["vedtaksperiodeId"].asText()
val forrigeTilstand = packet["forrigeTilstand"].asText()
val gjeldendeTilstand = packet["gjeldendeTilstand"].asText()
Expand Down
10 changes: 8 additions & 2 deletions src/main/kotlin/no/nav/helse/spammer/PåminnelseMonitor.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package no.nav.helse.spammer

import com.fasterxml.jackson.databind.JsonNode
import com.github.navikt.tbd_libs.rapids_and_rivers.JsonMessage
import com.github.navikt.tbd_libs.rapids_and_rivers.River
import com.github.navikt.tbd_libs.rapids_and_rivers.asLocalDateTime
import com.github.navikt.tbd_libs.rapids_and_rivers_api.MessageContext
import com.github.navikt.tbd_libs.rapids_and_rivers_api.MessageMetadata
import com.github.navikt.tbd_libs.rapids_and_rivers_api.RapidsConnection
import com.github.navikt.tbd_libs.spurtedu.SpurteDuClient
import no.nav.helse.rapids_rivers.*
import io.micrometer.core.instrument.MeterRegistry
import org.slf4j.LoggerFactory
import kotlin.time.ExperimentalTime

Expand Down Expand Up @@ -38,7 +44,7 @@ internal class PåminnelseMonitor(
}

private class Påminnelser(private val slackClient: SlackClient?, private val slackThreadDao: SlackThreadDao?, private val spurteDuClient: SpurteDuClient): River.PacketListener {
override fun onPacket(packet: JsonMessage, context: MessageContext) {
override fun onPacket(packet: JsonMessage, context: MessageContext, metadata: MessageMetadata, meterRegistry: MeterRegistry) {
if (slackThreadDao == null) return
val antallGangerPåminnet = packet["antallGangerPåminnet"].asInt()
// sørger for å lage en alarm for hver 20. påminnelse
Expand Down
13 changes: 10 additions & 3 deletions src/main/kotlin/no/nav/helse/spammer/SlackmeldingMonitor.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
package no.nav.helse.spammer

import no.nav.helse.rapids_rivers.*
import com.github.navikt.tbd_libs.rapids_and_rivers.JsonMessage
import com.github.navikt.tbd_libs.rapids_and_rivers.River
import com.github.navikt.tbd_libs.rapids_and_rivers.isMissingOrNull
import com.github.navikt.tbd_libs.rapids_and_rivers_api.MessageContext
import com.github.navikt.tbd_libs.rapids_and_rivers_api.MessageMetadata
import com.github.navikt.tbd_libs.rapids_and_rivers_api.MessageProblems
import com.github.navikt.tbd_libs.rapids_and_rivers_api.RapidsConnection
import io.micrometer.core.instrument.MeterRegistry
import org.slf4j.LoggerFactory

internal class SlackmeldingMonitor(
Expand All @@ -19,11 +26,11 @@ internal class SlackmeldingMonitor(
}.register(this)
}

override fun onError(problems: MessageProblems, context: MessageContext) {
override fun onError(problems: MessageProblems, context: MessageContext, metadata: MessageMetadata) {
sikkerLog.error("forstod ikke slackmelding:\n${problems.toExtendedReport()}")
}

override fun onPacket(packet: JsonMessage, context: MessageContext) {
override fun onPacket(packet: JsonMessage, context: MessageContext, metadata: MessageMetadata, meterRegistry: MeterRegistry) {
val melding = packet["melding"].asText()
val skalHaPrefix = packet["utenPrefix"].isMissingOrNull()
val skalHaSuffix = packet["utenSuffix"].isMissingOrNull()
Expand Down
13 changes: 10 additions & 3 deletions src/main/kotlin/no/nav/helse/spammer/UtbetalingMonitor.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
package no.nav.helse.spammer

import com.fasterxml.jackson.databind.JsonNode
import no.nav.helse.rapids_rivers.*
import com.github.navikt.tbd_libs.rapids_and_rivers.JsonMessage
import com.github.navikt.tbd_libs.rapids_and_rivers.River
import com.github.navikt.tbd_libs.rapids_and_rivers.asLocalDateTime
import com.github.navikt.tbd_libs.rapids_and_rivers_api.MessageContext
import com.github.navikt.tbd_libs.rapids_and_rivers_api.MessageMetadata
import com.github.navikt.tbd_libs.rapids_and_rivers_api.MessageProblems
import com.github.navikt.tbd_libs.rapids_and_rivers_api.RapidsConnection
import io.micrometer.core.instrument.MeterRegistry
import org.slf4j.LoggerFactory
import kotlin.time.ExperimentalTime

Expand All @@ -26,11 +33,11 @@ internal class UtbetalingMonitor(
}

private class UtbetalingFeilet(private val slackClient: SlackClient?, private val slackThreadDao: SlackThreadDao?): River.PacketListener {
override fun onError(problems: MessageProblems, context: MessageContext) {
override fun onError(problems: MessageProblems, context: MessageContext, metadata: MessageMetadata) {
sikkerLog.error("forstod ikke transaksjon_status:\n${problems.toExtendedReport()}")
}

override fun onPacket(packet: JsonMessage, context: MessageContext) {
override fun onPacket(packet: JsonMessage, context: MessageContext, metadata: MessageMetadata, meterRegistry: MeterRegistry) {
if (slackThreadDao == null) return
slackClient?.postMessage(
String.format(
Expand Down
2 changes: 1 addition & 1 deletion src/test/kotlin/no/nav/helse/spammer/LoopMonitorTest.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package no.nav.helse.spammer

import com.github.navikt.tbd_libs.rapids_and_rivers.test_support.TestRapid
import io.mockk.CapturingSlot
import io.mockk.mockk
import io.mockk.verify
import no.nav.helse.rapids_rivers.testsupport.TestRapid
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
Expand Down

0 comments on commit b05a489

Please sign in to comment.