Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EY-3454: Unngår bruk av kafka-avro-serializer-biblioteket der det ikkje trengs #3666

Merged
merged 5 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion apps/etterlatte-egne-ansatte-lytter/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ dependencies {

implementation(libs.kafka.clients)
implementation(libs.kafka.avro)
implementation(libs.kafka.avroserializer)

testImplementation(libs.kafka.embeddedenv)
testImplementation(libs.el.api)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package no.nav.etterlatte.kafka

import io.confluent.kafka.schemaregistry.client.SchemaRegistryClientConfig
import io.confluent.kafka.serializers.AbstractKafkaSchemaSerDeConfig
import org.apache.kafka.common.serialization.StringDeserializer

class KafkaEnvironment : Kafkakonfigurasjon<StringDeserializer>(
groupId = "SKJERMING_GROUP_ID",
deserializerClass = StringDeserializer::class.java,
userInfoConfigKey = SchemaRegistryClientConfig.USER_INFO_CONFIG,
schemaRegistryUrlConfigKey = AbstractKafkaSchemaSerDeConfig.SCHEMA_REGISTRY_URL_CONFIG,
userInfoConfigKey = Avrokonstanter.USER_INFO_CONFIG,
schemaRegistryUrlConfigKey = Avrokonstanter.SCHEMA_REGISTRY_URL_CONFIG,
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package no.nav.etterlatte.kafka

import io.confluent.kafka.serializers.KafkaAvroDeserializerConfig
import io.mockk.every
import io.mockk.just
import io.mockk.mockk
Expand Down Expand Up @@ -83,7 +82,7 @@ class SkjermingslesingTest {
ProducerConfig.BOOTSTRAP_SERVERS_CONFIG to kafkaEnv.brokersURL,
ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG to StringSerializer::class.java.canonicalName,
ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG to StringSerializer::class.java.canonicalName,
KafkaAvroDeserializerConfig.SCHEMA_REGISTRY_URL_CONFIG to kafkaEnv.schemaRegistry?.url,
Avrokonstanter.SCHEMA_REGISTRY_URL_CONFIG to kafkaEnv.schemaRegistry?.url,
ProducerConfig.ACKS_CONFIG to "all",
),
)
Expand All @@ -97,7 +96,7 @@ class SkjermingslesingTest {
put(CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG, kafkaEnv.brokersURL)
put(ConsumerConfig.GROUP_ID_CONFIG, env["SKJERMING_GROUP_ID"])
put(ConsumerConfig.CLIENT_ID_CONFIG, "etterlatte-egne-ansatte-lytter")
put(KafkaAvroDeserializerConfig.SCHEMA_REGISTRY_URL_CONFIG, kafkaEnv.schemaRegistry?.url!!)
put(Avrokonstanter.SCHEMA_REGISTRY_URL_CONFIG, kafkaEnv.schemaRegistry?.url!!)
put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer::class.java)
put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer::class.java)
put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package no.nav.etterlatte.joarkhendelser.config

import io.confluent.kafka.serializers.KafkaAvroDeserializer
import io.confluent.kafka.serializers.KafkaAvroDeserializerConfig
import no.nav.etterlatte.kafka.Avrokonstanter
import no.nav.etterlatte.kafka.Kafkakonfigurasjon
import org.apache.kafka.common.IsolationLevel
import java.util.Locale

class KafkaEnvironment : Kafkakonfigurasjon<KafkaAvroDeserializer>(
groupId = "JOARK_HENDELSE_GROUP_ID",
deserializerClass = KafkaAvroDeserializer::class.java,
userInfoConfigKey = KafkaAvroDeserializerConfig.USER_INFO_CONFIG,
schemaRegistryUrlConfigKey = KafkaAvroDeserializerConfig.SCHEMA_REGISTRY_URL_CONFIG,
userInfoConfigKey = Avrokonstanter.USER_INFO_CONFIG,
schemaRegistryUrlConfigKey = Avrokonstanter.SCHEMA_REGISTRY_URL_CONFIG,
isolationLevelConfig = IsolationLevel.READ_COMMITTED.toString().lowercase(Locale.getDefault()),
specificAvroReaderConfig = true,
)
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package no.nav.etterlatte.hendelserpdl.config

import io.confluent.kafka.serializers.KafkaAvroDeserializer
import io.confluent.kafka.serializers.KafkaAvroDeserializerConfig
import no.nav.etterlatte.kafka.Avrokonstanter
import no.nav.etterlatte.kafka.Kafkakonfigurasjon
import org.apache.kafka.common.IsolationLevel
import java.util.Locale

class KafkaEnvironment : Kafkakonfigurasjon<KafkaAvroDeserializer>(
groupId = "LEESAH_KAFKA_GROUP_ID",
deserializerClass = KafkaAvroDeserializer::class.java,
userInfoConfigKey = KafkaAvroDeserializerConfig.USER_INFO_CONFIG,
schemaRegistryUrlConfigKey = KafkaAvroDeserializerConfig.SCHEMA_REGISTRY_URL_CONFIG,
userInfoConfigKey = Avrokonstanter.USER_INFO_CONFIG,
schemaRegistryUrlConfigKey = Avrokonstanter.SCHEMA_REGISTRY_URL_CONFIG,
isolationLevelConfig = IsolationLevel.READ_COMMITTED.toString().lowercase(Locale.getDefault()),
specificAvroReaderConfig = true,
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package no.nav.etterlatte.hendelserpdl

import com.fasterxml.jackson.module.kotlin.readValue
import io.confluent.kafka.serializers.KafkaAvroDeserializer
import io.confluent.kafka.serializers.KafkaAvroDeserializerConfig
import io.confluent.kafka.serializers.KafkaAvroSerializer
import io.ktor.client.HttpClient
import io.ktor.client.engine.mock.MockEngine
Expand All @@ -17,6 +16,7 @@ import io.mockk.verify
import no.nav.common.KafkaEnvironment
import no.nav.etterlatte.hendelserpdl.common.PersonhendelseKonsument
import no.nav.etterlatte.hendelserpdl.pdl.PdlTjenesterKlient
import no.nav.etterlatte.kafka.Avrokonstanter
import no.nav.etterlatte.kafka.KafkaConsumerConfiguration
import no.nav.etterlatte.kafka.LocalKafkaConfig
import no.nav.etterlatte.kafka.rapidsAndRiversProducer
Expand Down Expand Up @@ -127,14 +127,14 @@ class IntegrationTest {
put(CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG, kafkaEnv.brokersURL)
put(ConsumerConfig.GROUP_ID_CONFIG, env["LEESAH_KAFKA_GROUP_ID"])
put(ConsumerConfig.CLIENT_ID_CONFIG, "etterlatte-pdl-hendelser")
put(KafkaAvroDeserializerConfig.SCHEMA_REGISTRY_URL_CONFIG, kafkaEnv.schemaRegistry?.url!!)
put(Avrokonstanter.SCHEMA_REGISTRY_URL_CONFIG, kafkaEnv.schemaRegistry?.url!!)
put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer::class.java)
put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, KafkaAvroDeserializer::class.java)
put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest")
put(ConsumerConfig.MAX_POLL_RECORDS_CONFIG, 100)
put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, false)
put(ConsumerConfig.MAX_POLL_INTERVAL_MS_CONFIG, trettiSekunder)
put(KafkaAvroDeserializerConfig.SPECIFIC_AVRO_READER_CONFIG, true)
put(Avrokonstanter.SPECIFIC_AVRO_READER_CONFIG, true)
}
return properties
}
Expand All @@ -146,7 +146,7 @@ class IntegrationTest {
ProducerConfig.BOOTSTRAP_SERVERS_CONFIG to kafkaEnv.brokersURL,
ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG to KafkaAvroSerializer::class.java.canonicalName,
ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG to KafkaAvroSerializer::class.java.canonicalName,
KafkaAvroDeserializerConfig.SCHEMA_REGISTRY_URL_CONFIG to kafkaEnv.schemaRegistry?.url,
Avrokonstanter.SCHEMA_REGISTRY_URL_CONFIG to kafkaEnv.schemaRegistry?.url,
ProducerConfig.ACKS_CONFIG to "all",
),
)
Expand Down
1 change: 0 additions & 1 deletion apps/etterlatte-hendelser-samordning/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ dependencies {

implementation(libs.kafka.clients)
implementation(libs.kafka.avro)
implementation(libs.kafka.avroserializer)

testImplementation(libs.kafka.embeddedenv)
testImplementation(libs.el.api)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ package no.nav.etterlatte.samordning

import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.fasterxml.jackson.module.kotlin.readValue
import io.confluent.kafka.schemaregistry.client.SchemaRegistryClientConfig
import io.confluent.kafka.serializers.AbstractKafkaSchemaSerDeConfig
import no.nav.etterlatte.kafka.Avrokonstanter
import no.nav.etterlatte.kafka.Kafkakonfigurasjon

class KafkaEnvironment : Kafkakonfigurasjon<KafkaEnvironment.JsonDeserializer>(
groupId = "SAMORDNINGVEDTAK_HENDELSE_GROUP_ID",
deserializerClass = JsonDeserializer::class.java,
userInfoConfigKey = SchemaRegistryClientConfig.USER_INFO_CONFIG,
schemaRegistryUrlConfigKey = AbstractKafkaSchemaSerDeConfig.SCHEMA_REGISTRY_URL_CONFIG,
userInfoConfigKey = Avrokonstanter.USER_INFO_CONFIG,
schemaRegistryUrlConfigKey = Avrokonstanter.SCHEMA_REGISTRY_URL_CONFIG,
) {
class JsonDeserializer : org.apache.kafka.common.serialization.Deserializer<SamordningVedtakHendelse> {
override fun deserialize(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package no.nav.etterlatte.samordning

import com.fasterxml.jackson.core.JsonProcessingException
import io.confluent.kafka.serializers.KafkaAvroDeserializerConfig
import io.ktor.server.application.Application
import io.mockk.spyk
import io.mockk.verify
import no.nav.common.KafkaEnvironment
import no.nav.etterlatte.kafka.Avrokonstanter
import no.nav.etterlatte.kafka.KafkaConsumerConfiguration
import no.nav.etterlatte.kafka.LocalKafkaConfig
import no.nav.etterlatte.kafka.rapidsAndRiversProducer
Expand Down Expand Up @@ -98,7 +98,7 @@ class SamordningHendelseIntegrationTest {
ProducerConfig.BOOTSTRAP_SERVERS_CONFIG to kafkaEnv.brokersURL,
ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG to StringSerializer::class.java.canonicalName,
ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG to SamJsonSerializer::class.java.canonicalName,
KafkaAvroDeserializerConfig.SCHEMA_REGISTRY_URL_CONFIG to kafkaEnv.schemaRegistry?.url,
Avrokonstanter.SCHEMA_REGISTRY_URL_CONFIG to kafkaEnv.schemaRegistry?.url,
ProducerConfig.ACKS_CONFIG to "all",
),
)
Expand All @@ -112,13 +112,13 @@ class SamordningHendelseIntegrationTest {
put(CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG, kafkaEnv.brokersURL)
put(ConsumerConfig.GROUP_ID_CONFIG, env["KAFKA_GROUP_ID"])
put(ConsumerConfig.CLIENT_ID_CONFIG, "etterlatte-test-v1")
put(KafkaAvroDeserializerConfig.SCHEMA_REGISTRY_URL_CONFIG, kafkaEnv.schemaRegistry?.url!!)
put(Avrokonstanter.SCHEMA_REGISTRY_URL_CONFIG, kafkaEnv.schemaRegistry?.url!!)
put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer::class.java)
put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, JsonDeserializer::class.java)
put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest")
put(ConsumerConfig.MAX_POLL_RECORDS_CONFIG, 100)
put(ConsumerConfig.MAX_POLL_INTERVAL_MS_CONFIG, tiSekunder)
put(KafkaAvroDeserializerConfig.SPECIFIC_AVRO_READER_CONFIG, true)
put(Avrokonstanter.SPECIFIC_AVRO_READER_CONFIG, true)
}
return properties
}
Expand Down
1 change: 0 additions & 1 deletion apps/etterlatte-institusjonsopphold/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ dependencies {
implementation(libs.ktor2.clientcontentnegotiation)
implementation(libs.ktor2.clientjackson)
implementation(libs.kafka.clients)
implementation(libs.kafka.avroserializer)

testImplementation(libs.ktor2.clientmock)
testImplementation(libs.kotlinx.coroutinescore)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ package no.nav.etterlatte.kafka

import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.fasterxml.jackson.module.kotlin.readValue
import io.confluent.kafka.schemaregistry.client.SchemaRegistryClientConfig
import io.confluent.kafka.serializers.AbstractKafkaSchemaSerDeConfig
import org.apache.kafka.common.IsolationLevel
import java.util.Locale

class KafkaEnvironment : Kafkakonfigurasjon<KafkaEnvironment.JsonDeserializer>(
groupId = "INSTITUSJONSOPPHOLD_GROUP_ID",
deserializerClass = JsonDeserializer::class.java,
userInfoConfigKey = SchemaRegistryClientConfig.USER_INFO_CONFIG,
schemaRegistryUrlConfigKey = AbstractKafkaSchemaSerDeConfig.SCHEMA_REGISTRY_URL_CONFIG,
userInfoConfigKey = Avrokonstanter.USER_INFO_CONFIG,
schemaRegistryUrlConfigKey = Avrokonstanter.SCHEMA_REGISTRY_URL_CONFIG,
isolationLevelConfig = IsolationLevel.READ_COMMITTED.toString().lowercase(Locale.getDefault()),
) {
class JsonDeserializer : org.apache.kafka.common.serialization.Deserializer<KafkaOppholdHendelse> {
Expand Down
1 change: 0 additions & 1 deletion apps/etterlatte-klage/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ dependencies {
implementation(project(":libs:saksbehandling-common"))

implementation(libs.kafka.clients)
implementation(libs.kafka.avroserializer)
implementation(libs.klage.kodeverk)
implementation(libs.ktor2.okhttp)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package no.nav.etterlatte.klage

import io.confluent.kafka.schemaregistry.client.SchemaRegistryClientConfig
import io.confluent.kafka.serializers.AbstractKafkaSchemaSerDeConfig
import no.nav.etterlatte.kafka.Avrokonstanter
import no.nav.etterlatte.kafka.Kafkakonfigurasjon
import no.nav.etterlatte.kafka.Kafkakonsument
import org.apache.kafka.clients.consumer.KafkaConsumer
Expand All @@ -27,6 +26,6 @@ class KlageKafkakonsument(
internal class KafkaEnvironment : Kafkakonfigurasjon<StringDeserializer>(
groupId = "KLAGE_GROUP_ID",
deserializerClass = StringDeserializer::class.java,
userInfoConfigKey = SchemaRegistryClientConfig.USER_INFO_CONFIG,
schemaRegistryUrlConfigKey = AbstractKafkaSchemaSerDeConfig.SCHEMA_REGISTRY_URL_CONFIG,
userInfoConfigKey = Avrokonstanter.USER_INFO_CONFIG,
schemaRegistryUrlConfigKey = Avrokonstanter.SCHEMA_REGISTRY_URL_CONFIG,
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ package no.nav.etterlatte.kafka
object Avrokonstanter {
const val SPECIFIC_AVRO_READER_CONFIG = "specific.avro.reader"
const val BASIC_AUTH_CREDENTIALS_SOURCE = SchemaRegistryClientConfig.BASIC_AUTH_CREDENTIALS_SOURCE
const val USER_INFO_CONFIG = SchemaRegistryClientConfig.USER_INFO_CONFIG
const val SCHEMA_REGISTRY_URL_CONFIG = "schema.registry.url"

private object SchemaRegistryClientConfig {
const val BASIC_AUTH_CREDENTIALS_SOURCE = "basic.auth.credentials.source"
const val USER_INFO_CONFIG = "basic.auth.user.info"
Comment on lines 4 to +11
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bytte ut strings med de statiske verdiene til AbstractKafkaSchemaSerDeConfig?

Og kanskje enda bedre, droppe filen Avrokonstanter og heller bruke det direkte, siden hele denne er en litt unødvendig abstraksjon av AbstractKafkaSchemaSerDeConfig 🤷‍♂️

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dette er ei avveging, ja. Grunngjevinga var meint å komme fram i PR-tittel pluss første kommentaren over, og ein litt meir utførleg diskusjon hadde vi på #3258

}
}
18 changes: 14 additions & 4 deletions libs/etterlatte-kafka/src/test/kotlin/AvrokonstanterTest.kt
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
package no.nav.etterlatte.kafka

import io.confluent.kafka.schemaregistry.client.SchemaRegistryClientConfig
import io.confluent.kafka.serializers.AbstractKafkaSchemaSerDeConfig
import org.junit.jupiter.api.Assertions
import io.confluent.kafka.serializers.KafkaAvroDeserializerConfig
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test

class AvrokonstanterTest {
@Test
fun `vaare hardkodede konstanter i libs matcher med dem i Avro-biblioteket`() {
Assertions.assertEquals(
assertEquals(
AbstractKafkaSchemaSerDeConfig.BASIC_AUTH_CREDENTIALS_SOURCE,
Avrokonstanter.BASIC_AUTH_CREDENTIALS_SOURCE,
)
Assertions.assertEquals(
io.confluent.kafka.serializers.KafkaAvroDeserializerConfig.SPECIFIC_AVRO_READER_CONFIG,
assertEquals(
KafkaAvroDeserializerConfig.SPECIFIC_AVRO_READER_CONFIG,
Avrokonstanter.SPECIFIC_AVRO_READER_CONFIG,
)
assertEquals(
SchemaRegistryClientConfig.USER_INFO_CONFIG,
Avrokonstanter.USER_INFO_CONFIG,
)
assertEquals(
AbstractKafkaSchemaSerDeConfig.SCHEMA_REGISTRY_URL_CONFIG,
Avrokonstanter.SCHEMA_REGISTRY_URL_CONFIG,
)
}
}