Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev/oppgradering-kafka-keys-ktor3'
Browse files Browse the repository at this point in the history
  • Loading branch information
robertkittilsen committed Dec 23, 2024
2 parents b54e65c + e76b065 commit 7ab7d8e
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 37 deletions.
35 changes: 17 additions & 18 deletions apps/kafka-key-generator/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
kotlin("jvm")
Expand All @@ -13,37 +12,37 @@ val jvmMajorVersion: String by project
dependencies {
// PAW
implementation(project(":lib:hoplite-config"))
implementation(project(":lib:error-handling"))
implementation(project(":lib:http-client-utils"))
implementation(project(":lib:pdl-client"))
implementation(project(":lib:error-handling-ktor3"))
implementation(project(":lib:http-client-utils-ktorv3"))
implementation(project(":lib:pdl-client-ktor3"))
implementation(project(":lib:kafka"))
implementation(project(":domain:interne-hendelser"))

// NAV
implementation(libs.nav.common.log)
implementation(libs.nav.common.tokenClient)
implementation(libs.nav.security.tokenClientCore)
implementation(libs.nav.security.tokenValidationKtorV2)
implementation(libs.nav.security.tokenValidationKtorV3)

// Kafka (for å beregne partisjonsnummer)
implementation(libs.kafka.clients)

// Ktor
implementation(libs.ktor.serialization.jackson)
implementation(libs.ktor3.serialization.jackson)

// Ktor Server
implementation(libs.bundles.ktorServerWithNettyAndMicrometer)
implementation(libs.ktor.server.cors)
implementation(libs.ktor.server.swagger)
implementation(libs.ktor.server.callId)
implementation(libs.ktor.server.statusPages)
implementation(libs.ktor.server.contentNegotiation)
implementation(libs.bundles.ktor3ServerWithNettyAndMicrometer)
implementation(libs.ktor3.server.cors)
implementation(libs.ktor3.server.swagger)
implementation(libs.ktor3.server.callId)
implementation(libs.ktor3.server.statusPages)
implementation(libs.ktor3.server.contentNegotiation)

// Ktor Client
implementation(libs.ktor.client.contentNegotiation)
implementation(libs.ktor.client.core)
implementation(libs.ktor.client.cio)
implementation(libs.ktor.client.logging)
implementation(libs.ktor3.client.contentNegotiation)
implementation(libs.ktor3.client.core)
implementation(libs.ktor3.client.cio)
implementation(libs.ktor3.client.logging)

// Micrometer & OTEL
implementation(libs.micrometer.registryPrometheus)
Expand Down Expand Up @@ -73,8 +72,8 @@ dependencies {
testImplementation(libs.bundles.testLibsWithUnitTesting)
testImplementation(libs.test.testContainers.core)
testImplementation(libs.test.testContainers.postgresql)
testImplementation(libs.ktor.server.testJvm)
testImplementation(libs.ktor.client.mock)
testImplementation(libs.ktor3.server.test.host)
testImplementation(libs.ktor3.client.mock)
}

java {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package no.nav.paw.kafkakeygenerator

import io.ktor.server.engine.EngineConnectorBuilder
import io.ktor.server.engine.embeddedServer
import io.ktor.server.netty.Netty
import io.micrometer.core.instrument.binder.kafka.KafkaClientMetrics
Expand Down Expand Up @@ -94,12 +95,14 @@ fun startApplication(
)

embeddedServer(
factory = Netty,
port = 8080,
Netty,
configure = {
connectionGroupSize = 8
workerGroupSize = 8
callGroupSize = 16
connectors.add(EngineConnectorBuilder().apply {
port = 8080
})
}
) {
configSerialization()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package no.nav.paw.kafkakeygenerator.api.recordkey

import io.ktor.server.application.*
import io.ktor.server.auth.*
import io.ktor.server.request.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
import io.ktor.util.pipeline.*
import io.opentelemetry.instrumentation.annotations.WithSpan
import no.nav.paw.kafkakeygenerator.api.recordkey.functions.recordKey
import no.nav.paw.kafkakeygenerator.config.AuthenticationConfig
Expand All @@ -29,7 +27,7 @@ fun Routing.configureRecordKeyApi(
}

@WithSpan
private suspend fun PipelineContext<Unit, ApplicationCall>.handleRequest(
private suspend fun RoutingContext.handleRequest(
kafkaKeysService: KafkaKeysService,
logger: Logger
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ package no.nav.paw.kafkakeygenerator.api.v2
import io.ktor.http.*
import io.ktor.http.HttpStatusCode.Companion.InternalServerError
import io.ktor.http.HttpStatusCode.Companion.OK
import io.ktor.server.application.*
import io.ktor.server.auth.*
import io.ktor.server.request.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
import io.ktor.util.pipeline.*
import io.opentelemetry.instrumentation.annotations.WithSpan
import no.nav.paw.kafkakeygenerator.service.KafkaKeysService
import no.nav.paw.kafkakeygenerator.vo.FailureCode
Expand Down Expand Up @@ -40,7 +38,7 @@ fun Routing.konfigurerApiV2(
}

@WithSpan
suspend fun PipelineContext<Unit, ApplicationCall>.hentLokalInfo(
suspend fun RoutingContext.hentLokalInfo(
kafkaKeysService: KafkaKeysService,
logger: Logger
) {
Expand All @@ -62,7 +60,7 @@ suspend fun PipelineContext<Unit, ApplicationCall>.hentLokalInfo(
}

@WithSpan
suspend fun PipelineContext<Unit, ApplicationCall>.hentInfo(
suspend fun RoutingContext.hentInfo(
kafkaKeysService: KafkaKeysService,
logger: Logger
) {
Expand All @@ -80,7 +78,7 @@ suspend fun PipelineContext<Unit, ApplicationCall>.hentInfo(
}

@WithSpan
private suspend fun PipelineContext<Unit, ApplicationCall>.hentEllerOpprett(
private suspend fun RoutingContext.hentEllerOpprett(
kafkaKeysService: KafkaKeysService,
logger: Logger
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package no.nav.paw.kafkakeygenerator.plugin
import io.ktor.server.application.Application
import io.ktor.server.auth.authentication
import no.nav.paw.kafkakeygenerator.config.AuthenticationConfig
import no.nav.security.token.support.v2.IssuerConfig
import no.nav.security.token.support.v2.RequiredClaims
import no.nav.security.token.support.v2.TokenSupportConfig
import no.nav.security.token.support.v2.tokenValidationSupport
import no.nav.security.token.support.v3.IssuerConfig
import no.nav.security.token.support.v3.RequiredClaims
import no.nav.security.token.support.v3.TokenSupportConfig
import no.nav.security.token.support.v3.tokenValidationSupport

fun Application.configureAuthentication(authenticationConfig: AuthenticationConfig) {
authentication {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package no.nav.paw.kafkakeygenerator.plugin
import io.ktor.http.HttpStatusCode
import io.ktor.server.application.Application
import io.ktor.server.application.install
import io.ktor.server.plugins.callloging.CallLogging
import io.ktor.server.plugins.calllogging.CallLogging
import io.ktor.server.request.path

fun Application.configureLogging() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import io.ktor.server.application.ApplicationStarted
import io.ktor.server.application.createApplicationPlugin
import io.ktor.server.application.hooks.MonitoringEvent
import io.ktor.server.application.log
import io.ktor.util.KtorDsl
import io.ktor.utils.io.KtorDsl
import org.flywaydb.core.Flyway
import javax.sql.DataSource

Expand All @@ -32,7 +32,7 @@ val FlywayPlugin: ApplicationPlugin<FlywayPluginConfig> =
on(MonitoringEvent(ApplicationStarted)) { application ->
application.log.info("Running database migration")
dataSource.flywayMigrate(baselineOnMigrate)
application.environment.monitor.raise(FlywayMigrationCompleted, application)
application.monitor.raise(FlywayMigrationCompleted, application)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import io.ktor.server.application.ApplicationStopping
import io.ktor.server.application.createApplicationPlugin
import io.ktor.server.application.hooks.MonitoringEvent
import io.ktor.server.application.log
import io.ktor.util.KtorDsl
import io.ktor.utils.io.KtorDsl
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -69,7 +69,7 @@ fun <K, V> kafkaConsumerPlugin(): ApplicationPlugin<KafkaConsumerPluginConfig<K,
on(MonitoringEvent(ApplicationStarted)) { application ->
logger.info("Kafka Consumer klargjøres")
kafkaConsumer.subscribe(kafkaTopics, rebalanceListener)
application.environment.monitor.raise(KafkaConsumerReady, application)
application.monitor.raise(KafkaConsumerReady, application)
}

on(MonitoringEvent(ApplicationStopping)) { _ ->
Expand Down

0 comments on commit 7ab7d8e

Please sign in to comment.