From 9ada5e667ec53de1998872184a60f90f7a8f3cab Mon Sep 17 00:00:00 2001 From: david steinsland Date: Fri, 29 Nov 2024 12:42:01 +0100 Subject: [PATCH] bruker naisful-app som ktor-server r&r sin ktor er plain og inneholder kun isalive, isready og metrics --- build.gradle.kts | 3 +- src/main/kotlin/no/nav/helse/spokelse/App.kt | 41 +++++++++++++++++++- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 8e9087c..7912d8c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,4 +1,4 @@ -val rapidsAndRiversVersion = "2024112511071732529266.253c42b70448" +val rapidsAndRiversVersion = "2024112911471732877250.f6df6f41226b" val tbdLibsVersion = "2024.11.25-10.59-6f263a10" val ktorVersion = "3.0.1" val postgresqlVersion = "42.7.4" @@ -18,6 +18,7 @@ plugins { dependencies { implementation("com.github.navikt:rapids-and-rivers:$rapidsAndRiversVersion") + implementation("com.github.navikt.tbd-libs:naisful-app:$tbdLibsVersion") implementation("io.ktor:ktor-server-auth-jwt:$ktorVersion") { exclude(group = "junit") } diff --git a/src/main/kotlin/no/nav/helse/spokelse/App.kt b/src/main/kotlin/no/nav/helse/spokelse/App.kt index 29b11a1..e719345 100644 --- a/src/main/kotlin/no/nav/helse/spokelse/App.kt +++ b/src/main/kotlin/no/nav/helse/spokelse/App.kt @@ -1,11 +1,22 @@ package no.nav.helse.spokelse +import com.fasterxml.jackson.databind.SerializationFeature +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule +import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.github.navikt.tbd_libs.naisful.naisApp import com.github.navikt.tbd_libs.rapids_and_rivers_api.RapidsConnection import io.ktor.client.* import io.ktor.client.engine.cio.CIO import io.ktor.server.application.* import io.ktor.server.auth.* +import io.ktor.server.auth.jwt.JWTPrincipal +import io.ktor.server.request.header import io.ktor.server.routing.* +import io.micrometer.core.instrument.Clock +import io.micrometer.prometheusmetrics.PrometheusConfig +import io.micrometer.prometheusmetrics.PrometheusMeterRegistry +import io.prometheus.metrics.model.registry.PrometheusRegistry +import no.nav.helse.rapids_rivers.NaisEndpoints import no.nav.helse.rapids_rivers.RapidApplication import no.nav.helse.spokelse.gamleutbetalinger.GamleUtbetalingerDao import no.nav.helse.spokelse.grunnlag.grunnlagApi @@ -40,11 +51,37 @@ fun launchApplication(env: Map) { val utbetaltePerioder = UtbetaltePerioder(env, HttpClient(CIO), TbdUtbetalingApi(tbdUtbetalingDao), gamleUtbetalingerDao) val tbdUtbetalingConsumer = TbdUtbetalingConsumer(env, tbdUtbetalingDao, observers = listOf(tbdUtbetalingDao, gamleUtbetalingerDao)) + val meterRegistry = PrometheusMeterRegistry(PrometheusConfig.DEFAULT, PrometheusRegistry.defaultRegistry, Clock.SYSTEM) RapidApplication.create( env = env, + meterRegistry = meterRegistry, builder = { - withCallIdHeader("x-callId") - withKtorModule { spokelse(env, auth, gamleUtbetalingerDao, TbdUtbetalingApi(tbdUtbetalingDao), ApplicationIdAllowlist) } + withKtor { preStopHook, rapid -> + naisApp( + meterRegistry = meterRegistry, + objectMapper = jacksonObjectMapper().registerModule(JavaTimeModule()).disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS), + applicationLogger = LoggerFactory.getLogger("no.nav.helse.spokelse.App"), + callLogger = LoggerFactory.getLogger("no.nav.helse.spokelse.CallLogging"), + naisEndpoints = com.github.navikt.tbd_libs.naisful.NaisEndpoints.Default, + callIdHeaderName = "x-callId", + timersConfig = { call, _ -> + this + .tag("azp_name", call.principal()?.get("azp_name") ?: "n/a") + // https://github.com/linkerd/polixy/blob/main/DESIGN.md#l5d-client-id-client-id + // eksempel: ..serviceaccount.identity.linkerd.cluster.local + .tag("konsument", call.request.header("L5d-Client-Id") ?: "n/a") + }, + mdcEntries = mapOf( + "azp_name" to { call: ApplicationCall -> call.principal()?.get("azp_name") }, + "konsument" to { call: ApplicationCall -> call.request.header("L5d-Client-Id") } + ), + aliveCheck = rapid::isReady, + readyCheck = rapid::isReady, + preStopHook = preStopHook::handlePreStopRequest + ) { + spokelse(env, auth, gamleUtbetalingerDao, TbdUtbetalingApi(tbdUtbetalingDao), ApplicationIdAllowlist) + } + } } ) .apply {