Nagarjunanm commented on code in PR #20559:
URL: https://github.com/apache/druid/pull/20559#discussion_r4316318936


##########
extensions-contrib/kafka-emitter/src/test/java/org/apache/druid/emitter/kafka/KafkaEmitterTest.java:
##########
@@ -673,4 +696,462 @@ public String getFeed()
       return "testFeed";
     }
   }
+
+  // ==================== Sampling Tests ====================
+
+  @Test
+  public void testShouldSampleOut_noSamplingWhenRateIs100()
+  {
+    final KafkaEmitter emitter = initKafkaEmitter(newSamplingConfig(100, 
ImmutableSet.of("query/time"), null));
+    ServiceMetricEvent event = 
ServiceMetricEvent.builder().setMetric("query/time", 100).build("svc", "host");
+    Assertions.assertFalse(emitter.shouldSampleOut(event));
+  }
+
+  @Test
+  public void testShouldSampleOut_noSamplingWhenSampledMetricsEmpty()
+  {
+    final KafkaEmitter emitter = initKafkaEmitter(newSamplingConfig(100, null, 
null));
+    ServiceMetricEvent event = 
ServiceMetricEvent.builder().setMetric("query/time", 100).build("svc", "host");
+    Assertions.assertFalse(emitter.shouldSampleOut(event));
+  }
+
+  /**
+   * samplingRate=10, both sampledMetrics and sampledNodeTypes empty → samples 
ALL metrics at 10%.
+   * With rate=0 we can deterministically assert true.
+   */
+  @Test
+  public void testShouldSampleOut_samplesAllWhenRateSetButFiltersEmpty()
+  {
+    final KafkaEmitter emitter = initKafkaEmitter(newSamplingConfig(0, null, 
null));

Review Comment:
   Thanks, the Javadoc was out of date. Fixed it: it now explains that the test 
uses rate 0 so that the result is deterministic.



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