-
Notifications
You must be signed in to change notification settings - Fork 40.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate Kafka metrics to KafkaClientMetrics
Closes gh-20838
- Loading branch information
Showing
4 changed files
with
30 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright 2012-2019 the original author or authors. | ||
* Copyright 2012-2020 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
|
@@ -18,37 +18,37 @@ | |
|
||
import java.util.Collections; | ||
|
||
import javax.management.MBeanServer; | ||
|
||
import io.micrometer.core.instrument.MeterRegistry; | ||
import io.micrometer.core.instrument.binder.kafka.KafkaConsumerMetrics; | ||
import org.apache.kafka.clients.consumer.KafkaConsumer; | ||
import io.micrometer.core.instrument.binder.kafka.KafkaClientMetrics; | ||
|
||
import org.springframework.boot.autoconfigure.AutoConfigureAfter; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
import org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate; | ||
import org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.kafka.core.ProducerFactory; | ||
|
||
/** | ||
* Auto-configuration for Kafka metrics. | ||
* | ||
* @author Andy Wilkinson | ||
* @author Stephane Nicoll | ||
* @since 2.1.0 | ||
*/ | ||
@Configuration(proxyBeanMethods = false) | ||
@AutoConfigureAfter({ MetricsAutoConfiguration.class, JmxAutoConfiguration.class }) | ||
@ConditionalOnClass({ KafkaConsumerMetrics.class, KafkaConsumer.class }) | ||
@AutoConfigureAfter({ MetricsAutoConfiguration.class, KafkaAutoConfiguration.class }) | ||
@ConditionalOnClass({ KafkaClientMetrics.class, ProducerFactory.class }) | ||
@ConditionalOnBean(MeterRegistry.class) | ||
public class KafkaMetricsAutoConfiguration { | ||
|
||
@Bean | ||
@ConditionalOnMissingBean | ||
@ConditionalOnBean(MBeanServer.class) | ||
public KafkaConsumerMetrics kafkaConsumerMetrics(MBeanServer mbeanServer) { | ||
return new KafkaConsumerMetrics(mbeanServer, Collections.emptyList()); | ||
@ConditionalOnSingleCandidate(ProducerFactory.class) | ||
public KafkaClientMetrics kafkaClientMetrics(ProducerFactory<?, ?> producerFactory) { | ||
This comment has been minimized.
Sorry, something went wrong. |
||
return new KafkaClientMetrics(producerFactory.createProducer(), Collections.emptyList()); | ||
This comment has been minimized.
Sorry, something went wrong.
izeye
Contributor
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This seems to be changed to producer metrics from consumer metrics.
KafkaClientMetrics
supports instrumentation forProducer
,Consumer
, andAdminClient
, so you might want to instrument others. Micrometer 1.4.0 also addsKafkaStreamsMetrics
, so you might want to use it, too.