narendly commented on a change in pull request #525: Add waged rebalancer
monitoring mbean metrics
URL: https://github.com/apache/helix/pull/525#discussion_r338329667
##########
File path:
helix-core/src/test/java/org/apache/helix/controller/rebalancer/waged/TestWagedRebalancerMetrics.java
##########
@@ -85,7 +90,59 @@ public void testMetricValuePropagation()
// Check that there exists a non-zero value in the metrics
Assert.assertTrue(_metricCollector.getMetricMap().values().stream()
- .anyMatch(metric -> metric.getLastEmittedMetricValue() > 0L));
+ .anyMatch(metric -> (long) metric.getLastEmittedMetricValue() > 0L));
+ }
+
+ @Test
+ public void testWagedRebalanceMetrics()
+ throws JMException, IOException, HelixRebalanceException {
+ _metadataStore.clearMetadataStore();
+ MetricCollector metricCollector = new
WagedRebalancerMetricCollector(TEST_STRING);
+ WagedRebalancer rebalancer = new WagedRebalancer(_metadataStore,
_algorithm, metricCollector);
+ // Generate the input for the rebalancer.
+ ResourceControllerDataProvider clusterData = setupClusterDataCache();
+ Map<String, Resource> resourceMap =
clusterData.getIdealStates().entrySet().stream()
+ .collect(Collectors.toMap(entry -> entry.getKey(), entry -> {
+ Resource resource = new Resource(entry.getKey());
+ entry.getValue().getPartitionSet().stream()
+ .forEach(partition -> resource.addPartition(partition));
+ return resource;
+ }));
+
+ Assert.assertEquals((long) metricCollector.getMetric(
+
WagedRebalancerMetricCollector.WagedRebalancerMetricNames.GlobalBaselineCalcCounter.name(),
+ CountMetric.class).getLastEmittedMetricValue(), 0L);
+ Assert.assertEquals((long) metricCollector.getMetric(
+
WagedRebalancerMetricCollector.WagedRebalancerMetricNames.PartialRebalanceCounter.name(),
+ CountMetric.class).getLastEmittedMetricValue(), 0L);
+ // -1.0d means metric value is not set.
+ Assert.assertEquals((double) metricCollector.getMetric(
+
WagedRebalancerMetricCollector.WagedRebalancerMetricNames.BaselineDivergenceGauge.name(),
+ RatioMetric.class).getLastEmittedMetricValue(), -1.0d);
+
+ // Cluster config change will trigger baseline recalculation and partial
rebalance.
+ when(clusterData.getRefreshedChangeTypes())
+
.thenReturn(Collections.singleton(HelixConstants.ChangeType.CLUSTER_CONFIG));
+
+ rebalancer.computeBestPossibleStates(clusterData, resourceMap, new
CurrentStateOutput());
+
+ Assert.assertEquals((long) metricCollector.getMetric(
+
WagedRebalancerMetricCollector.WagedRebalancerMetricNames.GlobalBaselineCalcCounter.name(),
+ CountMetric.class).getLastEmittedMetricValue(), 1L);
+ Assert.assertEquals((long) metricCollector.getMetric(
+
WagedRebalancerMetricCollector.WagedRebalancerMetricNames.PartialRebalanceCounter.name(),
+ CountMetric.class).getLastEmittedMetricValue(), 1L);
+
+ // Wait for asyncReportBaselineDivergenceGauge to complete.
+ try {
+ Thread.sleep(200L);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+
+ Assert.assertEquals((double) metricCollector.getMetric(
+
WagedRebalancerMetricCollector.WagedRebalancerMetricNames.BaselineDivergenceGauge.name(),
+ RatioMetric.class).getLastEmittedMetricValue(), 1.0d);
Review comment:
Please avoid using Thread.sleep(x). It introduces instability into our test
suite.
In this case, you could do a variable amount of waiting using
`TestHelper.verify()` that dynamically waits until getLastEmittedMetricValue()
gives 1.0d.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]