Search in sources :

Example 11 with BrokerEntity

use of com.linkedin.kafka.cruisecontrol.monitor.sampling.holder.BrokerEntity in project cruise-control by linkedin.

the class SlowBrokerFinder method updateBrokerSlownessScore.

private void updateBrokerSlownessScore(Set<BrokerEntity> detectedMetricAnomalies) {
    for (BrokerEntity broker : detectedMetricAnomalies) {
        // Update slow broker detection time and slowness score.
        long currentTimeMs = _kafkaCruiseControl.timeMs();
        _detectedSlowBrokers.putIfAbsent(broker, currentTimeMs);
        _brokerSlownessScore.compute(broker, (k, v) -> (v == null) ? 1 : Math.min(v + 1, _slowBrokerDecommissionScore));
    }
    // For brokers which are previously detected as slow brokers, decrease their slowness score if their metrics has
    // recovered back to normal range.
    Set<BrokerEntity> brokersRecovered = new HashSet<>();
    for (Map.Entry<BrokerEntity, Integer> entry : _brokerSlownessScore.entrySet()) {
        BrokerEntity broker = entry.getKey();
        if (!detectedMetricAnomalies.contains(broker)) {
            Integer score = entry.getValue();
            if (score != null && --score == 0) {
                brokersRecovered.add(broker);
            } else {
                entry.setValue(score);
            }
        }
    }
    // If the broker has recovered, remove its suspicion.
    for (BrokerEntity broker : brokersRecovered) {
        _brokerSlownessScore.remove(broker);
        _detectedSlowBrokers.remove(broker);
    }
}
Also used : BrokerEntity(com.linkedin.kafka.cruisecontrol.monitor.sampling.holder.BrokerEntity) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Aggregations

BrokerEntity (com.linkedin.kafka.cruisecontrol.monitor.sampling.holder.BrokerEntity)11 HashMap (java.util.HashMap)8 Map (java.util.Map)7 HashSet (java.util.HashSet)6 ValuesAndExtrapolations (com.linkedin.cruisecontrol.monitor.sampling.aggregator.ValuesAndExtrapolations)5 KafkaCruiseControl (com.linkedin.kafka.cruisecontrol.KafkaCruiseControl)4 ArrayList (java.util.ArrayList)4 KafkaCruiseControlConfig (com.linkedin.kafka.cruisecontrol.config.KafkaCruiseControlConfig)3 MetricAnomaly (com.linkedin.cruisecontrol.detector.metricanomaly.MetricAnomaly)2 AggregatedMetricValues (com.linkedin.cruisecontrol.monitor.sampling.aggregator.AggregatedMetricValues)2 List (java.util.List)2 Properties (java.util.Properties)2 Test (org.junit.Test)2 CruiseControlUtils.utcDateFor (com.linkedin.cruisecontrol.CruiseControlUtils.utcDateFor)1 Anomaly (com.linkedin.cruisecontrol.detector.Anomaly)1 MetricAnomalyFinder (com.linkedin.cruisecontrol.detector.metricanomaly.MetricAnomalyFinder)1 MetricAnomalyType (com.linkedin.cruisecontrol.detector.metricanomaly.MetricAnomalyType)1 PercentileMetricAnomalyFinderUtils.isDataSufficient (com.linkedin.cruisecontrol.detector.metricanomaly.PercentileMetricAnomalyFinderUtils.isDataSufficient)1 MetricValues (com.linkedin.cruisecontrol.monitor.sampling.aggregator.MetricValues)1 OptimizerResult (com.linkedin.kafka.cruisecontrol.analyzer.OptimizerResult)1