Search in sources :

Example 6 with DoubleAccumulation

use of io.opentelemetry.sdk.metrics.internal.aggregator.DoubleAccumulation in project opentelemetry-java by open-telemetry.

the class TemporalMetricStorageTest method synchronousCumulative_dropsStaleAtLimit.

@Test
void synchronousCumulative_dropsStaleAtLimit() {
    TemporalMetricStorage<DoubleAccumulation> storage = new TemporalMetricStorage<>(SUM, /* isSynchronous= */
    true);
    // Send in new measurement at time 10 for collector 1, with attr1
    Map<Attributes, DoubleAccumulation> measurement1 = new HashMap<>();
    for (int i = 0; i < MetricStorageUtils.MAX_ACCUMULATIONS; i++) {
        Attributes attr1 = Attributes.builder().put("key", "value" + i).build();
        measurement1.put(attr1, DoubleAccumulation.create(3));
    }
    assertThat(storage.buildMetricFor(collector1, Resource.empty(), InstrumentationLibraryInfo.empty(), METRIC_DESCRIPTOR, AggregationTemporality.CUMULATIVE, measurement1, 0, 10)).hasDoubleSum().isCumulative().points().hasSize(MetricStorageUtils.MAX_ACCUMULATIONS).isNotEmpty().allSatisfy(point -> assertThat(point).hasStartEpochNanos(0).hasEpochNanos(10).hasValue(3));
    // Send in new measurement at time 20 for collector 1, with attr2
    // Result should drop accumulation for attr1, only reporting accumulation for attr2
    Map<Attributes, DoubleAccumulation> measurement2 = new HashMap<>();
    Attributes attr2 = Attributes.builder().put("key", "value" + (MetricStorageUtils.MAX_ACCUMULATIONS + 1)).build();
    measurement2.put(attr2, DoubleAccumulation.create(3));
    assertThat(storage.buildMetricFor(collector1, Resource.empty(), InstrumentationLibraryInfo.empty(), METRIC_DESCRIPTOR, AggregationTemporality.CUMULATIVE, measurement2, 0, 20)).hasDoubleSum().isCumulative().points().hasSize(// Limiting to only recent measurements means we cut everything here.
    1).isNotEmpty().extracting(PointData::getAttributes).contains(attr2);
}
Also used : HashMap(java.util.HashMap) DoubleAccumulation(io.opentelemetry.sdk.metrics.internal.aggregator.DoubleAccumulation) Attributes(io.opentelemetry.api.common.Attributes) Test(org.junit.jupiter.api.Test)

Example 7 with DoubleAccumulation

use of io.opentelemetry.sdk.metrics.internal.aggregator.DoubleAccumulation in project opentelemetry-java by open-telemetry.

the class TemporalMetricStorageTest method asynchronousCumulative_doesNotJoin.

@Test
void asynchronousCumulative_doesNotJoin() {
    AggregationTemporality temporality = AggregationTemporality.CUMULATIVE;
    TemporalMetricStorage<DoubleAccumulation> storage = new TemporalMetricStorage<>(ASYNC_SUM, /* isSynchronous= */
    false);
    // Send in new measurement at time 10 for collector 1
    assertThat(storage.buildMetricFor(collector1, Resource.empty(), InstrumentationLibraryInfo.empty(), METRIC_DESCRIPTOR, temporality, createMeasurement(3), 0, 10)).hasDoubleSum().isCumulative().points().isNotEmpty().satisfiesExactly(point -> assertThat(point).hasStartEpochNanos(0).hasEpochNanos(10).hasValue(3));
    // Send in new measurement at time 30 for collector 1
    assertThat(storage.buildMetricFor(collector1, Resource.empty(), InstrumentationLibraryInfo.empty(), METRIC_DESCRIPTOR, temporality, createMeasurement(3), 0, 30)).hasDoubleSum().isCumulative().points().isNotEmpty().satisfiesExactly(point -> assertThat(point).hasStartEpochNanos(0).hasEpochNanos(30).hasValue(3));
    // Send in new measurement at time 40 for collector 2
    assertThat(storage.buildMetricFor(collector2, Resource.empty(), InstrumentationLibraryInfo.empty(), METRIC_DESCRIPTOR, temporality, createMeasurement(4), 0, 60)).hasDoubleSum().isCumulative().points().isNotEmpty().satisfiesExactly(point -> assertThat(point).hasStartEpochNanos(0).hasEpochNanos(60).hasValue(4));
    // Send in new measurement at time 35 for collector 1
    assertThat(storage.buildMetricFor(collector1, Resource.empty(), InstrumentationLibraryInfo.empty(), METRIC_DESCRIPTOR, temporality, createMeasurement(2), 0, 35)).hasDoubleSum().isCumulative().points().isNotEmpty().satisfiesExactly(point -> assertThat(point).hasStartEpochNanos(0).hasEpochNanos(35).hasValue(2));
}
Also used : DoubleAccumulation(io.opentelemetry.sdk.metrics.internal.aggregator.DoubleAccumulation) AggregationTemporality(io.opentelemetry.sdk.metrics.data.AggregationTemporality) Test(org.junit.jupiter.api.Test)

Example 8 with DoubleAccumulation

use of io.opentelemetry.sdk.metrics.internal.aggregator.DoubleAccumulation in project opentelemetry-java by open-telemetry.

the class TemporalMetricStorageTest method synchronousCumulative_joinsWithLastMeasurementForCumulative.

@Test
void synchronousCumulative_joinsWithLastMeasurementForCumulative() {
    AggregationTemporality temporality = AggregationTemporality.CUMULATIVE;
    TemporalMetricStorage<DoubleAccumulation> storage = new TemporalMetricStorage<>(SUM, /* isSynchronous= */
    true);
    // Send in new measurement at time 10 for collector 1
    assertThat(storage.buildMetricFor(collector1, Resource.empty(), InstrumentationLibraryInfo.empty(), METRIC_DESCRIPTOR, temporality, createMeasurement(3), 0, 10)).hasDoubleSum().isCumulative().points().isNotEmpty().satisfiesExactly(point -> assertThat(point).hasStartEpochNanos(0).hasEpochNanos(10).hasValue(3));
    // Send in new measurement at time 30 for collector 1
    assertThat(storage.buildMetricFor(collector1, Resource.empty(), InstrumentationLibraryInfo.empty(), METRIC_DESCRIPTOR, temporality, createMeasurement(3), 0, 30)).hasDoubleSum().isCumulative().points().isNotEmpty().satisfiesExactly(point -> assertThat(point).hasStartEpochNanos(0).hasEpochNanos(30).hasValue(6));
    // Send in new measurement at time 40 for collector 2
    assertThat(storage.buildMetricFor(collector2, Resource.empty(), InstrumentationLibraryInfo.empty(), METRIC_DESCRIPTOR, temporality, createMeasurement(4), 0, 60)).hasDoubleSum().isCumulative().points().isNotEmpty().satisfiesExactly(point -> assertThat(point).hasStartEpochNanos(0).hasEpochNanos(60).hasValue(4));
    // Send in new measurement at time 35 for collector 1
    assertThat(storage.buildMetricFor(collector1, Resource.empty(), InstrumentationLibraryInfo.empty(), METRIC_DESCRIPTOR, temporality, createMeasurement(2), 0, 35)).hasDoubleSum().isCumulative().points().isNotEmpty().satisfiesExactly(point -> assertThat(point).hasStartEpochNanos(0).hasEpochNanos(35).hasValue(8));
}
Also used : DoubleAccumulation(io.opentelemetry.sdk.metrics.internal.aggregator.DoubleAccumulation) AggregationTemporality(io.opentelemetry.sdk.metrics.data.AggregationTemporality) Test(org.junit.jupiter.api.Test)

Aggregations

DoubleAccumulation (io.opentelemetry.sdk.metrics.internal.aggregator.DoubleAccumulation)8 Test (org.junit.jupiter.api.Test)8 Attributes (io.opentelemetry.api.common.Attributes)4 AggregationTemporality (io.opentelemetry.sdk.metrics.data.AggregationTemporality)4 HashMap (java.util.HashMap)4