hachikuji commented on code in PR #12227:
URL: https://github.com/apache/kafka/pull/12227#discussion_r885101221


##########
clients/src/main/java/org/apache/kafka/clients/producer/internals/RecordAccumulator.java:
##########
@@ -195,29 +193,17 @@ public RecordAccumulator(LogContext logContext,
     }
 
     private void registerMetrics(Metrics metrics, String metricGrpName) {
-        MetricName metricName = metrics.metricName("waiting-threads", 
metricGrpName, "The number of user threads blocked waiting for buffer memory to 
enqueue their records");
-        Measurable waitingThreads = new Measurable() {
-            public double measure(MetricConfig config, long now) {
-                return free.queued();
-            }
-        };
-        metrics.addMetric(metricName, waitingThreads);
+        MetricName metricName = metrics.metricName("waiting-threads", 
metricGrpName,
+            "The number of user threads blocked waiting for buffer memory to 
enqueue their records");
+        metrics.addMetric(metricName, (config, now) -> free.queued());
 
-        metricName = metrics.metricName("buffer-total-bytes", metricGrpName, 
"The maximum amount of buffer memory the client can use (whether or not it is 
currently used).");
-        Measurable totalBytes = new Measurable() {
-            public double measure(MetricConfig config, long now) {
-                return free.totalMemory();
-            }
-        };
-        metrics.addMetric(metricName, totalBytes);
+        metricName = metrics.metricName("buffer-total-bytes", metricGrpName,

Review Comment:
   While we're at it, these redefinitions are a little annoying. Could we 
create a little helper or just use different variables? e.g.:
   ```java
           MetricName waitingThreadsName = 
metrics.metricName("waiting-threads", metricGrpName,
               "The number of user threads blocked waiting for buffer memory to 
enqueue their records");
           metrics.addMetric(waitingThreadsName, (config, now) -> 
free.queued());
   ...
   ```



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