use of io.opentelemetry.sdk.metrics.data.ExemplarData in project opentelemetry-java by open-telemetry.
the class DoubleExponentialHistogramAggregatorTest method diffDownScaledAccumulation.
@Test
void diffDownScaledAccumulation() {
Attributes attributes = Attributes.builder().put("test", "value").build();
ExemplarData exemplar = DoubleExemplarData.create(attributes, 2L, SpanContext.create("00000000000000000000000000000001", "0000000000000002", TraceFlags.getDefault(), TraceState.getDefault()), 1);
List<ExemplarData> exemplars = Collections.singletonList(exemplar);
List<ExemplarData> previousExemplars = Collections.singletonList(DoubleExemplarData.create(attributes, 1L, SpanContext.create("00000000000000000000000000000001", "0000000000000002", TraceFlags.getDefault(), TraceState.getDefault()), 2));
ExponentialHistogramAccumulation nextAccumulation = getTestAccumulation(exemplars, 1, 1, 100, -1, -100);
ExponentialHistogramAccumulation previousAccumulation = getTestAccumulation(previousExemplars, 1, -1);
// Assure most recent exemplars are kept
ExponentialHistogramAccumulation diff = aggregator.diff(previousAccumulation, nextAccumulation);
assertThat(diff).isEqualTo(getTestAccumulation(exemplars, 1, 100, -100));
}
use of io.opentelemetry.sdk.metrics.data.ExemplarData in project opentelemetry-java by open-telemetry.
the class DoubleExponentialHistogramAggregatorTest method testMergeAccumulation.
@Test
void testMergeAccumulation() {
Attributes attributes = Attributes.builder().put("test", "value").build();
ExemplarData exemplar = DoubleExemplarData.create(attributes, 2L, SpanContext.create("00000000000000000000000000000001", "0000000000000002", TraceFlags.getDefault(), TraceState.getDefault()), 1);
List<ExemplarData> exemplars = Collections.singletonList(exemplar);
List<ExemplarData> previousExemplars = Collections.singletonList(DoubleExemplarData.create(attributes, 1L, SpanContext.create("00000000000000000000000000000001", "0000000000000002", TraceFlags.getDefault(), TraceState.getDefault()), 2));
ExponentialHistogramAccumulation previousAccumulation = getTestAccumulation(previousExemplars, 0, 4.1, 100, 100, 10000, 1000000);
ExponentialHistogramAccumulation nextAccumulation = getTestAccumulation(exemplars, -1000, -2000000, -8.2, 2.3);
// Merged accumulations should equal accumulation with equivalent recordings and latest
// exemplars.
assertThat(aggregator.merge(previousAccumulation, nextAccumulation)).isEqualTo(getTestAccumulation(exemplars, 0, 4.1, 100, 100, 10000, 1000000, -1000, -2000000, -8.2, 2.3));
}
use of io.opentelemetry.sdk.metrics.data.ExemplarData in project opentelemetry-java by open-telemetry.
the class DoubleExponentialHistogramAggregatorTest method testExemplarsInAccumulation.
@Test
void testExemplarsInAccumulation() {
DoubleExponentialHistogramAggregator agg = new DoubleExponentialHistogramAggregator(() -> reservoir);
Attributes attributes = Attributes.builder().put("test", "value").build();
ExemplarData exemplar = DoubleExemplarData.create(attributes, 2L, SpanContext.create("00000000000000000000000000000001", "0000000000000002", TraceFlags.getDefault(), TraceState.getDefault()), 1);
List<ExemplarData> exemplars = Collections.singletonList(exemplar);
Mockito.when(reservoir.collectAndReset(Attributes.empty())).thenReturn(exemplars);
AggregatorHandle<ExponentialHistogramAccumulation> aggregatorHandle = agg.createHandle();
aggregatorHandle.recordDouble(0, attributes, Context.root());
assertThat(Objects.requireNonNull(aggregatorHandle.accumulateThenReset(Attributes.empty())).getExemplars()).isEqualTo(exemplars);
}
use of io.opentelemetry.sdk.metrics.data.ExemplarData in project opentelemetry-java by open-telemetry.
the class DoubleHistogramAggregatorTest method mergeAccumulation.
@Test
void mergeAccumulation() {
Attributes attributes = Attributes.builder().put("test", "value").build();
ExemplarData exemplar = DoubleExemplarData.create(attributes, 2L, SpanContext.create("00000000000000000000000000000001", "0000000000000002", TraceFlags.getDefault(), TraceState.getDefault()), 1);
List<ExemplarData> exemplars = Collections.singletonList(exemplar);
List<ExemplarData> previousExemplars = Collections.singletonList(DoubleExemplarData.create(attributes, 1L, SpanContext.create("00000000000000000000000000000001", "0000000000000002", TraceFlags.getDefault(), TraceState.getDefault()), 2));
HistogramAccumulation previousAccumulation = HistogramAccumulation.create(2, new long[] { 1, 1, 0 }, previousExemplars);
HistogramAccumulation nextAccumulation = HistogramAccumulation.create(2, new long[] { 0, 0, 2 }, exemplars);
// Assure most recent exemplars are kept.
assertThat(aggregator.merge(previousAccumulation, nextAccumulation)).isEqualTo(HistogramAccumulation.create(4, new long[] { 1, 1, 2 }, exemplars));
}
use of io.opentelemetry.sdk.metrics.data.ExemplarData in project opentelemetry-java by open-telemetry.
the class DoubleHistogramAggregatorTest method diffAccumulation.
@Test
void diffAccumulation() {
Attributes attributes = Attributes.builder().put("test", "value").build();
ExemplarData exemplar = DoubleExemplarData.create(attributes, 2L, SpanContext.create("00000000000000000000000000000001", "0000000000000002", TraceFlags.getDefault(), TraceState.getDefault()), 1);
List<ExemplarData> exemplars = Collections.singletonList(exemplar);
List<ExemplarData> previousExemplars = Collections.singletonList(DoubleExemplarData.create(attributes, 1L, SpanContext.create("00000000000000000000000000000001", "0000000000000002", TraceFlags.getDefault(), TraceState.getDefault()), 2));
HistogramAccumulation previousAccumulation = HistogramAccumulation.create(2, new long[] { 1, 1, 2 }, previousExemplars);
HistogramAccumulation nextAccumulation = HistogramAccumulation.create(5, new long[] { 2, 2, 2 }, exemplars);
// Assure most recent exemplars are kept.
assertThat(aggregator.diff(previousAccumulation, nextAccumulation)).isEqualTo(HistogramAccumulation.create(3, new long[] { 1, 1, 0 }, exemplars));
}
Aggregations