chia7712 commented on code in PR #16618:
URL: https://github.com/apache/kafka/pull/16618#discussion_r1683727988


##########
server-common/src/main/java/org/apache/kafka/server/metrics/KafkaMetricsGroup.java:
##########
@@ -70,16 +71,26 @@ public static MetricName explicitMetricName(String group, 
String typeName,
         return new MetricName(group, typeName, name, scope, 
nameBuilder.toString());
     }
 
-    public final <T> Gauge<T> newGauge(String name, Gauge<T> metric, 
Map<String, String> tags) {
-        return KafkaYammerMetrics.defaultRegistry().newGauge(metricName(name, 
tags), metric);
+    public <T> Gauge<T> newGauge(String name, Supplier<T> metric, Map<String, 
String> tags) {
+        return KafkaYammerMetrics.defaultRegistry().newGauge(metricName(name, 
tags), new Gauge<T>() {

Review Comment:
   how about `return newGauge(metricName(name, tags), metric);`?



##########
storage/src/main/java/org/apache/kafka/storage/internals/log/RemoteStorageThreadPool.java:
##########
@@ -51,18 +50,10 @@ public String logPrefix() {
             }
         }.logger(RemoteStorageThreadPool.class);
 
-        
metricsGroup.newGauge(REMOTE_LOG_READER_TASK_QUEUE_SIZE_METRIC.getName(), new 
Gauge<Integer>() {
-            @Override
-            public Integer value() {
-                return RemoteStorageThreadPool.this.getQueue().size();
-            }
-        });
-        
metricsGroup.newGauge(REMOTE_LOG_READER_AVG_IDLE_PERCENT_METRIC.getName(), new 
Gauge<Double>() {
-            @Override
-            public Double value() {
-                return 1 - (double) 
RemoteStorageThreadPool.this.getActiveCount() / (double) 
RemoteStorageThreadPool.this.getCorePoolSize();
-            }
-        });
+        
metricsGroup.newGauge(REMOTE_LOG_READER_TASK_QUEUE_SIZE_METRIC.getName(),
+                () -> RemoteStorageThreadPool.this.getQueue().size());

Review Comment:
   how about `getQueue().size()` ?



##########
storage/src/main/java/org/apache/kafka/storage/internals/log/RemoteStorageThreadPool.java:
##########
@@ -51,18 +50,10 @@ public String logPrefix() {
             }
         }.logger(RemoteStorageThreadPool.class);
 
-        
metricsGroup.newGauge(REMOTE_LOG_READER_TASK_QUEUE_SIZE_METRIC.getName(), new 
Gauge<Integer>() {
-            @Override
-            public Integer value() {
-                return RemoteStorageThreadPool.this.getQueue().size();
-            }
-        });
-        
metricsGroup.newGauge(REMOTE_LOG_READER_AVG_IDLE_PERCENT_METRIC.getName(), new 
Gauge<Double>() {
-            @Override
-            public Double value() {
-                return 1 - (double) 
RemoteStorageThreadPool.this.getActiveCount() / (double) 
RemoteStorageThreadPool.this.getCorePoolSize();
-            }
-        });
+        
metricsGroup.newGauge(REMOTE_LOG_READER_TASK_QUEUE_SIZE_METRIC.getName(),
+                () -> RemoteStorageThreadPool.this.getQueue().size());
+        
metricsGroup.newGauge(REMOTE_LOG_READER_AVG_IDLE_PERCENT_METRIC.getName(),
+                () -> 1 - (double) 
RemoteStorageThreadPool.this.getActiveCount() / (double) 
RemoteStorageThreadPool.this.getCorePoolSize());

Review Comment:
   ditto



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