From 2700414abf29362ace3953d5ce8e70a5b17b52f9 Mon Sep 17 00:00:00 2001 From: Sagar Rao Date: Wed, 15 Jun 2022 23:19:13 +0530 Subject: [PATCH 1/4] KAFKA-13846: Follow up PR to address review comments --- .../org/apache/kafka/common/metrics/Metrics.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/clients/src/main/java/org/apache/kafka/common/metrics/Metrics.java b/clients/src/main/java/org/apache/kafka/common/metrics/Metrics.java index 398819016cb5b..a7581442f5d12 100644 --- a/clients/src/main/java/org/apache/kafka/common/metrics/Metrics.java +++ b/clients/src/main/java/org/apache/kafka/common/metrics/Metrics.java @@ -502,6 +502,7 @@ public void addMetric(MetricName metricName, MetricConfig config, Measurable mea * * @param metricName The name of the metric * @param metricValueProvider The metric value provider associated with this metric + * @throws IllegalArgumentException if a metric with same name already exists. */ public void addMetric(MetricName metricName, MetricConfig config, MetricValueProvider metricValueProvider) { KafkaMetric m = new KafkaMetric(new Object(), @@ -587,18 +588,19 @@ public synchronized void removeReporter(MetricsReporter reporter) { } /** - * Register a metric if not present or return an already existing metric otherwise. + * Register a metric if not present or return the already existing metric with the same name. * When a metric is newly registered, this method returns null * * @param metric The KafkaMetric to register - * @return KafkaMetric if the metric already exists, null otherwise + * @return the existing metric with the same name or null */ synchronized KafkaMetric registerMetric(KafkaMetric metric) { MetricName metricName = metric.metricName(); - if (this.metrics.containsKey(metricName)) { - return this.metrics.get(metricName); + KafkaMetric existingMetric = this.metrics.putIfAbsent(metricName, metric); + if (existingMetric != null) { + return existingMetric; } - this.metrics.put(metricName, metric); + // newly added metric for (MetricsReporter reporter : reporters) { try { reporter.metricChange(metric); From a658a9d3f4f3b96b2d302d4c5c3e49bbfc05286c Mon Sep 17 00:00:00 2001 From: Sagar Rao Date: Thu, 16 Jun 2022 18:11:32 +0530 Subject: [PATCH 2/4] Updating docs --- docs/upgrade.html | 56 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 53 insertions(+), 3 deletions(-) diff --git a/docs/upgrade.html b/docs/upgrade.html index b29259aa2b8b0..56691fde9b1ac 100644 --- a/docs/upgrade.html +++ b/docs/upgrade.html @@ -19,6 +19,56 @@