use of com.newrelic.telemetry.metrics.Metric in project dropwizard-metrics-newrelic by newrelic.
the class HistogramTransformerTest method testTransformWithAttributeAndNameCustomization.
@Test
void testTransformWithAttributeAndNameCustomization() {
Histogram histogram = new Histogram(new ExponentiallyDecayingReservoir());
String baseName = "history";
String name = baseName + "[tag:value,otherTag:otherValue]";
Attributes otherAttributes = new Attributes().put("tag", "value").put("otherTag", "otherValue");
long startTime = System.currentTimeMillis();
long endTime = startTime + 11000;
Count expectedCount = new Count("countery", 12.6, startTime, endTime, otherAttributes);
Metric expectedSamplingResult = new Gauge("samplery", 77.1, endTime, otherAttributes);
Collection<Metric> expectedMetrics = Sets.newSet(expectedCount, expectedSamplingResult);
when(counter.transform(eq("history"), eq(histogram), notNull())).thenReturn(singleton(expectedCount));
when(sampler.transform(eq("history"), eq(histogram), notNull())).thenReturn(singleton(expectedSamplingResult));
HistogramTransformer testClass = new HistogramTransformer(counter, sampler, MetricCustomizerTestUtils.NAME_TAG_STRIPPER, MetricCustomizerTestUtils.ATTRIBUTES_FROM_TAGGED_NAME);
Collection<Metric> result = testClass.transform(name, histogram);
assertEquals(expectedMetrics, result);
}
use of com.newrelic.telemetry.metrics.Metric in project dropwizard-metrics-newrelic by newrelic.
the class HistogramTransformerTest method testTransform.
@Test
void testTransform() {
Histogram histogram = new Histogram(new ExponentiallyDecayingReservoir());
long startTime = System.currentTimeMillis();
long endTime = startTime + 11000;
Count expectedCount = new Count("countery", 12.6, startTime, endTime, new Attributes());
Metric expectedSamplingResult = new Gauge("samplery", 77.1, endTime, new Attributes());
Collection<Metric> expectedMetrics = Sets.newSet(expectedCount, expectedSamplingResult);
when(counter.transform(eq("history"), eq(histogram), notNull())).thenReturn(singleton(expectedCount));
when(sampler.transform(eq("history"), eq(histogram), notNull())).thenReturn(singleton(expectedSamplingResult));
HistogramTransformer testClass = new HistogramTransformer(counter, sampler);
Collection<Metric> result = testClass.transform("history", histogram);
assertEquals(expectedMetrics, result);
}
use of com.newrelic.telemetry.metrics.Metric in project dropwizard-metrics-newrelic by newrelic.
the class MeterTransformerTest method testTransform.
@Test
void testTransform() {
Meter meter = new Meter();
Metric expectedMetric = createExpectedGaugeMetric(new Attributes());
Count expectedCount = createExpectedCountMetric(new Attributes());
Collection<Metric> expectedMeters = Sets.newSet(expectedMetric, expectedCount);
when(converter.transform(eq(baseName), eq(meter), notNull())).thenReturn(expectedMeters);
when(countingTransformer.transform(eq(baseName), eq(meter), notNull())).thenReturn(singleton(expectedCount));
MeterTransformer testClass = new MeterTransformer(converter, countingTransformer);
Collection<Metric> result = testClass.transform(baseName, meter);
assertEquals(expectedMeters, result);
}
use of com.newrelic.telemetry.metrics.Metric 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);
}
use of com.newrelic.telemetry.metrics.Metric in project dropwizard-metrics-newrelic by newrelic.
the class SamplingTransformerTest method testMultipleVisitsGetYouSomeState.
@Test
void testMultipleVisitsGetYouSomeState() {
Histogram histogram = new Histogram(new SlidingWindowReservoir(10));
recordSomeData(histogram);
long later = now + 5000;
TimeTracker timeTracker = mock(TimeTracker.class);
when(timeTracker.getCurrentTime()).thenReturn(later);
when(timeTracker.getPreviousTime()).thenReturn(now);
SamplingTransformer testClass = new SamplingTransformer(timeTracker, 0.10d);
testClass.transform("hollerMonkey", histogram, baseAttributes);
recordSomeData(histogram);
Collection<Metric> result = testClass.transform("hollerMonkey", histogram, baseAttributes);
Snapshot snapshot = histogram.getSnapshot();
Collection<Metric> expected = Sets.newSet(new Summary("hollerMonkey", 10, 40, 3 * 10, 5 * 10, now, later, new Attributes()), new Gauge("hollerMonkey.percentiles", snapshot.getMedian() * 10, later, percentileAttributes(50.0).put("commonName", "median")), new Gauge("hollerMonkey.percentiles", snapshot.get75thPercentile() * 10, later, percentileAttributes(75.0)), new Gauge("hollerMonkey.percentiles", snapshot.get95thPercentile() * 10, later, percentileAttributes(95.0)), new Gauge("hollerMonkey.percentiles", snapshot.get98thPercentile() * 10, later, percentileAttributes(98.0)), new Gauge("hollerMonkey.percentiles", snapshot.get99thPercentile() * 10, later, percentileAttributes(99.0)), new Gauge("hollerMonkey.percentiles", snapshot.get999thPercentile() * 10, later, percentileAttributes(99.9)));
assertEquals(expected, result);
}
Aggregations