Search in sources :

Example 1 with MetricsCloudWatchReporter

use of com.kixeye.chassis.support.metrics.aws.MetricsCloudWatchReporter in project chassis by Kixeye.

the class CloudWatchReporterTest method testRecoverAfterFailedPublication.

/**
     * Ensure that a failed publication does not prevent subsequent attempts
     */
@Test
@Ignore("Fix the thread sleeps.")
public void testRecoverAfterFailedPublication() throws InterruptedException {
    MetricRegistry metricRegistry = new MetricRegistry();
    metricRegistry.counter("UnitTestCounter").inc();
    final AmazonCloudWatch amazonCloudWatch = Mockito.mock(AmazonCloudWatch.class);
    reporter = new MetricsCloudWatchReporter(APP_NAME, APP_VERSION, APP_ENVIRONMENT, "utc=UnitTestCounter", 2, TimeUnit.SECONDS, metricRegistry, createCloudWatchFactory(amazonCloudWatch));
    Mockito.doThrow(new RuntimeException("CloudWatch request error")).when(amazonCloudWatch).putMetricData(Mockito.any(PutMetricDataRequest.class));
    reporter.start();
    //give the reporter a chance to publish
    Thread.sleep(3000);
    //verify that
    Mockito.verify(amazonCloudWatch, Mockito.times(1)).putMetricData(Mockito.any(PutMetricDataRequest.class));
    Mockito.reset(amazonCloudWatch);
    metricRegistry.counter("UnitTestCounter").inc();
    Thread.sleep(3000);
    PutMetricDataRequestMatcher matcher = new PutMetricDataRequestMatcher(new MetricDatumValidator("utc", APP_ENVIRONMENT, 2d));
    Mockito.verify(amazonCloudWatch, Mockito.times(2)).putMetricData(Mockito.argThat(matcher));
}
Also used : MetricsCloudWatchReporter(com.kixeye.chassis.support.metrics.aws.MetricsCloudWatchReporter) AmazonCloudWatch(com.amazonaws.services.cloudwatch.AmazonCloudWatch) PutMetricDataRequest(com.amazonaws.services.cloudwatch.model.PutMetricDataRequest) MetricRegistry(com.codahale.metrics.MetricRegistry) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with MetricsCloudWatchReporter

use of com.kixeye.chassis.support.metrics.aws.MetricsCloudWatchReporter in project chassis by Kixeye.

the class CloudWatchReporterTest method testPublishInMultipleCloudWatchRequests.

/**
     * Ensure all metrics are published event when the max number of cloudwatch metrics (per request) is exceeded.
     */
@Test
public void testPublishInMultipleCloudWatchRequests() throws InterruptedException {
    MetricRegistry metricRegistry = new MetricRegistry();
    StringBuilder filter = new StringBuilder();
    for (int i = 0; i < MetricsCloudWatchReporter.MAX_CLOUDWATCH_DATUM_PER_REQUEST + 1; i++) {
        String metric = "UnitTestCounter" + i;
        metricRegistry.counter(metric).inc();
        if (i > 0) {
            filter.append(",");
        }
        filter.append(metric).append("=").append(metric);
    }
    final AmazonCloudWatch amazonCloudWatch = Mockito.mock(AmazonCloudWatch.class);
    reporter = new MetricsCloudWatchReporter(APP_NAME, APP_VERSION, APP_ENVIRONMENT, filter.toString(), 2, TimeUnit.SECONDS, metricRegistry, createCloudWatchFactory(amazonCloudWatch));
    reporter.start();
    Mockito.verify(amazonCloudWatch, Mockito.never()).putMetricData(Mockito.any(PutMetricDataRequest.class));
    Thread.sleep(3000);
    Mockito.verify(amazonCloudWatch, Mockito.times(2)).putMetricData(Mockito.any(PutMetricDataRequest.class));
}
Also used : MetricsCloudWatchReporter(com.kixeye.chassis.support.metrics.aws.MetricsCloudWatchReporter) AmazonCloudWatch(com.amazonaws.services.cloudwatch.AmazonCloudWatch) PutMetricDataRequest(com.amazonaws.services.cloudwatch.model.PutMetricDataRequest) MetricRegistry(com.codahale.metrics.MetricRegistry) Test(org.junit.Test)

Example 3 with MetricsCloudWatchReporter

use of com.kixeye.chassis.support.metrics.aws.MetricsCloudWatchReporter in project chassis by Kixeye.

the class MetricsCloudWatchConfigurationTest method testRestartReporter.

@Test
public void testRestartReporter() {
    Assert.assertTrue(metricsCloudWatchConfiguration.isEnabled());
    Assert.assertNotNull(metricsCloudWatchConfiguration.getReporter());
    MetricsCloudWatchReporter originalReporter = metricsCloudWatchConfiguration.getReporter();
    ConfigurationManager.getConfigInstance().setProperty(removePlaceholder(MetricsCloudWatchConfiguration.METRICS_AWS_ENABLED_PROPERTY_NAME), "false");
    Assert.assertFalse(metricsCloudWatchConfiguration.isEnabled());
    Assert.assertNull(metricsCloudWatchConfiguration.getReporter());
    ConfigurationManager.getConfigInstance().setProperty(removePlaceholder(MetricsCloudWatchConfiguration.METRICS_AWS_ENABLED_PROPERTY_NAME), "true");
    Assert.assertTrue(metricsCloudWatchConfiguration.isEnabled());
    Assert.assertNotNull(metricsCloudWatchConfiguration.getReporter());
    Assert.assertNotSame(originalReporter, metricsCloudWatchConfiguration.getReporter());
}
Also used : MetricsCloudWatchReporter(com.kixeye.chassis.support.metrics.aws.MetricsCloudWatchReporter) Test(org.junit.Test)

Example 4 with MetricsCloudWatchReporter

use of com.kixeye.chassis.support.metrics.aws.MetricsCloudWatchReporter in project chassis by Kixeye.

the class CloudWatchReporterTest method testPublishMetrics.

/**
     * successfully publish metrics. no stat filtering
     */
@Test
public void testPublishMetrics() throws InterruptedException {
    MetricRegistry metricRegistry = new MetricRegistry();
    metricRegistry.counter("UnitTestCounter1").inc();
    metricRegistry.counter("UnitTestCounter2").inc();
    metricRegistry.counter("UnitTestCounter2").inc();
    metricRegistry.counter("UnitTestCounter3").inc();
    metricRegistry.meter("UnitTestMeter");
    metricRegistry.histogram("UnitTestHistogram");
    metricRegistry.timer("UnitTestTimer");
    metricRegistry.register("UnitTestGauge", new Gauge<Object>() {

        @Override
        public Object getValue() {
            return 1;
        }
    });
    //this gauge should not be reported to AWS because its value is not numeric
    metricRegistry.register("InvalidUnitTestGauge", new Gauge<Object>() {

        @Override
        public Object getValue() {
            return "foo";
        }
    });
    final AmazonCloudWatch amazonCloudWatch = Mockito.mock(AmazonCloudWatch.class);
    reporter = new MetricsCloudWatchReporter(APP_NAME, APP_VERSION, APP_ENVIRONMENT, "utc1=UnitTestCounter1,utc2=UnitTestCounter2,utg=UnitTestGauge,utm=UnitTestMeter,uth=UnitTestHistogram,utt=UnitTestTimer", 2, TimeUnit.SECONDS, metricRegistry, createCloudWatchFactory(amazonCloudWatch));
    reporter.start();
    //give the reporter a chance to publish
    Thread.sleep(3000);
    PutMetricDataRequestMatcher matcher = new PutMetricDataRequestMatcher(new MetricDatumValidator("utg", APP_ENVIRONMENT, 1d), new MetricDatumValidator("utc1", APP_ENVIRONMENT, 1d), new MetricDatumValidator("utc2", APP_ENVIRONMENT, 2d), new MetricDatumValidator("uth.count", APP_ENVIRONMENT, 0d), new MetricDatumValidator("uth.min", APP_ENVIRONMENT, 0d), new MetricDatumValidator("uth.max", APP_ENVIRONMENT, 0d), new MetricDatumValidator("uth.mean", APP_ENVIRONMENT, 0d), new MetricDatumValidator("uth.stddev", APP_ENVIRONMENT, 0d), new MetricDatumValidator("uth.75p", APP_ENVIRONMENT, 0d), new MetricDatumValidator("uth.95p", APP_ENVIRONMENT, 0d), new MetricDatumValidator("uth.98p", APP_ENVIRONMENT, 0d), new MetricDatumValidator("uth.99p", APP_ENVIRONMENT, 0d), new MetricDatumValidator("uth.999p", APP_ENVIRONMENT, 0d), new MetricDatumValidator("utm.1m", APP_ENVIRONMENT, 0d), new MetricDatumValidator("utm.5m", APP_ENVIRONMENT, 0d), new MetricDatumValidator("utm.15m", APP_ENVIRONMENT, 0d), new MetricDatumValidator("utm.mean", APP_ENVIRONMENT, 0d), new MetricDatumValidator("utt.count", APP_ENVIRONMENT, 0d), new MetricDatumValidator("utt.1m", APP_ENVIRONMENT, 0d), new MetricDatumValidator("utt.5m", APP_ENVIRONMENT, 0d));
    PutMetricDataRequestMatcher matcher2 = new PutMetricDataRequestMatcher(new MetricDatumValidator("utt.15m", APP_ENVIRONMENT, 0d), new MetricDatumValidator("utt.mean", APP_ENVIRONMENT, 0d));
    //first request to AWS with 20 events
    Mockito.verify(amazonCloudWatch, Mockito.times(1)).putMetricData(Mockito.argThat(matcher));
    //seconds request to AWS with 2 events
    Mockito.verify(amazonCloudWatch, Mockito.times(1)).putMetricData(Mockito.argThat(matcher2));
}
Also used : MetricsCloudWatchReporter(com.kixeye.chassis.support.metrics.aws.MetricsCloudWatchReporter) AmazonCloudWatch(com.amazonaws.services.cloudwatch.AmazonCloudWatch) MetricRegistry(com.codahale.metrics.MetricRegistry) Test(org.junit.Test)

Example 5 with MetricsCloudWatchReporter

use of com.kixeye.chassis.support.metrics.aws.MetricsCloudWatchReporter in project chassis by Kixeye.

the class CloudWatchReporterTest method testPublishFilteredMetrics_metricStatFiltered.

/**
     * A metric is not fully filtered, but some stats within the metric are
     */
@Test
public void testPublishFilteredMetrics_metricStatFiltered() throws InterruptedException {
    MetricRegistry metricRegistry = new MetricRegistry();
    metricRegistry.meter("UnitTestMeter1").mark();
    metricRegistry.meter("UnitTestMeter2").mark();
    final AmazonCloudWatch amazonCloudWatch = Mockito.mock(AmazonCloudWatch.class);
    reporter = new MetricsCloudWatchReporter(APP_NAME, APP_VERSION, APP_ENVIRONMENT, "utm1=UnitTestMeter1,utm2=UnitTestMeter2:1m:5m:15m", 2, TimeUnit.SECONDS, metricRegistry, createCloudWatchFactory(amazonCloudWatch));
    reporter.start();
    //give the reporter a chance to publish
    Thread.sleep(3000);
    PutMetricDataRequestMatcher matcher = new PutMetricDataRequestMatcher(new MetricDatumValidator("utm1.1m", APP_ENVIRONMENT, 0d), new MetricDatumValidator("utm1.5m", APP_ENVIRONMENT, 0d), new MetricDatumValidator("utm1.15m", APP_ENVIRONMENT, 0d), new MetricDatumValidator("utm1.mean", APP_ENVIRONMENT, null), new MetricDatumValidator("utm2.1m", APP_ENVIRONMENT, 0d), new MetricDatumValidator("utm2.5m", APP_ENVIRONMENT, 0d), new MetricDatumValidator("utm2.15m", APP_ENVIRONMENT, 0d));
    Mockito.verify(amazonCloudWatch, Mockito.times(1)).putMetricData(Mockito.argThat(matcher));
}
Also used : MetricsCloudWatchReporter(com.kixeye.chassis.support.metrics.aws.MetricsCloudWatchReporter) AmazonCloudWatch(com.amazonaws.services.cloudwatch.AmazonCloudWatch) MetricRegistry(com.codahale.metrics.MetricRegistry) Test(org.junit.Test)

Aggregations

MetricsCloudWatchReporter (com.kixeye.chassis.support.metrics.aws.MetricsCloudWatchReporter)5 Test (org.junit.Test)5 AmazonCloudWatch (com.amazonaws.services.cloudwatch.AmazonCloudWatch)4 MetricRegistry (com.codahale.metrics.MetricRegistry)4 PutMetricDataRequest (com.amazonaws.services.cloudwatch.model.PutMetricDataRequest)2 Ignore (org.junit.Ignore)1