Search in sources :

Example 1 with KafkaAnomalyType

use of com.linkedin.kafka.cruisecontrol.detector.notifier.KafkaAnomalyType in project cruise-control by linkedin.

the class AnomalyDetailsTest method testPopulateAnomalyDetails.

@Test
public void testPopulateAnomalyDetails() {
    AnomalyState mockAnomalyState = EasyMock.mock(AnomalyState.class);
    for (KafkaAnomalyType anomalyType : KafkaAnomalyType.cachedValues()) {
        AnomalyDetails details = new AnomalyDetails(mockAnomalyState, anomalyType, false, false);
        EasyMock.expect(mockAnomalyState.detectionMs()).andReturn(MOCK_DETECTION_MS).once();
        EasyMock.expect(mockAnomalyState.status()).andReturn(DETECTED).once();
        EasyMock.expect(mockAnomalyState.anomalyId()).andReturn(MOCK_ANOMALY_ID).once();
        EasyMock.expect(mockAnomalyState.statusUpdateMs()).andReturn(MOCK_STATUS_UPDATE_MS).once();
        switch(anomalyType) {
            case GOAL_VIOLATION:
                GoalViolations goalViolations = EasyMock.mock(GoalViolations.class);
                EasyMock.expect(goalViolations.violatedGoalsByFixability()).andReturn(VIOLATED_GOALS_BY_FIXABILITY).once();
                replayAndVerify(mockAnomalyState, details, goalViolations);
                break;
            case BROKER_FAILURE:
                BrokerFailures brokerFailures = EasyMock.mock(BrokerFailures.class);
                EasyMock.expect(brokerFailures.failedBrokers()).andReturn(FAILED_BROKERS).once();
                replayAndVerify(mockAnomalyState, details, brokerFailures);
                break;
            case DISK_FAILURE:
                DiskFailures diskFailures = EasyMock.mock(DiskFailures.class);
                EasyMock.expect(diskFailures.failedDisks()).andReturn(FAILED_DISKS).once();
                replayAndVerify(mockAnomalyState, details, diskFailures);
                break;
            case METRIC_ANOMALY:
                KafkaMetricAnomaly kafkaMetricAnomaly = EasyMock.mock(KafkaMetricAnomaly.class);
                EasyMock.expect(kafkaMetricAnomaly.description()).andReturn(MOCK_DESCRIPTION).once();
                replayAndVerify(mockAnomalyState, details, kafkaMetricAnomaly);
                break;
            case TOPIC_ANOMALY:
                TopicAnomaly topicAnomaly = EasyMock.mock(TopicAnomaly.class);
                // Note: EasyMock provides a built-in behavior for equals(), toString(), hashCode() and finalize() even for class mocking.
                // Hence, we cannot record our own behavior for topicAnomaly.toString().
                replayAndVerify(mockAnomalyState, details, topicAnomaly);
                break;
            case MAINTENANCE_EVENT:
                MaintenanceEvent maintenanceEvent = EasyMock.mock(MaintenanceEvent.class);
                // Note: EasyMock provides a built-in behavior for equals(), toString(), hashCode() and finalize() even for class mocking.
                // Hence, we cannot record our own behavior for maintenanceEvent.toString().
                replayAndVerify(mockAnomalyState, details, maintenanceEvent);
                break;
            default:
                throw new IllegalStateException("Unrecognized anomaly type " + anomalyType);
        }
    }
}
Also used : KafkaAnomalyType(com.linkedin.kafka.cruisecontrol.detector.notifier.KafkaAnomalyType) Test(org.junit.Test)

Example 2 with KafkaAnomalyType

use of com.linkedin.kafka.cruisecontrol.detector.notifier.KafkaAnomalyType in project cruise-control by linkedin.

the class AnomalyDetectorManager method registerGaugeSensors.

/**
 * Register gauge sensors.
 * @param dropwizardMetricRegistry The metric registry that holds all the metrics for monitoring Cruise Control.
 */
private void registerGaugeSensors(MetricRegistry dropwizardMetricRegistry) {
    dropwizardMetricRegistry.register(MetricRegistry.name(ANOMALY_DETECTOR_SENSOR, "balancedness-score"), (Gauge<Double>) _goalViolationDetector::balancednessScore);
    // Self-Healing is turned on/off. 1/0 metric for each of the self-healing options.
    for (KafkaAnomalyType anomalyType : KafkaAnomalyType.cachedValues()) {
        dropwizardMetricRegistry.register(MetricRegistry.name(ANOMALY_DETECTOR_SENSOR, String.format("%s-self-healing-enabled", anomalyType.toString().toLowerCase())), (Gauge<Integer>) () -> _anomalyNotifier.selfHealingEnabled().get(anomalyType) ? 1 : 0);
    }
    // The cluster is identified as under-provisioned, over-provisioned, or right-sized (undecided not reported).
    dropwizardMetricRegistry.register(MetricRegistry.name(ANOMALY_DETECTOR_SENSOR, "under-provisioned"), (Gauge<Integer>) () -> (_goalViolationDetector.provisionStatus() == ProvisionStatus.UNDER_PROVISIONED) ? 1 : 0);
    dropwizardMetricRegistry.register(MetricRegistry.name(ANOMALY_DETECTOR_SENSOR, "over-provisioned"), (Gauge<Integer>) () -> (_goalViolationDetector.provisionStatus() == ProvisionStatus.OVER_PROVISIONED) ? 1 : 0);
    dropwizardMetricRegistry.register(MetricRegistry.name(ANOMALY_DETECTOR_SENSOR, "right-sized"), (Gauge<Integer>) () -> (_goalViolationDetector.provisionStatus() == ProvisionStatus.RIGHT_SIZED) ? 1 : 0);
    // The number of metric anomalies corresponding to each metric anomaly type.
    for (MetricAnomalyType type : MetricAnomalyType.cachedValues()) {
        dropwizardMetricRegistry.register(MetricRegistry.name(ANOMALY_DETECTOR_SENSOR, String.format("num-%s-metric-anomalies", type.toString().toLowerCase())), (Gauge<Integer>) () -> _metricAnomalyDetector.numAnomaliesOfType(type));
    }
    // The cluster has partitions with RF > the number of eligible racks (0: No such partitions, 1: Has such partitions)
    dropwizardMetricRegistry.register(MetricRegistry.name(ANOMALY_DETECTOR_SENSOR, "has-partitions-with-replication-factor-greater-than-num-racks"), (Gauge<Integer>) () -> _goalViolationDetector.hasPartitionsWithRFGreaterThanNumRacks() ? 1 : 0);
    // The time taken to generate a fix for self-healing for each anomaly type
    for (KafkaAnomalyType anomalyType : KafkaAnomalyType.cachedValues()) {
        Timer timer = dropwizardMetricRegistry.timer(MetricRegistry.name(ANOMALY_DETECTOR_SENSOR, String.format("%s-self-healing-fix-generation-timer", anomalyType.toString().toLowerCase())));
        _selfHealingFixGenerationTimer.put(anomalyType, timer);
    }
}
Also used : KafkaAnomalyType(com.linkedin.kafka.cruisecontrol.detector.notifier.KafkaAnomalyType) Timer(com.codahale.metrics.Timer) MetricAnomalyType(com.linkedin.cruisecontrol.detector.metricanomaly.MetricAnomalyType)

Aggregations

KafkaAnomalyType (com.linkedin.kafka.cruisecontrol.detector.notifier.KafkaAnomalyType)2 Timer (com.codahale.metrics.Timer)1 MetricAnomalyType (com.linkedin.cruisecontrol.detector.metricanomaly.MetricAnomalyType)1 Test (org.junit.Test)1