Search in sources :

Example 1 with DoubleAccumulation

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

the class TemporalMetricStorageTest method synchronousDelta_dropsStale.

@Test
void synchronousDelta_dropsStale() {
    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<>();
    Attributes attr1 = Attributes.builder().put("key", "value1").build();
    measurement1.put(attr1, DoubleAccumulation.create(3));
    assertThat(storage.buildMetricFor(collector1, Resource.empty(), InstrumentationLibraryInfo.empty(), METRIC_DESCRIPTOR, AggregationTemporality.DELTA, measurement1, 0, 10)).hasDoubleSum().isDelta().points().hasSize(1).isNotEmpty().contains(ImmutableDoublePointData.create(0, 10, attr1, 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", "value2").build();
    measurement2.put(attr2, DoubleAccumulation.create(7));
    assertThat(storage.buildMetricFor(collector1, Resource.empty(), InstrumentationLibraryInfo.empty(), METRIC_DESCRIPTOR, AggregationTemporality.DELTA, measurement2, 0, 20)).hasDoubleSum().isDelta().points().hasSize(1).isNotEmpty().containsExactly(ImmutableDoublePointData.create(10, 20, attr2, 7));
}
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 2 with DoubleAccumulation

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

the class TemporalMetricStorageTest method asynchronousDelta_diffsLastTimestamp.

@Test
void asynchronousDelta_diffsLastTimestamp() {
    AggregationTemporality temporality = AggregationTemporality.DELTA;
    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().isDelta().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().isDelta().points().isNotEmpty().satisfiesExactly(point -> assertThat(point).hasStartEpochNanos(10).hasEpochNanos(30).hasValue(0));
    // 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().isDelta().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().isDelta().points().isNotEmpty().satisfiesExactly(point -> assertThat(point).hasStartEpochNanos(30).hasEpochNanos(35).hasValue(-1));
}
Also used : DoubleAccumulation(io.opentelemetry.sdk.metrics.internal.aggregator.DoubleAccumulation) AggregationTemporality(io.opentelemetry.sdk.metrics.data.AggregationTemporality) Test(org.junit.jupiter.api.Test)

Example 3 with DoubleAccumulation

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

the class TemporalMetricStorageTest method asynchronousDelta_dropsStale.

@Test
void asynchronousDelta_dropsStale() {
    TemporalMetricStorage<DoubleAccumulation> storage = new TemporalMetricStorage<>(ASYNC_SUM, /* isSynchronous= */
    false);
    // Send in new measurement at time 10 for collector 1, with attr1
    Map<Attributes, DoubleAccumulation> measurement1 = new HashMap<>();
    Attributes attr1 = Attributes.builder().put("key", "value1").build();
    measurement1.put(attr1, DoubleAccumulation.create(3));
    assertThat(storage.buildMetricFor(collector1, Resource.empty(), InstrumentationLibraryInfo.empty(), METRIC_DESCRIPTOR, AggregationTemporality.DELTA, measurement1, 0, 10)).hasDoubleSum().isDelta().points().hasSize(1).isNotEmpty().contains(ImmutableDoublePointData.create(0, 10, attr1, 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", "value2").build();
    measurement2.put(attr2, DoubleAccumulation.create(7));
    assertThat(storage.buildMetricFor(collector1, Resource.empty(), InstrumentationLibraryInfo.empty(), METRIC_DESCRIPTOR, AggregationTemporality.DELTA, measurement2, 0, 20)).hasDoubleSum().isDelta().points().hasSize(1).isNotEmpty().containsExactly(ImmutableDoublePointData.create(10, 20, attr2, 7));
}
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 4 with DoubleAccumulation

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

the class TemporalMetricStorageTest method asynchronousCumulative_dropsStale.

@Test
void asynchronousCumulative_dropsStale() {
    TemporalMetricStorage<DoubleAccumulation> storage = new TemporalMetricStorage<>(ASYNC_SUM, /* isSynchronous= */
    false);
    // Send in new measurement at time 10 for collector 1, with attr1
    Map<Attributes, DoubleAccumulation> measurement1 = new HashMap<>();
    Attributes attr1 = Attributes.builder().put("key", "value1").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(1).isNotEmpty().contains(ImmutableDoublePointData.create(0, 10, attr1, 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", "value2").build();
    measurement2.put(attr2, DoubleAccumulation.create(7));
    assertThat(storage.buildMetricFor(collector1, Resource.empty(), InstrumentationLibraryInfo.empty(), METRIC_DESCRIPTOR, AggregationTemporality.CUMULATIVE, measurement2, 0, 20)).hasDoubleSum().isCumulative().points().hasSize(1).isNotEmpty().containsExactly(ImmutableDoublePointData.create(0, 20, attr2, 7));
}
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 5 with DoubleAccumulation

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

the class TemporalMetricStorageTest method synchronousDelta_useLastTimestamp.

@Test
void synchronousDelta_useLastTimestamp() {
    AggregationTemporality temporality = AggregationTemporality.DELTA;
    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().isDelta().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().isDelta().points().isNotEmpty().satisfiesExactly(point -> assertThat(point).hasStartEpochNanos(10).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().isDelta().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().isDelta().points().isNotEmpty().satisfiesExactly(point -> assertThat(point).hasStartEpochNanos(30).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)

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