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


##########
extensions-contrib/prometheus-emitter/src/test/java/org/apache/druid/emitter/prometheus/PrometheusEmitterTest.java:
##########
@@ -430,4 +434,78 @@
 
     EasyMock.verify(mockPushGateway);
   }
+
+  @Test
+  public void testMetricTtlExpiration()
+  {
+    Long metricTtl = 1000L;
+    PrometheusEmitterConfig config = new 
PrometheusEmitterConfig(PrometheusEmitterConfig.Strategy.exporter, "test", 
null, 0, null, false, true, 60, null, false, null, metricTtl);
+    PrometheusEmitter emitter = new PrometheusEmitter(config);
+    emitter.start();
+
+    ServiceMetricEvent event = ServiceMetricEvent.builder()
+                                                 
.setMetric("segment/loadQueue/count", 10)
+                                                 
.build(ImmutableMap.of("service", "historical", "host", "druid.test.cn"));
+    emitter.emit(event);
+
+    // Get the metrics and check that it's not expired initially
+    Map<String, DimensionsAndCollector> registeredMetrics = 
emitter.getMetrics().getRegisteredMetrics();
+    DimensionsAndCollector testMetric = 
registeredMetrics.get("segment/loadQueue/count");
+
+    Assert.assertNotNull("Test metric should be registered", testMetric);
+    Assert.assertFalse("Metric should not be expired initially",
+                       testMetric.isExpired(metricTtl));
+
+    // Wait for the metric to expire (ttl + 1 second buffer)
+    try {
+      Thread.sleep(metricTtl + 1000);
+    }
+    catch (InterruptedException e) {
+      Thread.currentThread().interrupt();
+    }
+
+    Assert.assertTrue("Metric should be expired after TTL",
+                      testMetric.isExpired(metricTtl));
+    emitter.close();
+  }
+
+  @Test
+  public void testMetricTtlUpdate()
+  {
+    Long metricTtl = 1000L;

Review Comment:
   ## Boxed variable is never null
   
   The variable 'metricTtl' is only assigned values of primitive type and is 
never 'null', but it is declared with the boxed type 'Long'.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/10494)



##########
extensions-contrib/prometheus-emitter/src/test/java/org/apache/druid/emitter/prometheus/PrometheusEmitterTest.java:
##########
@@ -430,4 +434,78 @@
 
     EasyMock.verify(mockPushGateway);
   }
+
+  @Test
+  public void testMetricTtlExpiration()
+  {
+    Long metricTtl = 1000L;

Review Comment:
   ## Boxed variable is never null
   
   The variable 'metricTtl' is only assigned values of primitive type and is 
never 'null', but it is declared with the boxed type 'Long'.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/10493)



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