github-advanced-security[bot] commented on code in PR #19013:
URL: https://github.com/apache/druid/pull/19013#discussion_r2796365143


##########
processing/src/test/java/org/apache/druid/java/util/metrics/JvmMonitorTest.java:
##########
@@ -56,6 +62,109 @@
     }
   }
 
+  @Test
+  public void testGcNotificationMetricsEmitted()
+  {
+    EventCollectingEmitter emitter = new EventCollectingEmitter();
+    final ServiceEmitter serviceEmitter = new ServiceEmitter("test", 
"localhost", emitter);
+    serviceEmitter.start();
+
+    final JvmMonitor jvmMonitor = new JvmMonitor();
+    jvmMonitor.start();
+    jvmMonitor.doMonitor(serviceEmitter);
+
+    Set<String> metricNames = emitter.events.stream()
+        .map(e -> ((ServiceMetricEvent) e).getMetric())
+        .collect(Collectors.toSet());
+
+    // Rate/gauge metrics should always be emitted (even if zero)
+    Assert.assertTrue("Expected jvm/gc/allocationRate/bytes", 
metricNames.contains("jvm/gc/allocationRate/bytes"));
+    Assert.assertTrue("Expected jvm/gc/promotionRate/bytes", 
metricNames.contains("jvm/gc/promotionRate/bytes"));
+    Assert.assertTrue("Expected jvm/gc/liveDataSize/bytes", 
metricNames.contains("jvm/gc/liveDataSize/bytes"));
+    Assert.assertTrue("Expected jvm/gc/maxDataSize/bytes", 
metricNames.contains("jvm/gc/maxDataSize/bytes"));
+
+    // Verify jvmVersion dimension on the new metrics
+    for (Event e : emitter.events) {
+      ServiceMetricEvent event = (ServiceMetricEvent) e;
+      String metric = event.getMetric();
+      if (metric.startsWith("jvm/gc/allocationRate")
+          || metric.startsWith("jvm/gc/promotionRate")
+          || metric.startsWith("jvm/gc/liveDataSize")
+          || metric.startsWith("jvm/gc/maxDataSize")) {
+        Map<String, Object> map = event.toMap();
+        Assert.assertNotNull("jvmVersion dimension should be set on " + 
metric, map.get("jvmVersion"));
+      }
+    }
+
+    jvmMonitor.stop();
+  }
+
+  @Test(timeout = 60_000L)
+  public void testPauseMetricsHaveDimensions() throws InterruptedException
+  {
+    EventCollectingEmitter emitter = new EventCollectingEmitter();
+    final ServiceEmitter serviceEmitter = new ServiceEmitter("test", 
"localhost", emitter);
+    serviceEmitter.start();
+
+    final JvmMonitor jvmMonitor = new JvmMonitor();
+    jvmMonitor.start();
+
+    // Generate garbage to trigger GC events
+    while (true) {
+      @SuppressWarnings("unused")
+      byte[] b = new byte[1024 * 1024 * 50];

Review Comment:
   ## Unread local variable
   
   Variable 'byte\[\] b' is never read.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/10813)



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to