Search in sources :

Example 1 with ExemplarData

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));
}
Also used : DoubleExemplarData(io.opentelemetry.sdk.metrics.data.DoubleExemplarData) ExemplarData(io.opentelemetry.sdk.metrics.data.ExemplarData) Attributes(io.opentelemetry.api.common.Attributes) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with ExemplarData

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));
}
Also used : DoubleExemplarData(io.opentelemetry.sdk.metrics.data.DoubleExemplarData) ExemplarData(io.opentelemetry.sdk.metrics.data.ExemplarData) Attributes(io.opentelemetry.api.common.Attributes) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with ExemplarData

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);
}
Also used : DoubleExemplarData(io.opentelemetry.sdk.metrics.data.DoubleExemplarData) ExemplarData(io.opentelemetry.sdk.metrics.data.ExemplarData) Attributes(io.opentelemetry.api.common.Attributes) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with ExemplarData

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));
}
Also used : DoubleExemplarData(io.opentelemetry.sdk.metrics.data.DoubleExemplarData) ExemplarData(io.opentelemetry.sdk.metrics.data.ExemplarData) Attributes(io.opentelemetry.api.common.Attributes) Test(org.junit.jupiter.api.Test)

Example 5 with ExemplarData

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));
}
Also used : DoubleExemplarData(io.opentelemetry.sdk.metrics.data.DoubleExemplarData) ExemplarData(io.opentelemetry.sdk.metrics.data.ExemplarData) Attributes(io.opentelemetry.api.common.Attributes) Test(org.junit.jupiter.api.Test)

Aggregations

ExemplarData (io.opentelemetry.sdk.metrics.data.ExemplarData)20 DoubleExemplarData (io.opentelemetry.sdk.metrics.data.DoubleExemplarData)19 Test (org.junit.jupiter.api.Test)19 Attributes (io.opentelemetry.api.common.Attributes)18 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 ExemplarReservoir (io.opentelemetry.sdk.metrics.exemplar.ExemplarReservoir)3 InstrumentType (io.opentelemetry.sdk.metrics.common.InstrumentType)2 AggregationTemporality (io.opentelemetry.sdk.metrics.data.AggregationTemporality)2 LongExemplarData (io.opentelemetry.sdk.metrics.data.LongExemplarData)1 MetricData (io.opentelemetry.sdk.metrics.data.MetricData)1 ArrayList (java.util.ArrayList)1