use of com.newrelic.telemetry.metrics.Metric in project dropwizard-metrics-newrelic by newrelic.
the class GaugeTransformerTest method testDoubleGauge.
@Test
void testDoubleGauge() {
// Given
double value = 12345d;
Gauge<Double> wizardGauge = () -> value;
Metric expectedMetric = new com.newrelic.telemetry.metrics.Gauge(GAUGE_NAME, value, timestamp, new Attributes());
GaugeTransformer converter = new GaugeTransformer(clock);
// When
Collection<Metric> result = converter.transform(GAUGE_NAME, wizardGauge);
// Then
assertEquals(singleton(expectedMetric), result);
}
use of com.newrelic.telemetry.metrics.Metric in project dropwizard-metrics-newrelic by newrelic.
the class GaugeTransformerTest method testRatioGauge.
@Test
void testRatioGauge() {
// Given
Ratio ratio = Ratio.of(37, 31);
RatioGauge wizardGauge = new RatioGauge() {
@Override
protected Ratio getRatio() {
return ratio;
}
};
Metric expectedMetric = new com.newrelic.telemetry.metrics.Gauge(GAUGE_NAME, ratio.getValue(), timestamp, new Attributes());
GaugeTransformer converter = new GaugeTransformer(clock);
// When
Collection<Metric> result = converter.transform(GAUGE_NAME, wizardGauge);
// Then
assertEquals(singleton(expectedMetric), result);
}
use of com.newrelic.telemetry.metrics.Metric in project dropwizard-metrics-newrelic by newrelic.
the class GaugeTransformerTest method testOtherNumericValue.
@Test
void testOtherNumericValue() {
// Given
BigDecimal value = new BigDecimal(12345d);
Gauge<BigDecimal> wizardGauge = () -> value;
Metric expectedMetric = new com.newrelic.telemetry.metrics.Gauge(GAUGE_NAME, value.doubleValue(), timestamp, new Attributes());
GaugeTransformer converter = new GaugeTransformer(clock);
// When
Collection<Metric> result = converter.transform(GAUGE_NAME, wizardGauge);
// Then
assertEquals(singleton(expectedMetric), result);
}
use of com.newrelic.telemetry.metrics.Metric in project dropwizard-metrics-newrelic by newrelic.
the class MeterTransformerTest method testTransformWithAttributeAndNameCustomization.
@Test
void testTransformWithAttributeAndNameCustomization() {
Attributes otherAttributes = new Attributes().put("tag", "value").put("otherTag", "otherValue");
Meter meter = new Meter();
Metric expectedMetric = createExpectedGaugeMetric(otherAttributes);
Count expectedCount = createExpectedCountMetric(otherAttributes);
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, MetricCustomizerTestUtils.NAME_TAG_STRIPPER, MetricCustomizerTestUtils.ATTRIBUTES_FROM_TAGGED_NAME);
Collection<Metric> result = testClass.transform(baseName + "[tag:value,otherTag:otherValue]", meter);
assertEquals(expectedMeters, result);
}
use of com.newrelic.telemetry.metrics.Metric 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);
}
Aggregations