You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by GitBox <gi...@apache.org> on 2022/06/13 17:35:42 UTC

[GitHub] [kafka] guozhangwang commented on a diff in pull request #12121: KAFKA-13846: Adding overloaded metricOrElseCreate method

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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org