diff --git a/hm-rapids-and-rivers-v2-core/src/main/kotlin/no/nav/helse/rapids_rivers/KafkaRapid.kt b/hm-rapids-and-rivers-v2-core/src/main/kotlin/no/nav/helse/rapids_rivers/KafkaRapid.kt index 0e5de55..2297862 100644 --- a/hm-rapids-and-rivers-v2-core/src/main/kotlin/no/nav/helse/rapids_rivers/KafkaRapid.kt +++ b/hm-rapids-and-rivers-v2-core/src/main/kotlin/no/nav/helse/rapids_rivers/KafkaRapid.kt @@ -37,6 +37,11 @@ class KafkaRapid( private val consumer = KafkaConsumer(consumerConfig, stringDeserializer, stringDeserializer) private val producer = KafkaProducer(producerConfig, stringSerializer, stringSerializer) + // metric definitions + private val consumerMetric = KafkaClientMetrics(consumer) + private val producerMetric = KafkaClientMetrics(producer) + private val rapidMetric = KafkaRapidMetrics(this) + private val topics = listOf(rapidTopic) + extraTopics private var seekToBeginning = false @@ -244,7 +249,12 @@ class KafkaRapid( } } - fun getMetrics() = listOf(KafkaClientMetrics(consumer), KafkaClientMetrics(producer), KafkaRapidMetrics(this)) + fun getMetrics() = listOf(consumerMetric, producerMetric, rapidMetric) + + fun getConsumerMetric() = consumerMetric + fun getProducerMetric() = producerMetric + fun getRapidMetric() = rapidMetric + companion object { private const val Stopped = false diff --git a/hm-rapids-and-rivers-v2-micronaut/src/main/kotlin/no/nav/hm/rapids_rivers/micronaut/RapidsRiversFactory.kt b/hm-rapids-and-rivers-v2-micronaut/src/main/kotlin/no/nav/hm/rapids_rivers/micronaut/RapidsRiversFactory.kt index 89cfdcf..7e856ef 100644 --- a/hm-rapids-and-rivers-v2-micronaut/src/main/kotlin/no/nav/hm/rapids_rivers/micronaut/RapidsRiversFactory.kt +++ b/hm-rapids-and-rivers-v2-micronaut/src/main/kotlin/no/nav/hm/rapids_rivers/micronaut/RapidsRiversFactory.kt @@ -1,11 +1,13 @@ package no.nav.hm.rapids_rivers.micronaut +import io.micrometer.core.instrument.binder.kafka.KafkaClientMetrics import io.micronaut.context.annotation.Bean import io.micronaut.context.annotation.Factory import io.micronaut.context.annotation.Primary import io.micronaut.context.annotation.Requires import io.micronaut.context.env.Environment +import jakarta.inject.Named import jakarta.inject.Singleton import no.nav.helse.rapids_rivers.KafkaConfig import no.nav.helse.rapids_rivers.KafkaRapid @@ -33,9 +35,16 @@ class RapidsRiversFactory { return KafkaRapid.create(kafkaConfig, kafkaProps.topic, kafkaProps.extraTopics) } - @Bean @Singleton - @Primary - fun rapidMetrics(kafkaRapid: KafkaRapid): KafkaRapidMetrics = KafkaRapidMetrics(kafkaRapid) + fun rapidMetrics(kafkaRapid: KafkaRapid): KafkaRapidMetrics = kafkaRapid.getRapidMetric() + + @Singleton + @Named("ConsumerMetric") + fun consumerMetric(kafkaRapid: KafkaRapid): KafkaClientMetrics = kafkaRapid.getConsumerMetric() + + @Singleton + @Named("ProducerMetric") + fun producerMetric(kafkaRapid: KafkaRapid): KafkaClientMetrics = kafkaRapid.getProducerMetric() + }