Search in sources :

Example 1 with AnomalyType

use of com.linkedin.cruisecontrol.detector.AnomalyType in project cruise-control by linkedin.

the class ParameterUtils method anomalyTypes.

private static Set<AnomalyType> anomalyTypes(HttpServletRequest request, boolean isEnable) throws UnsupportedEncodingException {
    Set<String> selfHealingForString = parseParamToStringSet(request, isEnable ? ENABLE_SELF_HEALING_FOR_PARAM : DISABLE_SELF_HEALING_FOR_PARAM);
    Set<AnomalyType> anomalyTypes = new HashSet<>();
    try {
        for (String shfString : selfHealingForString) {
            anomalyTypes.add(KafkaAnomalyType.valueOf(shfString.toUpperCase()));
        }
    } catch (IllegalArgumentException iae) {
        throw new UserRequestException(String.format("Unsupported anomaly types in %s. Supported: %s", selfHealingForString, KafkaAnomalyType.cachedValues()));
    }
    return Collections.unmodifiableSet(anomalyTypes);
}
Also used : KafkaAnomalyType(com.linkedin.kafka.cruisecontrol.detector.notifier.KafkaAnomalyType) AnomalyType(com.linkedin.cruisecontrol.detector.AnomalyType) UserRequestException(com.linkedin.kafka.cruisecontrol.servlet.UserRequestException) HashSet(java.util.HashSet)

Example 2 with AnomalyType

use of com.linkedin.cruisecontrol.detector.AnomalyType in project cruise-control by linkedin.

the class SelfHealingNotifier method selfHealingEnabledRatio.

@Override
public synchronized Map<AnomalyType, Float> selfHealingEnabledRatio() {
    Map<AnomalyType, Float> selfHealingEnabledRatio = new HashMap<>();
    long nowMs = _time.milliseconds();
    long uptimeMs = uptimeMs(nowMs);
    for (AnomalyType anomalyType : KafkaAnomalyType.cachedValues()) {
        long enabledTimeMs = enabledTimeMs(anomalyType, nowMs);
        selfHealingEnabledRatio.put(anomalyType, ((float) enabledTimeMs / uptimeMs));
    }
    return selfHealingEnabledRatio;
}
Also used : HashMap(java.util.HashMap) AnomalyType(com.linkedin.cruisecontrol.detector.AnomalyType)

Example 3 with AnomalyType

use of com.linkedin.cruisecontrol.detector.AnomalyType in project cruise-control by linkedin.

the class AdminRequest method processUpdateSelfHealingRequest.

protected void processUpdateSelfHealingRequest(Map<AnomalyType, Boolean> selfHealingBefore, Map<AnomalyType, Boolean> selfHealingAfter) {
    UpdateSelfHealingParameters updateSelfHealingParameters = _parameters.updateSelfHealingParameters();
    if (updateSelfHealingParameters != null) {
        Set<AnomalyType> disableSelfHealingFor = updateSelfHealingParameters.disableSelfHealingFor();
        Set<AnomalyType> enableSelfHealingFor = updateSelfHealingParameters.enableSelfHealingFor();
        for (AnomalyType anomalyType : disableSelfHealingFor) {
            selfHealingBefore.put(anomalyType, _kafkaCruiseControl.setSelfHealingFor(anomalyType, false));
            selfHealingAfter.put(anomalyType, false);
        }
        for (AnomalyType anomalyType : enableSelfHealingFor) {
            selfHealingBefore.put(anomalyType, _kafkaCruiseControl.setSelfHealingFor(anomalyType, true));
            selfHealingAfter.put(anomalyType, true);
        }
        if (!disableSelfHealingFor.isEmpty() || !enableSelfHealingFor.isEmpty()) {
            LOG.info("Self healing state is modified by user (before: {} after: {}).", selfHealingBefore, selfHealingAfter);
        }
    }
}
Also used : UpdateSelfHealingParameters(com.linkedin.kafka.cruisecontrol.servlet.parameters.UpdateSelfHealingParameters) AnomalyType(com.linkedin.cruisecontrol.detector.AnomalyType)

Example 4 with AnomalyType

use of com.linkedin.cruisecontrol.detector.AnomalyType in project cruise-control by linkedin.

the class AlertaSelfHealingNotifier method alertTopicAnomaly.

private void alertTopicAnomaly(AnomalyType anomalyType, final String localHostname, List<AlertaMessage> alertaMessages, TopicAnomaly topicAnomaly) {
    if (topicAnomaly instanceof TopicPartitionSizeAnomaly) {
        TopicPartitionSizeAnomaly topicPartitionSizeAnomaly = (TopicPartitionSizeAnomaly) topicAnomaly;
        for (Map.Entry<TopicPartition, Double> entry : topicPartitionSizeAnomaly.sizeInMbByPartition().entrySet()) {
            AlertaMessage alertaMessage = new AlertaMessage(localHostname, ALERT_MESSAGE_PREFIX_TOPIC_PARTITION_SIZE_ANOMALY + entry.getKey().toString());
            alertaMessage.setSeverity(NotifierUtils.getAlertSeverity(anomalyType).toString());
            alertaMessage.setGroup(AlertaAlertGroup.PERFORMANCE.toString());
            alertaMessage.setValue(String.format("%f MB", entry.getValue()));
            alertaMessage.setCreateTime(CruiseControlUtils.utcDateFor(topicAnomaly.detectionTimeMs(), 3, ChronoUnit.SECONDS));
            alertaMessages.add(alertaMessage);
        }
    } else if (topicAnomaly instanceof TopicReplicationFactorAnomaly) {
        TopicReplicationFactorAnomaly topicReplicationFactorAnomaly = (TopicReplicationFactorAnomaly) topicAnomaly;
        for (Entry<Short, Set<TopicReplicationFactorAnomalyEntry>> entry : topicReplicationFactorAnomaly.badTopicsByDesiredRF().entrySet()) {
            entry.getValue().forEach(topicReplicationFactorAnomalyEntry -> {
                AlertaMessage alertaMessage = new AlertaMessage(localHostname, ALERT_MESSAGE_PREFIX_TOPIC_REPLICATION_FACTOR_ANOMALY + topicReplicationFactorAnomalyEntry.topicName());
                alertaMessage.setSeverity(NotifierUtils.getAlertSeverity(anomalyType).toString());
                alertaMessage.setGroup(AlertaAlertGroup.PERFORMANCE.toString());
                alertaMessage.setValue(String.format("%.2f", topicReplicationFactorAnomalyEntry.violationRatio()));
                alertaMessage.setCreateTime(CruiseControlUtils.utcDateFor(topicAnomaly.detectionTimeMs(), 3, ChronoUnit.SECONDS));
                alertaMessages.add(alertaMessage);
            });
        }
    } else {
        AlertaMessage alertaMessage = new AlertaMessage(localHostname, anomalyType.toString());
        alertaMessage.setSeverity(NotifierUtils.getAlertSeverity(anomalyType).toString());
        alertaMessage.setGroup(AlertaAlertGroup.PERFORMANCE.toString());
        alertaMessage.setCreateTime(CruiseControlUtils.utcDateFor(topicAnomaly.detectionTimeMs(), 3, ChronoUnit.SECONDS));
        alertaMessages.add(alertaMessage);
    }
}
Also used : GoalViolations(com.linkedin.kafka.cruisecontrol.detector.GoalViolations) BrokerEntity(com.linkedin.kafka.cruisecontrol.monitor.sampling.holder.BrokerEntity) BrokerFailures(com.linkedin.kafka.cruisecontrol.detector.BrokerFailures) LoggerFactory(org.slf4j.LoggerFactory) KafkaMetricAnomaly(com.linkedin.kafka.cruisecontrol.detector.KafkaMetricAnomaly) TopicAnomaly(com.linkedin.kafka.cruisecontrol.detector.TopicAnomaly) ArrayList(java.util.ArrayList) InetAddress(java.net.InetAddress) Anomaly(com.linkedin.cruisecontrol.detector.Anomaly) TopicReplicationFactorAnomaly(com.linkedin.kafka.cruisecontrol.detector.TopicReplicationFactorAnomaly) DiskFailures(com.linkedin.kafka.cruisecontrol.detector.DiskFailures) Map(java.util.Map) MaintenanceEvent(com.linkedin.kafka.cruisecontrol.detector.MaintenanceEvent) TopicPartition(org.apache.kafka.common.TopicPartition) CruiseControlUtils.utcDateFor(com.linkedin.cruisecontrol.CruiseControlUtils.utcDateFor) Logger(org.slf4j.Logger) CruiseControlUtils(com.linkedin.cruisecontrol.CruiseControlUtils) Time(org.apache.kafka.common.utils.Time) AnomalyType(com.linkedin.cruisecontrol.detector.AnomalyType) Set(java.util.Set) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) List(java.util.List) ChronoUnit(java.time.temporal.ChronoUnit) TopicReplicationFactorAnomalyEntry(com.linkedin.kafka.cruisecontrol.detector.TopicReplicationFactorAnomaly.TopicReplicationFactorAnomalyEntry) Entry(java.util.Map.Entry) TopicPartitionSizeAnomaly(com.linkedin.kafka.cruisecontrol.detector.TopicPartitionSizeAnomaly) Collections(java.util.Collections) TopicReplicationFactorAnomalyEntry(com.linkedin.kafka.cruisecontrol.detector.TopicReplicationFactorAnomaly.TopicReplicationFactorAnomalyEntry) Entry(java.util.Map.Entry) TopicPartition(org.apache.kafka.common.TopicPartition) TopicPartitionSizeAnomaly(com.linkedin.kafka.cruisecontrol.detector.TopicPartitionSizeAnomaly) Map(java.util.Map) TopicReplicationFactorAnomaly(com.linkedin.kafka.cruisecontrol.detector.TopicReplicationFactorAnomaly) TopicReplicationFactorAnomalyEntry(com.linkedin.kafka.cruisecontrol.detector.TopicReplicationFactorAnomaly.TopicReplicationFactorAnomalyEntry)

Example 5 with AnomalyType

use of com.linkedin.cruisecontrol.detector.AnomalyType in project cruise-control by linkedin.

the class AnomalyDetectorState method onAnomalyHandle.

/**
 * Update state regarding how the anomaly has been handled.
 *
 * @param anomaly The anomaly to handle.
 * @param status A status information regarding how the anomaly was handled.
 */
synchronized void onAnomalyHandle(Anomaly anomaly, AnomalyState.Status status) {
    AnomalyType anomalyType = anomaly.anomalyType();
    String anomalyId = anomaly.anomalyId();
    if (status == AnomalyState.Status.FIX_STARTED) {
        _ongoingSelfHealingAnomaly = anomaly;
    }
    AnomalyState recentAnomalyState = _recentAnomaliesByType.get(anomalyType).get(anomalyId);
    if (recentAnomalyState != null) {
        recentAnomalyState.setStatus(status);
    } else if (LOG.isDebugEnabled()) {
        LOG.debug("Anomaly (type: {}, anomalyId: {}) is no longer in the anomaly detector state cache.", anomalyType, anomalyId);
    }
}
Also used : KafkaAnomalyType(com.linkedin.kafka.cruisecontrol.detector.notifier.KafkaAnomalyType) AnomalyType(com.linkedin.cruisecontrol.detector.AnomalyType)

Aggregations

AnomalyType (com.linkedin.cruisecontrol.detector.AnomalyType)6 KafkaAnomalyType (com.linkedin.kafka.cruisecontrol.detector.notifier.KafkaAnomalyType)3 HashMap (java.util.HashMap)2 CruiseControlUtils (com.linkedin.cruisecontrol.CruiseControlUtils)1 CruiseControlUtils.utcDateFor (com.linkedin.cruisecontrol.CruiseControlUtils.utcDateFor)1 Anomaly (com.linkedin.cruisecontrol.detector.Anomaly)1 BrokerFailures (com.linkedin.kafka.cruisecontrol.detector.BrokerFailures)1 DiskFailures (com.linkedin.kafka.cruisecontrol.detector.DiskFailures)1 GoalViolations (com.linkedin.kafka.cruisecontrol.detector.GoalViolations)1 KafkaMetricAnomaly (com.linkedin.kafka.cruisecontrol.detector.KafkaMetricAnomaly)1 MaintenanceEvent (com.linkedin.kafka.cruisecontrol.detector.MaintenanceEvent)1 TopicAnomaly (com.linkedin.kafka.cruisecontrol.detector.TopicAnomaly)1 TopicPartitionSizeAnomaly (com.linkedin.kafka.cruisecontrol.detector.TopicPartitionSizeAnomaly)1 TopicReplicationFactorAnomaly (com.linkedin.kafka.cruisecontrol.detector.TopicReplicationFactorAnomaly)1 TopicReplicationFactorAnomalyEntry (com.linkedin.kafka.cruisecontrol.detector.TopicReplicationFactorAnomaly.TopicReplicationFactorAnomalyEntry)1 BrokerEntity (com.linkedin.kafka.cruisecontrol.monitor.sampling.holder.BrokerEntity)1 UserRequestException (com.linkedin.kafka.cruisecontrol.servlet.UserRequestException)1 UpdateSelfHealingParameters (com.linkedin.kafka.cruisecontrol.servlet.parameters.UpdateSelfHealingParameters)1 IOException (java.io.IOException)1 InetAddress (java.net.InetAddress)1