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


##########
clients/src/test/java/org/apache/kafka/clients/consumer/internals/FetchMetricsManagerTest.java:
##########
@@ -66,14 +69,41 @@ public void tearDown() {
 
     @Test
     public void testLatency() {
-        metricsManager.recordLatency(123);
+        metricsManager.recordLatency("", 123);
         time.sleep(metrics.config().timeWindowMs() + 1);
-        metricsManager.recordLatency(456);
+        metricsManager.recordLatency("", 456);
 
         assertEquals(289.5, metricValue(metricsRegistry.fetchLatencyAvg), 
EPSILON);
         assertEquals(456, metricValue(metricsRegistry.fetchLatencyMax), 
EPSILON);
     }
 
+    @Test
+    public void testNodeLatency() {
+        String connectionId = "0";
+        MetricName nodeLatencyAvg = metrics.metricName("request-latency-avg", 
"group");
+        MetricName nodeLatencyMax = metrics.metricName("request-latency-max", 
"group");
+        registerNodeLatencyMetric(connectionId, nodeLatencyAvg, 
nodeLatencyMax);
+
+        metricsManager.recordLatency(connectionId, 123);
+        time.sleep(metrics.config().timeWindowMs() + 1);
+        metricsManager.recordLatency(connectionId, 456);
+
+        assertEquals(289.5, metricValue(metricsRegistry.fetchLatencyAvg), 
EPSILON);
+        assertEquals(456, metricValue(metricsRegistry.fetchLatencyMax), 
EPSILON);
+
+        assertEquals(289.5, metricValue(nodeLatencyAvg), EPSILON);
+        assertEquals(456, metricValue(nodeLatencyMax), EPSILON);
+
+        // Record metric against another node.
+        metricsManager.recordLatency("1", 501);
+
+        assertEquals(360, metricValue(metricsRegistry.fetchLatencyAvg), 
EPSILON);
+        assertEquals(501, metricValue(metricsRegistry.fetchLatencyMax), 
EPSILON);
+        // Node specific metric should not be affected.
+        assertEquals(289.5, metricValue(nodeLatencyAvg), EPSILON);
+        assertEquals(456, metricValue(nodeLatencyMax), EPSILON);

Review Comment:
   As the node metrics get registered in Selector.java, which cannot be spawned 
from FetchMetricsManagerTest, hence I added a node latency metric in tests to 
verify if the value is recorded for the node.
   
   As in the tests, we are not registering any node 1 sensor/metric hence it 
won't be found, so I don't find any valid validation here. I did check if the 
recordLatency method is called for some other node, then node-0 metrics should 
be unchanged.



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