@SuppressWarnings("unchecked") public static void alertException( String pipelineName, String revision, MetricRegistry metrics, Object value, RuleDefinition ruleDefinition) { final Map<String, Object> alertResponse = new HashMap<>(); alertResponse.put(EmailConstants.EXCEPTION_MESSAGE, value); Gauge<Object> gauge = MetricsConfigurator.getGauge(metrics, AlertsUtil.getAlertGaugeName(ruleDefinition.getId())); if (gauge != null) { // remove existing gauge MetricsConfigurator.removeGauge( metrics, AlertsUtil.getAlertGaugeName(ruleDefinition.getId()), pipelineName, revision); } Gauge<Object> alertResponseGauge = new Gauge<Object>() { @Override public Object getValue() { return alertResponse; } }; MetricsConfigurator.createGauge( metrics, AlertsUtil.getAlertGaugeName(ruleDefinition.getId()), alertResponseGauge, pipelineName, revision); }
public static Gauge<Object> createAlertResponseGauge( String pipelineName, String revision, MetricRegistry metrics, Object value, RuleDefinition ruleDefinition) { final Map<String, Object> alertResponse = new HashMap<>(); alertResponse.put(EmailConstants.CURRENT_VALUE, value); Gauge<Object> alertResponseGauge = new Gauge<Object>() { @Override public Object getValue() { return alertResponse; } }; alertResponse.put(EmailConstants.TIMESTAMP, System.currentTimeMillis()); List<String> alertTexts = new ArrayList<>(); alertTexts.add(ruleDefinition.getAlertText()); alertResponse.put(EmailConstants.ALERT_TEXTS, alertTexts); MetricsConfigurator.createGauge( metrics, AlertsUtil.getAlertGaugeName(ruleDefinition.getId()), alertResponseGauge, pipelineName, revision); return alertResponseGauge; }
private static void updateAlertText(RuleDefinition ruleDefinition, List<String> alertTexts) { // As of today Data and Metric Rules have the same fixed alert texts for a given rule. // But Drift rules can have different alert texts based on the drift in the values. // The check below will avoid collecting the same alert texts again and again in case of metric // and data rules. // One may ask why not just add alert texts the first time for metric and data rules and skip // updating it? // Because when we add EL support in alert texts then metric and data rules may produce // different alert texts. int size = alertTexts.size(); String alertText = ruleDefinition.getAlertText(); if (size > 0) { String lastAlertText = alertTexts.get(size - 1); if (!lastAlertText.equals(alertText)) { alertTexts.add(alertText); if (alertTexts.size() > 10) { alertTexts.remove(0); } } } else { // add alertTexts.add(alertText); if (alertTexts.size() > 10) { alertTexts.remove(0); } } }