Skip to content

Commit 9b9d0be

Browse files
Add an extra ctor, javadoc, polish
1 parent aba85b3 commit 9b9d0be

File tree

1 file changed

+49
-17
lines changed

1 file changed

+49
-17
lines changed

micrometer-core/src/main/java/io/micrometer/core/instrument/binder/kafka/KafkaClientMetrics.java

Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -227,37 +227,69 @@ public KafkaClientMetrics(AdminClient adminClient) {
227227
}
228228

229229
/**
230-
* Kafka client metrics binder
231-
* @param metricsSupplier supplier of metrics, make sure this comes from the Java
232-
* Kafka Client because {@link KafkaClientMetrics} heavily depends on the behavior of
233-
* the Java Kafka Client
230+
* Kafka client metrics binder. The lifecycle of the custom scheduler passed is the
231+
* responsibility of the caller. It will not be shut down when this instance is
232+
* {@link #close() closed}. A scheduler can be shared among multiple instances of
233+
* {@link KafkaClientMetrics} to reduce resource usage by reducing the number of
234+
* threads if there will be many instances.
235+
* @param metricsSupplier supplier of Kafka metrics, should come from the Java Kafka
236+
* Client
237+
* @param tags additional tags
238+
* @param scheduler custom scheduler to check and bind metrics
239+
* @since 1.16.0
234240
*/
235-
public KafkaClientMetrics(Supplier<Map<MetricName, ? extends Metric>> metricsSupplier) {
236-
super(metricsSupplier);
241+
public KafkaClientMetrics(Supplier<Map<MetricName, ? extends Metric>> metricsSupplier, Iterable<Tag> tags,
242+
ScheduledExecutorService scheduler) {
243+
super(metricsSupplier, tags, scheduler);
244+
}
245+
246+
/**
247+
* Kafka client metrics binder. The lifecycle of the custom scheduler passed is the
248+
* responsibility of the caller. It will not be shut down when this instance is
249+
* {@link #close() closed}. A scheduler can be shared among multiple instances of
250+
* {@link KafkaClientMetrics} to reduce resource usage by reducing the number of
251+
* threads if there will be many instances.
252+
* <p>
253+
* The refresh interval governs how frequently Micrometer should call the Kafka
254+
* Client's Metrics API to discover new metrics to register and discard old ones since
255+
* the Kafka Client can add/remove/recreate metrics on-the-fly. Please notice that
256+
* this is not for fetching values for already registered metrics but for updating the
257+
* list of registered metrics when the Kafka Client adds/removes/recreates them. It is
258+
* the responsibility of the caller to choose the right value since this process can
259+
* be expensive and metrics can appear and disappear without being published if the
260+
* interval is not chosen appropriately.
261+
* @param metricsSupplier supplier of Kafka metrics, should come from the Java Kafka
262+
* Client
263+
* @param tags additional tags
264+
* @param scheduler custom scheduler to check and bind metrics
265+
* @param refreshInterval interval of discovering new/removed/recreated metrics by the
266+
* Kafka Client
267+
* @since 1.16.0
268+
*/
269+
public KafkaClientMetrics(Supplier<Map<MetricName, ? extends Metric>> metricsSupplier, Iterable<Tag> tags,
270+
ScheduledExecutorService scheduler, Duration refreshInterval) {
271+
super(metricsSupplier, tags, scheduler, refreshInterval);
237272
}
238273

239274
/**
240275
* Kafka client metrics binder
241-
* @param metricsSupplier supplier of metrics, make sure this comes from the Java
242-
* Kafka Client because {@link KafkaClientMetrics} heavily depends on the behavior of
243-
* the Java Kafka Client
276+
* @param metricsSupplier supplier of Kafka metrics, should come from the Java Kafka
277+
* Client
244278
* @param tags additional tags
279+
* @since 1.16.0
245280
*/
246281
public KafkaClientMetrics(Supplier<Map<MetricName, ? extends Metric>> metricsSupplier, Iterable<Tag> tags) {
247282
super(metricsSupplier, tags);
248283
}
249284

250285
/**
251286
* Kafka client metrics binder
252-
* @param metricsSupplier supplier of metrics, make sure this comes from the Java
253-
* Kafka Client because {@link KafkaClientMetrics} heavily depends on the behavior of
254-
* the Java Kafka Client
255-
* @param tags additional tags
256-
* @param scheduler custom scheduler to check and bind metrics
287+
* @param metricsSupplier supplier of Kafka metrics, should come from the Java Kafka
288+
* Client
289+
* @since 1.16.0
257290
*/
258-
public KafkaClientMetrics(Supplier<Map<MetricName, ? extends Metric>> metricsSupplier, Iterable<Tag> tags,
259-
ScheduledExecutorService scheduler) {
260-
super(metricsSupplier, tags, scheduler);
291+
public KafkaClientMetrics(Supplier<Map<MetricName, ? extends Metric>> metricsSupplier) {
292+
super(metricsSupplier);
261293
}
262294

263295
}

0 commit comments

Comments
 (0)