@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);
 }
  @Test
  public void testHistogramDisabled() {
    // create timer with id "testMetricAlerts" and register with metric registry, bump up value to
    // 4.
    Histogram h =
        MetricsConfigurator.createHistogram5Min(
            metrics, "testHistogramDisabled", PIPELINE_NAME, REVISION);
    h.update(1000);

    MetricsRuleDefinition metricsRuleDefinition =
        new MetricsRuleDefinition(
            "testHistogramDisabled",
            "testHistogramDisabled",
            "testHistogramDisabled",
            MetricType.HISTOGRAM,
            MetricElement.HISTOGRAM_COUNT,
            "${value()==1}",
            false,
            false);
    MetricRuleEvaluator metricRuleEvaluator =
        new MetricRuleEvaluator(
            metricsRuleDefinition,
            metrics,
            new AlertManager(
                PIPELINE_NAME, REVISION, null, metrics, runtimeInfo, new EventListenerManager()),
            Collections.<String>emptyList());
    metricRuleEvaluator.checkForAlerts();

    // get alert gauge
    Gauge<Object> gauge =
        MetricsConfigurator.getGauge(
            metrics, AlertsUtil.getAlertGaugeName(metricsRuleDefinition.getId()));
    Assert.assertNull(gauge);
  }
  @Test
  public void testTimerMatch() {
    // create timer with id "testMetricAlerts" and register with metric registry, bump up value to
    // 4.
    Timer t = MetricsConfigurator.createTimer(metrics, "testTimerMatch", PIPELINE_NAME, REVISION);
    t.update(1000, TimeUnit.MILLISECONDS);
    t.update(2000, TimeUnit.MILLISECONDS);
    t.update(3000, TimeUnit.MILLISECONDS);

    MetricsRuleDefinition metricsRuleDefinition =
        new MetricsRuleDefinition(
            "testTimerMatch",
            "testTimerMatch",
            "testTimerMatch",
            MetricType.TIMER,
            MetricElement.TIMER_COUNT,
            "${value()>2}",
            false,
            true);
    MetricRuleEvaluator metricRuleEvaluator =
        new MetricRuleEvaluator(
            metricsRuleDefinition,
            metrics,
            new AlertManager(
                PIPELINE_NAME, REVISION, null, metrics, runtimeInfo, new EventListenerManager()),
            Collections.<String>emptyList());
    metricRuleEvaluator.checkForAlerts();

    // get alert gauge
    Gauge<Object> gauge =
        MetricsConfigurator.getGauge(
            metrics, AlertsUtil.getAlertGaugeName(metricsRuleDefinition.getId()));
    Assert.assertNotNull(gauge);
    Assert.assertEquals((long) 3, ((Map<String, Object>) gauge.getValue()).get("currentValue"));
  }
  @Test
  public void testMeterNoMatch() {
    // create timer with id "testMetricAlerts" and register with metric registry, bump up value to
    // 4.
    Meter m = MetricsConfigurator.createMeter(metrics, "testMeterNoMatch", PIPELINE_NAME, REVISION);
    m.mark(1000);

    MetricsRuleDefinition metricsRuleDefinition =
        new MetricsRuleDefinition(
            "testMeterNoMatch",
            "testMeterNoMatch",
            "testMeterNoMatch",
            MetricType.METER,
            MetricElement.METER_COUNT,
            "${value()>1001}",
            false,
            true);
    MetricRuleEvaluator metricRuleEvaluator =
        new MetricRuleEvaluator(
            metricsRuleDefinition,
            metrics,
            new AlertManager(
                PIPELINE_NAME, REVISION, null, metrics, runtimeInfo, new EventListenerManager()),
            Collections.<String>emptyList());
    metricRuleEvaluator.checkForAlerts();

    // get alert gauge
    Gauge<Object> gauge =
        MetricsConfigurator.getGauge(
            metrics, AlertsUtil.getAlertGaugeName(metricsRuleDefinition.getId()));
    Assert.assertNull(gauge);
  }