Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -559,18 +559,19 @@ private void fixAnomalyInProgress(AnomalyType anomalyType) throws Exception {
skipReportingIfNotUpdated = anomalyType == KafkaAnomalyType.BROKER_FAILURE;
throw ofe;
} finally {
handlePostFixAnomaly(isReadyToFix, fixStarted, anomalyId, skipReportingIfNotUpdated);
handlePostFixAnomaly(isReadyToFix, fixStarted, anomalyId, skipReportingIfNotUpdated, anomalyType);
}
}
}
}

private void handlePostFixAnomaly(boolean isReadyToFix, boolean fixStarted, String anomalyId, boolean skipReportingIfNotUpdated) {
private void handlePostFixAnomaly(boolean isReadyToFix, boolean fixStarted, String anomalyId, boolean skipReportingIfNotUpdated,
AnomalyType anomalyType) {
if (isReadyToFix) {
_anomalyDetectorState.onAnomalyHandle(_anomalyInProgress, fixStarted ? AnomalyState.Status.FIX_STARTED
: AnomalyState.Status.FIX_FAILED_TO_START);
if (fixStarted) {
_anomalyDetectorState.incrementNumSelfHealingStarted();
_anomalyDetectorState.incrementNumSelfHealingStarted(anomalyType);
LOG.info("[{}] Self-healing started successfully.", anomalyId);
} else {
_anomalyDetectorState.incrementNumSelfHealingFailedToStart();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package com.linkedin.kafka.cruisecontrol.detector;

import com.codahale.metrics.Counter;
import com.codahale.metrics.Gauge;
import com.codahale.metrics.Meter;
import com.codahale.metrics.MetricRegistry;
Expand Down Expand Up @@ -81,6 +82,8 @@ public class AnomalyDetectorState {
private double _balancednessScore;
private boolean _hasUnfixableGoals;
private final Map<AnomalyType, Timer> _anomalyDetectToFixCompleteTimer;
private final Map<AnomalyType, Counter> _numSelfHealingStartedPerAnomaly;
private final Map<AnomalyType, Counter> _numSelfHealingEndedPerAnomaly;

public AnomalyDetectorState(Time time,
AnomalyNotifier anomalyNotifier,
Expand All @@ -105,6 +108,8 @@ protected boolean removeEldestEntry(Map.Entry<String, AnomalyState> eldest) {
_ongoingAnomalyDurationSumForAverageMs = 0;
_numSelfHealingStarted = new AtomicLong(0L);
_numSelfHealingFailedToStart = new AtomicLong(0L);
_numSelfHealingStartedPerAnomaly = new HashMap<>();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need to do anything in the refreshMetrics method to reset these maps? There seems to be a numSelfHealingStarted() call in there as part of creating a new AnomalyMetrics instance.

I don't know if that is relevant but you should check if these maps need to be reset.

_numSelfHealingEndedPerAnomaly = new HashMap<>();

Map<AnomalyType, Double> meanTimeBetweenAnomaliesMs = new HashMap<>();
for (AnomalyType anomalyType : KafkaAnomalyType.cachedValues()) {
Expand Down Expand Up @@ -141,6 +146,14 @@ protected boolean removeEldestEntry(Map.Entry<String, AnomalyState> eldest) {
Timer timer = dropwizardMetricRegistry.timer(
MetricRegistry.name(ANOMALY_DETECTOR_SENSOR, String.format("%s-detect-to-fix-complete-timer", anomalyType.toString().toLowerCase())));
_anomalyDetectToFixCompleteTimer.put(anomalyType, timer);

Counter counter = dropwizardMetricRegistry.counter(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If these counter and counter1 variables are not actually used anywhere other than the map.put call, can you just in-line them?

Same with timer variable above?

MetricRegistry.name(ANOMALY_DETECTOR_SENSOR, String.format("num-of-self-healing-started-for-%s", anomalyType.toString().toLowerCase())));
_numSelfHealingStartedPerAnomaly.put(anomalyType, counter);

Counter counter1 = dropwizardMetricRegistry.counter(
MetricRegistry.name(ANOMALY_DETECTOR_SENSOR, String.format("num-of-self-healing-ended-for-%s", anomalyType.toString().toLowerCase())));
_numSelfHealingEndedPerAnomaly.put(anomalyType, counter1);
}
} else {
_anomalyRateByType = new HashMap<>();
Expand Down Expand Up @@ -259,9 +272,21 @@ long numSelfHealingStarted() {

/**
* Increment the number of self healing actions started successfully.
*
* @param anomalyType Type of anomaly
*/
void incrementNumSelfHealingStarted() {
void incrementNumSelfHealingStarted(AnomalyType anomalyType) {
_numSelfHealingStarted.incrementAndGet();
_numSelfHealingStartedPerAnomaly.get(anomalyType).inc();
}

/**
* Increment the number of self healing actions ended successfully per anomaly.
*
* @param anomalyType Type of anomaly
*/
void incrementNumSelfHealingEndedPerAnomaly(AnomalyType anomalyType) {
_numSelfHealingEndedPerAnomaly.get(anomalyType).inc();
}

/**
Expand Down Expand Up @@ -309,6 +334,7 @@ public synchronized void markSelfHealingFinished(String anomalyId, boolean compl
// Time the duration if the self-healing is completed successfully.
// completeWithError is true if the proposal execution is interrupted (receive stop signal) or encountered exception.
// execution-stopped metrics track the number of stopped execution.
incrementNumSelfHealingEndedPerAnomaly(_ongoingSelfHealingAnomaly.anomalyType());
_anomalyDetectToFixCompleteTimer.get(_ongoingSelfHealingAnomaly.anomalyType()).update(totalTime, TimeUnit.MILLISECONDS);
}
_ongoingSelfHealingAnomaly = null;
Expand Down