guozhangwang commented on code in PR #12121:
URL: https://github.com/apache/kafka/pull/12121#discussion_r895970308


##########
clients/src/main/java/org/apache/kafka/common/metrics/Metrics.java:
##########
@@ -509,7 +509,10 @@ public void addMetric(MetricName metricName, MetricConfig 
config, MetricValuePro
                                         
Objects.requireNonNull(metricValueProvider),
                                         config == null ? this.config : config,
                                         time);
-        registerMetric(m);
+        KafkaMetric existingMetric = registerMetric(m);

Review Comment:
   Could we clarify in the javadoc above that if the metric already exists, an 
exception would be thrown?



##########
clients/src/main/java/org/apache/kafka/common/metrics/Metrics.java:
##########
@@ -563,10 +586,18 @@ public synchronized void removeReporter(MetricsReporter 
reporter) {
         }
     }
 
-    synchronized void registerMetric(KafkaMetric metric) {
+    /**
+     * Register a metric if not present or return an already existing metric 
otherwise.
+     * 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

Review Comment:
   nit: we can just say "the existing metric with the same name"



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to