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);
}
}
Aggregations