3838import org .springframework .util .Assert ;
3939import org .springframework .util .ReflectionUtils ;
4040
41-
4241import io .micrometer .core .instrument .ImmutableTag ;
4342import io .micrometer .core .instrument .MeterRegistry ;
4443import io .micrometer .core .instrument .Tag ;
4544import io .micrometer .core .instrument .binder .MeterBinder ;
4645import io .micrometer .core .instrument .binder .kafka .KafkaClientMetrics ;
4746
4847/**
49- * An abstract class to manage {@link io.micrometer.core.instrument.binder.kafka. KafkaClientMetrics}.
48+ * An abstract class to manage {@link KafkaClientMetrics}.
5049 *
5150 * @param <C> the Kafka Client type.
5251 *
5352 * @author Artem Bilan
5453 *
5554 * @since 3.3
55+ *
56+ * @see KafkaClientMetrics
5657 */
5758public abstract class KafkaMetricsSupport <C > {
5859
@@ -67,7 +68,6 @@ public abstract class KafkaMetricsSupport<C> {
6768
6869 /**
6970 * Construct an instance with the provided registry.
70- *
7171 * @param meterRegistry the registry.
7272 */
7373 protected KafkaMetricsSupport (MeterRegistry meterRegistry ) {
@@ -76,7 +76,6 @@ protected KafkaMetricsSupport(MeterRegistry meterRegistry) {
7676
7777 /**
7878 * Construct an instance with the provided {@link MeterRegistry} and {@link TaskScheduler}.
79- *
8079 * @param meterRegistry the registry.
8180 * @param taskScheduler the task scheduler.
8281 */
@@ -86,7 +85,6 @@ protected KafkaMetricsSupport(MeterRegistry meterRegistry, TaskScheduler taskSch
8685
8786 /**
8887 * Construct an instance with the provided {@link MeterRegistry} and tags.
89- *
9088 * @param meterRegistry the registry.
9189 * @param tags the tags.
9290 */
@@ -99,7 +97,6 @@ protected KafkaMetricsSupport(MeterRegistry meterRegistry, List<Tag> tags) {
9997
10098 /**
10199 * Construct an instance with the provided {@link MeterRegistry}, tags and {@link TaskScheduler}.
102- *
103100 * @param meterRegistry the registry.
104101 * @param tags the tags.
105102 * @param taskScheduler the task scheduler.
@@ -112,7 +109,12 @@ protected KafkaMetricsSupport(MeterRegistry meterRegistry, List<Tag> tags, TaskS
112109 this .scheduler = obtainScheduledExecutorService (taskScheduler );
113110 }
114111
115- protected void clientAdded (String id , C client ) {
112+ /**
113+ * Bind metrics for the Apache Kafka client with provided id.
114+ * @param id the unique identifier for the client to manage in store.
115+ * @param client the Kafka client instance to bind.
116+ */
117+ protected final void bindClient (String id , C client ) {
116118 if (!this .metrics .containsKey (id )) {
117119 List <Tag > clientTags = new ArrayList <>(this .tags );
118120 clientTags .add (new ImmutableTag ("spring.id" , id ));
@@ -121,6 +123,15 @@ protected void clientAdded(String id, C client) {
121123 }
122124 }
123125
126+ /**
127+ * Create a {@code io.micrometer.core.instrument.binder.kafka.KafkaMetrics} instance
128+ * for the provided Kafka client and metric tags.
129+ * By default, this factory is aware of {@link Consumer}, {@link Producer} and {@link AdminClient} types.
130+ * For other use-case this method can be overridden.
131+ * @param client the client to create a {@code io.micrometer.core.instrument.binder.kafka.KafkaMetrics} instance for.
132+ * @param tags the tags for the {@code io.micrometer.core.instrument.binder.kafka.KafkaMetrics}.
133+ * @return the {@code io.micrometer.core.instrument.binder.kafka.KafkaMetrics}.
134+ */
124135 protected MeterBinder createClientMetrics (C client , List <Tag > tags ) {
125136 if (client instanceof Consumer <?, ?> consumer ) {
126137 return createConsumerMetrics (consumer , tags );
@@ -153,7 +164,12 @@ private KafkaClientMetrics createAdminMetrics(AdminClient adminClient, List<Tag>
153164 : new KafkaClientMetrics (adminClient , tags );
154165 }
155166
156- protected void clientRemoved (String id , C client ) {
167+ /**
168+ * Unbind a {@code io.micrometer.core.instrument.binder.kafka.KafkaMetrics} for the provided Kafka client.
169+ * @param id the unique identifier for the client to manage in store.
170+ * @param client the Kafka client instance to unbind.
171+ */
172+ protected final void unbindClient (String id , C client ) {
157173 AutoCloseable removed = (AutoCloseable ) this .metrics .remove (id );
158174 if (removed != null ) {
159175 try {
0 commit comments