showuon commented on code in PR #15133:
URL: https://github.com/apache/kafka/pull/15133#discussion_r1448610306


##########
core/src/test/java/kafka/log/remote/RemoteLogManagerTest.java:
##########
@@ -860,28 +871,39 @@ void testRemoteLogManagerRemoteMetrics() throws Exception 
{
         when(mockLog.onlyLocalLogSegmentsCount()).thenReturn(1L);
 
         // before running tasks, the metric should not be registered
-        assertThrows(NoSuchElementException.class, () -> 
yammerMetricValue("RemoteCopyLagBytes"));
-        assertThrows(NoSuchElementException.class, () -> 
yammerMetricValue("RemoteCopyLagSegments"));
-        assertThrows(NoSuchElementException.class, () -> 
yammerMetricValue("RemoteLogSizeComputationTime"));
+        assertThrows(NoSuchElementException.class, () -> 
yammerMetricValue("RemoteCopyLagBytes,topic=" + leaderTopic));
+        assertThrows(NoSuchElementException.class, () -> 
yammerMetricValue("RemoteCopyLagSegments,topic=" + leaderTopic));
+        assertThrows(NoSuchElementException.class, () -> 
yammerMetricValue("RemoteLogSizeComputationTime,topic=" + leaderTopic));
+        // all topic metrics should be 0
+        assertEquals(0L, yammerMetricValue("RemoteCopyLagBytes"));
+        assertEquals(0L, yammerMetricValue("RemoteCopyLagSegments"));
+        assertEquals(0L, yammerMetricValue("RemoteLogSizeComputationTime"));
+
         
remoteLogManager.onLeadershipChange(Collections.singleton(mockLeaderPartition), 
Collections.emptySet(), topicIds);
         TestUtils.waitForCondition(
-                () -> 75 == safeLongYammerMetricValue("RemoteCopyLagBytes"),
-                String.format("Expected to find 75 for RemoteCopyLagBytes 
metric value, but found %d", safeLongYammerMetricValue("RemoteCopyLagBytes")));
+                () -> 75 == safeLongYammerMetricValue("RemoteCopyLagBytes") && 
75 == safeLongYammerMetricValue("RemoteCopyLagBytes,topic=" + leaderTopic),
+                String.format("Expected to find 75 for RemoteCopyLagBytes 
metric value, but found %d for topic 'Leader' and %d for all topics.",
+                        safeLongYammerMetricValue("RemoteCopyLagBytes,topic=" 
+ leaderTopic),
+                        safeLongYammerMetricValue("RemoteCopyLagBytes")));
         TestUtils.waitForCondition(
-                () -> 1 == safeLongYammerMetricValue("RemoteCopyLagSegments"),
-                String.format("Expected to find 1 for RemoteCopyLagSegments 
metric value, but found %d", 
safeLongYammerMetricValue("RemoteCopyLagSegments")));
+                () -> 1 == safeLongYammerMetricValue("RemoteCopyLagSegments") 
&& 1 == safeLongYammerMetricValue("RemoteCopyLagSegments,topic=" + leaderTopic),
+                String.format("Expected to find 1 for RemoteCopyLagSegments 
metric value, but found %d for topic 'Leader' and %d for all topics.",
+                        
safeLongYammerMetricValue("RemoteCopyLagSegments,topic=" + leaderTopic),
+                        safeLongYammerMetricValue("RemoteCopyLagSegments")));
         // unlock copyLogSegmentData
         latch.countDown();
 
         TestUtils.waitForCondition(
-                () -> 
safeLongYammerMetricValue("RemoteLogSizeComputationTime") >= 1000,
-                String.format("Expected to find 1000 for 
RemoteLogSizeComputationTime metric value, but found %d", 
safeLongYammerMetricValue("RemoteLogSizeComputationTime")));
+                () -> 
safeLongYammerMetricValue("RemoteLogSizeComputationTime") >= 1000 && 
safeLongYammerMetricValue("RemoteLogSizeComputationTime,topic=" + leaderTopic) 
>= 1000,
+                String.format("Expected to find 1000 for 
RemoteLogSizeComputationTime metric value, but found %d for topic 'Leader' and 
%d for all topics.",
+                        
safeLongYammerMetricValue("RemoteLogSizeComputationTime,topic=" + leaderTopic),
+                        
safeLongYammerMetricValue("RemoteLogSizeComputationTime")));
         remoteLogSizeComputationTimeLatch.countDown();
     }
 
     private Object yammerMetricValue(String name) {
         Gauge gauge = (Gauge) 
KafkaYammerMetrics.defaultRegistry().allMetrics().entrySet().stream()
-                .filter(e -> e.getKey().getMBeanName().contains(name))
+                .filter(e -> e.getKey().getMBeanName().endsWith(name))

Review Comment:
   Using `endsWith`, so that we can test the all topic metrics and the specific 
topic metrics. Ex:
   `kafka.server:type=BrokerTopicMetrics,name=RemoteCopyLagSegments` and
   
`kafka.server:type=BrokerTopicMetrics,name=RemoteCopyLagSegments,topic=Leader`



-- 
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-unsubscr...@kafka.apache.org

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

Reply via email to