i3wangyi commented on a change in pull request #490: Add latency metric components for WAGED rebalancer URL: https://github.com/apache/helix/pull/490#discussion_r331592834
########## File path: helix-core/src/main/java/org/apache/helix/controller/stages/BestPossibleStateCalcStage.java ########## @@ -253,20 +258,41 @@ private boolean validateOfflineInstancesLimit(final ResourceControllerDataProvid Map<String, IdealState> newIdealStates = new HashMap<>(); // Init rebalancer with the rebalance preferences. - Map<ClusterConfig.GlobalRebalancePreferenceKey, Integer> preferences = cache.getClusterConfig() - .getGlobalRebalancePreference(); + Map<ClusterConfig.GlobalRebalancePreferenceKey, Integer> preferences = + cache.getClusterConfig().getGlobalRebalancePreference(); + + if (METRIC_COLLECTOR_THREAD_LOCAL.get() == null) { + try { + // If HelixManager is null, we just pass in null for MetricCollector so that a + // non-functioning WagedRebalancerMetricCollector would be created in WagedRebalancer's + // constructor. This is to handle two cases: 1. HelixManager is null for non-testing cases - + // in this case, WagedRebalancer will not read/write to metadata store and just use + // CurrentState-based rebalancing. 2. Tests that require instrumenting the rebalancer for + // verifying whether the cluster has converged. + METRIC_COLLECTOR_THREAD_LOCAL.set(helixManager == null ? null + : new WagedRebalancerMetricCollector(helixManager.getClusterName())); + } catch (JMException e) { + LogUtil.logWarn(logger, _eventId, String.format( + "MetricCollector instantiation failed! WagedRebalancer will not emit metrics due to JMException %s", + e)); + } + } + // TODO avoid creating the rebalancer on every rebalance call for performance enhancement - WagedRebalancer wagedRebalancer = new WagedRebalancer(helixManager, preferences); + WagedRebalancer wagedRebalancer = + new WagedRebalancer(helixManager, preferences, METRIC_COLLECTOR_THREAD_LOCAL.get()); Review comment: In the case of Exception, what's the value? Is it null? ---------------------------------------------------------------- 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: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@helix.apache.org For additional commands, e-mail: reviews-h...@helix.apache.org