Skip to content

Commit

Permalink
bruker naisful-app som ktor-server
Browse files Browse the repository at this point in the history
r&r sin ktor er plain og inneholder kun isalive, isready og metrics
  • Loading branch information
davidsteinsland committed Nov 29, 2024
1 parent 75e56ce commit 9ada5e6
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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")
}
Expand Down
41 changes: 39 additions & 2 deletions src/main/kotlin/no/nav/helse/spokelse/App.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -40,11 +51,37 @@ fun launchApplication(env: Map<String, String>) {
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<JWTPrincipal>()?.get("azp_name") ?: "n/a")
// https://github.com/linkerd/polixy/blob/main/DESIGN.md#l5d-client-id-client-id
// eksempel: <APP>.<NAMESPACE>.serviceaccount.identity.linkerd.cluster.local
.tag("konsument", call.request.header("L5d-Client-Id") ?: "n/a")
},
mdcEntries = mapOf(
"azp_name" to { call: ApplicationCall -> call.principal<JWTPrincipal>()?.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 {
Expand Down

0 comments on commit 9ada5e6

Please sign in to comment.