tibrewalpratik17 commented on code in PR #14064:
URL: https://github.com/apache/pinot/pull/14064#discussion_r1775948765
##########
pinot-common/src/test/java/org/apache/pinot/common/metrics/AbstractMetricsTest.java:
##########
@@ -268,4 +274,157 @@ public void testMeteredMetrics() {
testMetrics.getMetricsRegistry().allMetrics().keySet().forEach(testMetrics.getMetricsRegistry()::removeMetric);
Assert.assertTrue(testMetrics.getMetricsRegistry().allMetrics().isEmpty());
}
+
+ @Test
+ public void testGlobalGaugeMetricsAsyncAddRemove() throws
ExecutionException, InterruptedException {
+ ControllerMetrics controllerMetrics = buildTestMetrics();
+ int gaugeOperationsRuntimeMs = 100;
+
+ ExecutorService executorService = Executors.newFixedThreadPool(2);
+ long endTime = System.currentTimeMillis() + gaugeOperationsRuntimeMs;
+
+ Future<?> addFuture = executorService.submit(() -> {
+ while (System.currentTimeMillis() < endTime + gaugeOperationsRuntimeMs) {
+ controllerMetrics.addValueToGlobalGauge(ControllerGauge.VERSION, 1L);
+ }
+ });
+ Future<?> removeFuture = executorService.submit(() -> {
+ while (System.currentTimeMillis() < endTime) {
+ controllerMetrics.removeGauge(ControllerGauge.VERSION.getGaugeName());
+ }
+ });
+
+ addFuture.get();
+ removeFuture.get();
+
+ executorService.shutdown();
+ boolean terminated = executorService.awaitTermination(1, TimeUnit.SECONDS);
+ Assert.assertTrue(terminated, "Tasks should complete and executor should
shut down after 1 seconds.");
+
Assert.assertFalse(controllerMetrics.getMetricsRegistry().allMetrics().isEmpty());
+
+ Long gaugeValue =
controllerMetrics.getGaugeValue(ControllerGauge.VERSION.getGaugeName());
+ Assert.assertNotNull(gaugeValue);
+ Assert.assertTrue(gaugeValue > 0);
+ }
+
+ @Test
+ public void testTableGaugeMetricsAsyncAddRemove() throws ExecutionException,
InterruptedException {
+ ControllerMetrics controllerMetrics = buildTestMetrics();
+ int gaugeOperationsRuntimeMs = 100;
+
+ ExecutorService executorService = Executors.newFixedThreadPool(2);
+ long endTime = System.currentTimeMillis() + gaugeOperationsRuntimeMs;
+
+ Future<?> addFuture = executorService.submit(() -> {
+ while (System.currentTimeMillis() < endTime + gaugeOperationsRuntimeMs) {
+ controllerMetrics.addValueToTableGauge("test_table",
ControllerGauge.VERSION, 1L);
+ }
+ });
+ Future<?> removeFuture = executorService.submit(() -> {
+ while (System.currentTimeMillis() < endTime) {
+ controllerMetrics.removeTableGauge("test_table",
ControllerGauge.VERSION);
+ }
+ });
+
+ addFuture.get();
+ removeFuture.get();
+
+ executorService.shutdown();
+ boolean terminated = executorService.awaitTermination(1, TimeUnit.SECONDS);
+ Assert.assertTrue(terminated, "Tasks should complete and executor should
shut down after 1 seconds.");
+
Assert.assertFalse(controllerMetrics.getMetricsRegistry().allMetrics().isEmpty());
+
+ Long gaugeValue =
controllerMetrics.getGaugeValue(ControllerGauge.VERSION.getGaugeName() +
".test_table");
+ Assert.assertNotNull(gaugeValue);
+ Assert.assertTrue(gaugeValue > 0);
+ }
+
+ @Test
+ public void testInitializeGlobalMeters() {
+ ControllerMetrics controllerMetrics = buildTestMetrics();
+
+ controllerMetrics.initializeGlobalMeters();
+
Assert.assertFalse(controllerMetrics.getMetricsRegistry().allMetrics().isEmpty());
+ Assert.assertEquals(0,
controllerMetrics.getGaugeValue(ControllerGauge.VERSION.getGaugeName()));
Review Comment:
nit: Here we can loop through controllerMetrics.getMeters() and filter out
the ones where `isGlobal` is true to validate all global meters will be init to
0.
--
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]