Search in sources :

Example 1 with SamplingTransformer

use of com.codahale.metrics.newrelic.transformer.interfaces.SamplingTransformer in project dropwizard-metrics-newrelic by newrelic.

the class TimerTransformerTest method testTransformWithAttributeAndNameCustomization.

@Test
void testTransformWithAttributeAndNameCustomization() {
    Attributes otherTags = new Attributes().put("tag", "value").put("otherTag", "otherValue");
    long now = System.currentTimeMillis();
    Gauge result1 = new Gauge(baseName, 55d, now, otherTags);
    Gauge result2 = new Gauge(baseName, 999d, now, otherTags);
    Count expectedCount = createExpectedCountMetric(otherTags);
    Timer timer = mock(Timer.class);
    SamplingTransformer samplingTransformer = mock(SamplingTransformer.class);
    MeteredTransformer meteredTransformer = mock(MeteredTransformer.class);
    CountingTransformer countingTransformer = mock(CountingTransformer.class);
    when(samplingTransformer.transform(eq(baseName), eq(timer), notNull())).thenReturn(singleton(result1));
    when(meteredTransformer.transform(eq(baseName), eq(timer), notNull())).thenReturn(singleton(result2));
    when(countingTransformer.transform(eq(baseName), eq(timer), notNull())).thenReturn(singleton(expectedCount));
    TimerTransformer timerTransformer = new TimerTransformer(samplingTransformer, meteredTransformer, countingTransformer, MetricCustomizerTestUtils.NAME_TAG_STRIPPER, MetricCustomizerTestUtils.ATTRIBUTES_FROM_TAGGED_NAME);
    Collection<Metric> results = timerTransformer.transform(baseName + "[tag:value,otherTag:otherValue]", timer);
    Collection<Metric> expected = Sets.newSet(result1, result2, expectedCount);
    assertEquals(expected, results);
}
Also used : SamplingTransformer(com.codahale.metrics.newrelic.transformer.interfaces.SamplingTransformer) MeteredTransformer(com.codahale.metrics.newrelic.transformer.interfaces.MeteredTransformer) Timer(com.codahale.metrics.Timer) Attributes(com.newrelic.telemetry.Attributes) Metric(com.newrelic.telemetry.metrics.Metric) Count(com.newrelic.telemetry.metrics.Count) CountingTransformer(com.codahale.metrics.newrelic.transformer.interfaces.CountingTransformer) Gauge(com.newrelic.telemetry.metrics.Gauge) Test(org.junit.jupiter.api.Test)

Example 2 with SamplingTransformer

use of com.codahale.metrics.newrelic.transformer.interfaces.SamplingTransformer in project dropwizard-metrics-newrelic by newrelic.

the class TimerTransformerTest method testTransform.

@Test
void testTransform() {
    long now = System.currentTimeMillis();
    Gauge result1 = new Gauge(baseName, 55d, now, new Attributes());
    Gauge result2 = new Gauge(baseName, 999d, now, new Attributes());
    Count expectedCount = createExpectedCountMetric(new Attributes());
    Timer timer = mock(Timer.class);
    SamplingTransformer samplingTransformer = mock(SamplingTransformer.class);
    MeteredTransformer meteredTransformer = mock(MeteredTransformer.class);
    CountingTransformer countingTransformer = mock(CountingTransformer.class);
    when(samplingTransformer.transform(eq(baseName), eq(timer), notNull())).thenReturn(singleton(result1));
    when(meteredTransformer.transform(eq(baseName), eq(timer), notNull())).thenReturn(singleton(result2));
    when(countingTransformer.transform(eq(baseName), eq(timer), notNull())).thenReturn(singleton(expectedCount));
    TimerTransformer timerTransformer = new TimerTransformer(samplingTransformer, meteredTransformer, countingTransformer);
    Collection<Metric> results = timerTransformer.transform(baseName, timer);
    Collection<Metric> expected = Sets.newSet(result1, result2, expectedCount);
    assertEquals(expected, results);
}
Also used : SamplingTransformer(com.codahale.metrics.newrelic.transformer.interfaces.SamplingTransformer) MeteredTransformer(com.codahale.metrics.newrelic.transformer.interfaces.MeteredTransformer) Timer(com.codahale.metrics.Timer) Attributes(com.newrelic.telemetry.Attributes) Metric(com.newrelic.telemetry.metrics.Metric) Count(com.newrelic.telemetry.metrics.Count) CountingTransformer(com.codahale.metrics.newrelic.transformer.interfaces.CountingTransformer) Gauge(com.newrelic.telemetry.metrics.Gauge) Test(org.junit.jupiter.api.Test)

Aggregations

Timer (com.codahale.metrics.Timer)2 CountingTransformer (com.codahale.metrics.newrelic.transformer.interfaces.CountingTransformer)2 MeteredTransformer (com.codahale.metrics.newrelic.transformer.interfaces.MeteredTransformer)2 SamplingTransformer (com.codahale.metrics.newrelic.transformer.interfaces.SamplingTransformer)2 Attributes (com.newrelic.telemetry.Attributes)2 Count (com.newrelic.telemetry.metrics.Count)2 Gauge (com.newrelic.telemetry.metrics.Gauge)2 Metric (com.newrelic.telemetry.metrics.Metric)2 Test (org.junit.jupiter.api.Test)2