apoorvmittal10 commented on code in PR #22129:
URL: https://github.com/apache/kafka/pull/22129#discussion_r3324948817


##########
clients/src/main/java/org/apache/kafka/common/metrics/KafkaMetric.java:
##########
@@ -124,4 +124,25 @@ public void config(MetricConfig config) {
             this.config = config;
         }
     }
+
+    /**
+     * Returns a human-readable representation of this metric, primarily 
useful for logging
+     * in contexts like {@link MetricsReporter#metricChange(KafkaMetric)}.

Review Comment:
   Same here, as above.



##########
clients/src/test/java/org/apache/kafka/common/metrics/KafkaMetricTest.java:
##########
@@ -70,7 +76,61 @@ public void 
testKafkaMetricAcceptsNonMeasurableNonGaugeProvider() {
     @Test
     public void testConstructorWithNullProvider() {
         assertThrows(NullPointerException.class, () ->
-                new KafkaMetric(new Object(), METRIC_NAME, null, new 
MetricConfig(), new MockTime())
+                new KafkaMetric(new Object(), METRIC_NAME_1, null, new 
MetricConfig(), new MockTime())
         );
     }
+
+    /**
+     * Verifies that toString produces a human-readable representation 
suitable for logging.
+     * Note that we skip the metric provider in this case, but this is still a
+     * significant improvement over the default Object.toString() output (e.g. 
"KafkaMetric@62a7d6c6").
+     */
+    @Test
+    public void testToStringWithLambdaProvider() {
+        Measurable metricValueProvider = (config, now) -> 0;
+        testToStringOnLambdaOrAnonymousClass(metricValueProvider);
+    }
+
+    /**
+     * Verifies that toString produces a human-readable representation 
suitable for logging,
+     * e.g. in {@link 
org.apache.kafka.common.metrics.MetricsReporter#metricChange(KafkaMetric)}.

Review Comment:
   Again this line is not helpful



-- 
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