Skip to content

Commit

Permalink
Oppdatert 3.parts biblioteker
Browse files Browse the repository at this point in the history
- Kotlin til 1.5.10
- Gradle til 7.1
- Jackson til 2.12.3
- Kafka til 2.8.1
- prometheus client til 0.11.0*
+++

* Prometheus bruker nå OpenMetrics datamodel
With this release the client_java simpleclient switches to the OpenMetrics data model and adds support for various new OpenMetrics-related features. This should be largely seamless, however any counters which lack a _total suffix on their sample will now have it added. If you'd prefer to make that change more gradually, you should change your metric names before upgrading to this version.
ref https://github.com/prometheus/client_java/releases/tag/parent-0.10.0
  • Loading branch information
geiralund committed Jun 24, 2021
1 parent a09372a commit 001b392
Show file tree
Hide file tree
Showing 13 changed files with 79 additions and 105 deletions.
5 changes: 1 addition & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@ allprojects {
dependsOn("spotlessApply", "spotlessKotlinCheck")
}

tasks.named("jar") {
dependsOn("test")
}

repositories {
jcenter()
maven("https://jitpack.io")
Expand All @@ -96,6 +92,7 @@ subprojects {
val scmUrl = "scm:git:https://github.com/navikt/dp-inntekt.git"

val sourcesJar by tasks.registering(Jar::class) {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
archiveClassifier.set("sources")
from(sourceSets["main"].allSource)
}
Expand Down
46 changes: 21 additions & 25 deletions buildSrc/src/main/kotlin/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ object Cucumber {
object Dagpenger {

object Biblioteker {
const val version = "2021.05.21-09.36.ed293b8f28a9"
const val version = "2021.06.23-14.39.74fbb7b79fde"
const val stsKlient = "com.github.navikt.dp-biblioteker:sts-klient:$version"
const val grunnbeløp = "com.github.navikt.dp-biblioteker:grunnbelop:$version"
const val ktorUtils = "com.github.navikt.dp-biblioteker:ktor-utils:$version"
Expand All @@ -45,16 +45,16 @@ object Dagpenger {
}
}

const val Streams = "com.github.navikt:dagpenger-streams:2021.05.18-14.31.6be662ea8106"
const val Events = "com.github.navikt:dagpenger-events:2021.02.19-08.31.cfd52901bc9f"
const val Streams = "com.github.navikt:dagpenger-streams:2021.06.23-14.29.bbb62ad15d52"
const val Events = "com.github.navikt:dagpenger-events:2021.06.23-14.38.f9ef5d423585"
}

object Database {
const val Postgres = "org.postgresql:postgresql:42.2.11"
const val Postgres = "org.postgresql:postgresql:42.2.22"
const val Kotlinquery = "com.github.seratch:kotliquery:1.3.1"
const val Flyway = "org.flywaydb:flyway-core:6.3.2"
const val HikariCP = "com.zaxxer:HikariCP:3.4.1"
const val VaultJdbc = "no.nav:vault-jdbc:1.3.1"
const val Flyway = "org.flywaydb:flyway-core:7.10.0"
const val HikariCP = "com.zaxxer:HikariCP:4.0.3"
const val VaultJdbc = "no.nav:vault-jdbc:1.3.7"
}

object Fuel {
Expand All @@ -69,14 +69,14 @@ object GradleWrapper {
}

object Jackson {
const val version = "2.12.1"
const val version = "2.12.3"
const val core = "com.fasterxml.jackson.core:jackson-core:$version"
const val kotlin = "com.fasterxml.jackson.module:jackson-module-kotlin:$version"
const val jsr310 = "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$version"
}

object Junit5 {
const val version = "5.7.1"
const val version = "5.7.2"
const val api = "org.junit.jupiter:junit-jupiter-api:$version"
const val params = "org.junit.jupiter:junit-jupiter-params:$version"
const val engine = "org.junit.jupiter:junit-jupiter-engine:$version"
Expand All @@ -96,14 +96,14 @@ object JsonAssert {
}

object Kafka {
const val version = "2.4.1"
const val version = "2.8.0"
const val clients = "org.apache.kafka:kafka-clients:$version"
const val streams = "org.apache.kafka:kafka-streams:$version"
const val streamTestUtils = "org.apache.kafka:kafka-streams-test-utils:$version"
fun library(name: String) = "org.apache.kafka:kafka-$name:$version"

object Confluent {
const val version = "5.4.0"
const val version = "6.2.0"
const val avroStreamSerdes = "io.confluent:kafka-streams-avro-serde:$version"
fun library(name: String) = "io.confluent:$name:$version"
}
Expand All @@ -113,16 +113,12 @@ object KafkaEmbedded {
const val env = "no.nav:kafka-embedded-env:2.4.0"
}

object Klint {
const val version = "0.33.0"
}

object Konfig {
const val konfig = "com.natpryce:konfig:1.6.10.0"
}

object Kotlin {
const val version = "1.4.30"
const val version = "1.5.10"
const val stdlib = "org.jetbrains.kotlin:kotlin-stdlib:$version"

object Coroutines {
Expand All @@ -131,7 +127,7 @@ object Kotlin {
}

object Logging {
const val version = "2.0.4"
const val version = "2.0.8"
const val kotlinLogging = "io.github.microutils:kotlin-logging:$version"
}
}
Expand All @@ -157,7 +153,7 @@ object Kotlinx {
}

object Ktor {
const val version = "1.5.1"
const val version = "1.6.0"
const val server = "io.ktor:ktor-server:$version"
const val serverNetty = "io.ktor:ktor-server-netty:$version"
const val auth = "io.ktor:ktor-auth:$version"
Expand All @@ -169,7 +165,7 @@ object Ktor {
}

object Log4j2 {
const val version = "2.14.0"
const val version = "2.14.1"
const val api = "org.apache.logging.log4j:log4j-api:$version"
const val core = "org.apache.logging.log4j:log4j-core:$version"
const val slf4j = "org.apache.logging.log4j:log4j-slf4j-impl:$version"
Expand All @@ -183,7 +179,7 @@ object Log4j2 {
}

object Micrometer {
const val version = "1.4.0"
const val version = "1.7.0"
const val prometheusRegistry = "io.micrometer:micrometer-registry-prometheus:$version"
}

Expand All @@ -199,7 +195,7 @@ object Moshi {
}

object Mockk {
const val version = "1.10.6"
const val version = "1.11.0"
const val mockk = "io.mockk:mockk:$version"
}

Expand All @@ -209,7 +205,7 @@ object Nare {
}

object Prometheus {
const val version = "0.8.1"
const val version = "0.11.0"
const val common = "io.prometheus:simpleclient_common:$version"
const val hotspot = "io.prometheus:simpleclient_hotspot:$version"
const val log4j2 = "io.prometheus:simpleclient_log4j2:$version"
Expand All @@ -221,7 +217,7 @@ object Prometheus {
}
}

const val RapidAndRivers = "com.github.navikt:rapids-and-rivers:1.f3e5de3"
const val RapidAndRivers = "com.github.navikt:rapids-and-rivers:20210617121814-3e67e4d"

object Slf4j {
const val version = "1.7.25"
Expand All @@ -233,7 +229,7 @@ object Ktlint {
}

object Spotless {
const val version = "5.10.1"
const val version = "5.14.0"
const val spotless = "com.diffplug.spotless"
}

Expand Down Expand Up @@ -263,7 +259,7 @@ object Wiremock {
}

object Graphql {
const val version = "4.0.0-alpha.12"
const val version = "4.1.1"
const val graphql = "com.expediagroup.graphql"
val client = library("client")
fun library(name: String) = "com.expediagroup:graphql-kotlin-$name:$version"
Expand Down
15 changes: 7 additions & 8 deletions dp-inntekt-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ dependencies {

implementation(Graphql.client)
implementation(Graphql.library("ktor-client"))
implementation(Graphql.library("client-jackson"))
implementation(Ktor.library("client-logging-jvm"))
implementation(Ktor.library("client-apache"))

Expand Down Expand Up @@ -81,7 +82,6 @@ dependencies {
implementation(Prometheus.common)
implementation(Prometheus.hotspot)
implementation(Prometheus.log4j2)

implementation(Bekk.nocommons)

implementation(Kotlinx.bimap)
Expand All @@ -91,7 +91,10 @@ dependencies {
runtimeOnly("io.grpc:grpc-netty-shaded:$grpcVersion")

testImplementation(kotlin("test"))
testImplementation(Ktor.ktorTest)
testImplementation(Ktor.ktorTest) {
// https://youtrack.jetbrains.com/issue/KT-46090
exclude("org.jetbrains.kotlin", "kotlin-test-junit")
}
testImplementation(Ktor.library("client-mock"))
testImplementation(Junit5.api)
testImplementation(Junit5.params)
Expand All @@ -110,10 +113,6 @@ tasks.named("shadowJar") {
dependsOn("test")
}

tasks.named("jar") {
dependsOn("test")
}

tasks.named("compileKotlin") {
dependsOn("spotlessCheck")
dependsOn("graphqlGenerateClient")
Expand All @@ -135,13 +134,13 @@ val graphqlGenerateClient by tasks.getting(com.expediagroup.graphql.plugin.gradl
queryFileDirectory.set("$projectDir/src/main/resources")
}

tasks.register<de.undercouch.gradle.tasks.download.Download>("downloadPdlSDL") {
val downloadPdlSDL by tasks.register<de.undercouch.gradle.tasks.download.Download>("downloadPdlSDL") {
src("https://navikt.github.io/pdl/pdl-api-sdl.graphqls")
dest(File(buildDir, schema))
}

tasks.register<Copy>("copySchemaToResources") {
dependsOn("downloadPdlSDL")
dependsOn(downloadPdlSDL)

from(buildDir) {
include(schema)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,13 @@ fun Application.inntektApi(
apiAuthApiKeyVerifier: AuthApiKeyVerifier,
jwkProvider: JwkProvider,
enhetsregisterClient: EnhetsregisterClient,
healthChecks: List<HealthCheck>
healthChecks: List<HealthCheck>,
collectorRegistry: CollectorRegistry = CollectorRegistry.defaultRegistry
) {
install(DefaultHeaders)

install(MicrometerMetrics) {
registry = PrometheusMeterRegistry(PrometheusConfig.DEFAULT, CollectorRegistry.defaultRegistry, Clock.SYSTEM)
registry = PrometheusMeterRegistry(PrometheusConfig.DEFAULT, collectorRegistry, Clock.SYSTEM)
}

install(Authentication) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fun hikariConfigFrom(config: Configuration) =
}

fun migrate(dataSource: HikariDataSource, initSql: String = "", locations: List<String> = listOf("db/migration")): Int =
Flyway.configure().locations(*locations.toTypedArray()).dataSource(dataSource).initSql(initSql).load().migrate()
Flyway.configure().locations(*locations.toTypedArray()).dataSource(dataSource).initSql(initSql).load().migrate().migrations.size

fun clean(dataSource: HikariDataSource) = Flyway.configure().dataSource(dataSource).load().clean()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ private fun isSykepengerFangstFiske(posteringsType: PosteringsType): Boolean {

private fun isTiltakslønn(posteringsType: PosteringsType): Boolean {
val tiltakslønnPosteringsTyper = listOf(
// @todo Honorar/Akkord/Prosent/Provisjon ?
PosteringsType.L_ANNET_T,
PosteringsType.L_BONUS_T,
PosteringsType.L_FAST_TILLEGG_T,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import io.ktor.client.features.HttpTimeout
import io.ktor.client.features.logging.LogLevel
import io.ktor.client.features.logging.Logging
import io.ktor.client.request.get
import io.ktor.util.KtorExperimentalAPI
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import org.apache.http.impl.conn.SystemDefaultRoutePlanner
Expand All @@ -34,7 +33,6 @@ class EnhetsregisterClient(
}
}

@KtorExperimentalAPI
internal fun httpClient(
engine: HttpClientEngine = Apache.create { customizeClient { setRoutePlanner(SystemDefaultRoutePlanner(ProxySelector.getDefault())) } }
): HttpClient {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
package no.nav.dagpenger.inntekt.oppslag.pdl

import com.expediagroup.graphql.client.GraphQLClient
import com.expediagroup.graphql.client.jackson.GraphQLClientJacksonSerializer
import com.expediagroup.graphql.client.ktor.GraphQLKtorClient
import com.expediagroup.graphql.types.GraphQLResponse
import com.expediagroup.graphql.client.types.GraphQLClientResponse
import io.ktor.client.HttpClient
import io.ktor.client.engine.cio.CIO
import io.ktor.client.features.defaultRequest
import io.ktor.client.features.logging.LogLevel
import io.ktor.client.features.logging.Logger
import io.ktor.client.features.logging.Logging
import io.ktor.client.request.header
import io.ktor.http.HttpHeaders
import io.ktor.util.KtorExperimentalAPI
import mu.KotlinLogging
import no.nav.dagpenger.inntekt.oppslag.Person
import no.nav.dagpenger.inntekt.oppslag.PersonOppslag
import no.nav.pdl.HentPerson
import no.nav.pdl.hentperson.Navn
import java.net.URL
import java.util.UUID

private val log = KotlinLogging.logger { }
private val sikkerlogg = KotlinLogging.logger("tjenestekall")

@KtorExperimentalAPI
class PdlGraphQLRepository constructor(
client: GraphQLClient
class PdlGraphQLRepository(
private val client: GraphQLKtorClient
) : PersonOppslag {

private val query = HentPerson(client)
override suspend fun hentPerson(aktørId: String): Person? {
val result = query.execute(HentPerson.Variables(ident = aktørId))
val query = HentPerson(HentPerson.Variables(ident = aktørId))
val result = client.execute(query)

return if (result.errors?.isNotEmpty() == true) {
log.error { "Feil i GraphQL-responsen: ${result.errors}" }
Expand All @@ -37,8 +38,8 @@ class PdlGraphQLRepository constructor(
}
}

private fun GraphQLResponse<HentPerson.Result>.toPerson(): Person? {
val navn: HentPerson.Navn? = data?.hentPerson?.navn?.firstOrNull()
private fun GraphQLClientResponse<HentPerson.Result>.toPerson(): Person? {
val navn: Navn? = data?.hentPerson?.navn?.firstOrNull()
val fødselsnummer = data?.hentIdenter?.identer?.firstOrNull()?.ident
return fødselsnummer?.let { fnr ->
navn?.let { navn ->
Expand All @@ -53,27 +54,31 @@ class PdlGraphQLRepository constructor(
}
}

@KtorExperimentalAPI
fun PdlGraphQLClientFactory(
url: String,
oidcProvider: () -> String
) = GraphQLKtorClient(url = URL(url)) {
install(Logging) {
logger = object : Logger {
override fun log(message: String) = sikkerlogg.info { message }
): GraphQLKtorClient {
val client = HttpClient(engineFactory = CIO) {
install(Logging) {
logger = object : Logger {
override fun log(message: String) = sikkerlogg.info { message }
}

level = LogLevel.HEADERS
}

level = LogLevel.HEADERS
}
defaultRequest {
oidcProvider().also {
header(HttpHeaders.Authorization, "Bearer $it")
header("Nav-Consumer-Token", "Bearer $it")
}

defaultRequest {
oidcProvider().also {
header(HttpHeaders.Authorization, "Bearer $it")
header("Nav-Consumer-Token", "Bearer $it")
header(HttpHeaders.UserAgent, "dp-inntekt-api")
header(HttpHeaders.Accept, "application/json")
header("Tema", "DAG")
header("Nav-Call-Id", UUID.randomUUID())
}

header("User-Agent", "dp-inntekt-api")
header("Tema", "DAG")
header("Nav-Call-Id", UUID.randomUUID())
}

return GraphQLKtorClient(url = URL(url), httpClient = client, serializer = GraphQLClientJacksonSerializer())
}
Loading

0 comments on commit 001b392

Please sign in to comment.