Search in sources :

Example 1 with PointData

use of io.opentelemetry.sdk.metrics.data.PointData in project opentelemetry-java by open-telemetry.

the class SdkDoubleHistogramTest method stressTest_WithDifferentLabelSet.

@Test
void stressTest_WithDifferentLabelSet() {
    String[] keys = { "Key_1", "Key_2", "Key_3", "Key_4" };
    String[] values = { "Value_1", "Value_2", "Value_3", "Value_4" };
    DoubleHistogram doubleRecorder = sdkMeter.histogramBuilder("testRecorder").build();
    StressTestRunner.Builder stressTestBuilder = StressTestRunner.builder().setInstrument((SdkDoubleHistogram) doubleRecorder).setCollectionIntervalMs(100);
    for (int i = 0; i < 4; i++) {
        stressTestBuilder.addOperation(StressTestRunner.Operation.create(2_000, 1, new SdkDoubleHistogramTest.OperationUpdaterDirectCall(doubleRecorder, keys[i], values[i])));
        stressTestBuilder.addOperation(StressTestRunner.Operation.create(2_000, 1, new OperationUpdaterWithBinding(((SdkDoubleHistogram) doubleRecorder).bind(Attributes.builder().put(keys[i], values[i]).build()))));
    }
    stressTestBuilder.build().run();
    assertThat(sdkMeterReader.collectAllMetrics()).satisfiesExactly(metric -> assertThat(metric).hasResource(RESOURCE).hasInstrumentationLibrary(INSTRUMENTATION_LIBRARY_INFO).hasName("testRecorder").hasDoubleHistogram().points().allSatisfy(point -> assertThat(point).hasStartEpochNanos(testClock.now()).hasEpochNanos(testClock.now()).hasCount(4_000).hasSum(40_000).hasBucketCounts(0, 2000, 2000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)).extracting(PointData::getAttributes).containsExactlyInAnyOrder(Attributes.of(stringKey(keys[0]), values[0]), Attributes.of(stringKey(keys[1]), values[1]), Attributes.of(stringKey(keys[2]), values[2]), Attributes.of(stringKey(keys[3]), values[3])));
}
Also used : Resource(io.opentelemetry.sdk.resources.Resource) DoubleHistogram(io.opentelemetry.api.metrics.DoubleHistogram) Attributes(io.opentelemetry.api.common.Attributes) InstrumentationLibraryInfo(io.opentelemetry.sdk.common.InstrumentationLibraryInfo) OperationUpdater(io.opentelemetry.sdk.metrics.StressTestRunner.OperationUpdater) Test(org.junit.jupiter.api.Test) PointData(io.opentelemetry.sdk.metrics.data.PointData) InMemoryMetricReader(io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader) LogCapturer(io.github.netmikey.logunit.api.LogCapturer) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) BoundDoubleHistogram(io.opentelemetry.sdk.metrics.internal.instrument.BoundDoubleHistogram) SuppressLogger(io.opentelemetry.internal.testing.slf4j.SuppressLogger) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) AttributeKey.stringKey(io.opentelemetry.api.common.AttributeKey.stringKey) Duration(java.time.Duration) TestClock(io.opentelemetry.sdk.testing.time.TestClock) MetricAssertions.assertThat(io.opentelemetry.sdk.testing.assertj.MetricAssertions.assertThat) Meter(io.opentelemetry.api.metrics.Meter) PointData(io.opentelemetry.sdk.metrics.data.PointData) DoubleHistogram(io.opentelemetry.api.metrics.DoubleHistogram) BoundDoubleHistogram(io.opentelemetry.sdk.metrics.internal.instrument.BoundDoubleHistogram) Test(org.junit.jupiter.api.Test)

Example 2 with PointData

use of io.opentelemetry.sdk.metrics.data.PointData in project opentelemetry-java by open-telemetry.

the class SdkLongCounterTest method stressTest_WithDifferentLabelSet.

@Test
void stressTest_WithDifferentLabelSet() {
    String[] keys = { "Key_1", "Key_2", "Key_3", "Key_4" };
    String[] values = { "Value_1", "Value_2", "Value_3", "Value_4" };
    LongCounter longCounter = sdkMeter.counterBuilder("testCounter").build();
    StressTestRunner.Builder stressTestBuilder = StressTestRunner.builder().setInstrument((SdkLongCounter) longCounter).setCollectionIntervalMs(100);
    for (int i = 0; i < 4; i++) {
        stressTestBuilder.addOperation(StressTestRunner.Operation.create(1_000, 2, new OperationUpdaterDirectCall(longCounter, keys[i], values[i])));
        stressTestBuilder.addOperation(StressTestRunner.Operation.create(1_000, 2, new OperationUpdaterWithBinding(((SdkLongCounter) longCounter).bind(Attributes.builder().put(keys[i], values[i]).build()))));
    }
    stressTestBuilder.build().run();
    assertThat(sdkMeterReader.collectAllMetrics()).satisfiesExactly(metric -> assertThat(metric).hasResource(RESOURCE).hasInstrumentationLibrary(INSTRUMENTATION_LIBRARY_INFO).hasName("testCounter").hasLongSum().isCumulative().isMonotonic().points().allSatisfy(point -> assertThat(point).hasStartEpochNanos(testClock.now()).hasEpochNanos(testClock.now()).hasValue(20_000)).extracting(PointData::getAttributes).containsExactlyInAnyOrder(Attributes.of(stringKey(keys[0]), values[0]), Attributes.of(stringKey(keys[1]), values[1]), Attributes.of(stringKey(keys[2]), values[2]), Attributes.of(stringKey(keys[3]), values[3])));
}
Also used : LongCounter(io.opentelemetry.api.metrics.LongCounter) Resource(io.opentelemetry.sdk.resources.Resource) Attributes(io.opentelemetry.api.common.Attributes) InstrumentationLibraryInfo(io.opentelemetry.sdk.common.InstrumentationLibraryInfo) OperationUpdater(io.opentelemetry.sdk.metrics.StressTestRunner.OperationUpdater) Test(org.junit.jupiter.api.Test) PointData(io.opentelemetry.sdk.metrics.data.PointData) InMemoryMetricReader(io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader) LogCapturer(io.github.netmikey.logunit.api.LogCapturer) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) BoundLongCounter(io.opentelemetry.sdk.metrics.internal.instrument.BoundLongCounter) SuppressLogger(io.opentelemetry.internal.testing.slf4j.SuppressLogger) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) AttributeKey.stringKey(io.opentelemetry.api.common.AttributeKey.stringKey) Duration(java.time.Duration) TestClock(io.opentelemetry.sdk.testing.time.TestClock) MetricAssertions.assertThat(io.opentelemetry.sdk.testing.assertj.MetricAssertions.assertThat) Meter(io.opentelemetry.api.metrics.Meter) PointData(io.opentelemetry.sdk.metrics.data.PointData) LongCounter(io.opentelemetry.api.metrics.LongCounter) BoundLongCounter(io.opentelemetry.sdk.metrics.internal.instrument.BoundLongCounter) Test(org.junit.jupiter.api.Test)

Example 3 with PointData

use of io.opentelemetry.sdk.metrics.data.PointData in project opentelemetry-java by open-telemetry.

the class SdkLongHistogramTest method stressTest_WithDifferentLabelSet.

@Test
void stressTest_WithDifferentLabelSet() {
    String[] keys = { "Key_1", "Key_2", "Key_3", "Key_4" };
    String[] values = { "Value_1", "Value_2", "Value_3", "Value_4" };
    LongHistogram longRecorder = sdkMeter.histogramBuilder("testRecorder").ofLongs().build();
    StressTestRunner.Builder stressTestBuilder = StressTestRunner.builder().setInstrument((SdkLongHistogram) longRecorder).setCollectionIntervalMs(100);
    for (int i = 0; i < 4; i++) {
        stressTestBuilder.addOperation(StressTestRunner.Operation.create(1_000, 2, new SdkLongHistogramTest.OperationUpdaterDirectCall(longRecorder, keys[i], values[i])));
        stressTestBuilder.addOperation(StressTestRunner.Operation.create(1_000, 2, new SdkLongHistogramTest.OperationUpdaterWithBinding(((SdkLongHistogram) longRecorder).bind(Attributes.builder().put(keys[i], values[i]).build()))));
    }
    stressTestBuilder.build().run();
    assertThat(sdkMeterReader.collectAllMetrics()).satisfiesExactly(metric -> assertThat(metric).hasResource(RESOURCE).hasInstrumentationLibrary(INSTRUMENTATION_LIBRARY_INFO).hasName("testRecorder").hasDoubleHistogram().points().allSatisfy(point -> assertThat(point).hasStartEpochNanos(testClock.now()).hasEpochNanos(testClock.now()).hasCount(2_000).hasSum(20_000).hasBucketCounts(0, 1000, 1000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)).extracting(PointData::getAttributes).containsExactlyInAnyOrder(Attributes.of(stringKey(keys[0]), values[0]), Attributes.of(stringKey(keys[1]), values[1]), Attributes.of(stringKey(keys[2]), values[2]), Attributes.of(stringKey(keys[3]), values[3])));
}
Also used : Resource(io.opentelemetry.sdk.resources.Resource) Attributes(io.opentelemetry.api.common.Attributes) BoundLongHistogram(io.opentelemetry.sdk.metrics.internal.instrument.BoundLongHistogram) InstrumentationLibraryInfo(io.opentelemetry.sdk.common.InstrumentationLibraryInfo) OperationUpdater(io.opentelemetry.sdk.metrics.StressTestRunner.OperationUpdater) Test(org.junit.jupiter.api.Test) PointData(io.opentelemetry.sdk.metrics.data.PointData) InMemoryMetricReader(io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader) LogCapturer(io.github.netmikey.logunit.api.LogCapturer) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) SuppressLogger(io.opentelemetry.internal.testing.slf4j.SuppressLogger) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) AttributeKey.stringKey(io.opentelemetry.api.common.AttributeKey.stringKey) Duration(java.time.Duration) LongHistogram(io.opentelemetry.api.metrics.LongHistogram) TestClock(io.opentelemetry.sdk.testing.time.TestClock) MetricAssertions.assertThat(io.opentelemetry.sdk.testing.assertj.MetricAssertions.assertThat) Meter(io.opentelemetry.api.metrics.Meter) PointData(io.opentelemetry.sdk.metrics.data.PointData) BoundLongHistogram(io.opentelemetry.sdk.metrics.internal.instrument.BoundLongHistogram) LongHistogram(io.opentelemetry.api.metrics.LongHistogram) Test(org.junit.jupiter.api.Test)

Example 4 with PointData

use of io.opentelemetry.sdk.metrics.data.PointData in project opentelemetry-java by open-telemetry.

the class SdkDoubleUpDownCounterTest method stressTest_WithDifferentLabelSet.

@Test
void stressTest_WithDifferentLabelSet() {
    String[] keys = { "Key_1", "Key_2", "Key_3", "Key_4" };
    String[] values = { "Value_1", "Value_2", "Value_3", "Value_4" };
    DoubleUpDownCounter doubleUpDownCounter = sdkMeter.upDownCounterBuilder("testUpDownCounter").ofDoubles().build();
    StressTestRunner.Builder stressTestBuilder = StressTestRunner.builder().setInstrument((SdkDoubleUpDownCounter) doubleUpDownCounter).setCollectionIntervalMs(100);
    for (int i = 0; i < 4; i++) {
        stressTestBuilder.addOperation(StressTestRunner.Operation.create(2_000, 1, new OperationUpdaterDirectCall(doubleUpDownCounter, keys[i], values[i])));
        stressTestBuilder.addOperation(StressTestRunner.Operation.create(2_000, 1, new OperationUpdaterWithBinding(((SdkDoubleUpDownCounter) doubleUpDownCounter).bind(Attributes.builder().put(keys[i], values[i]).build()))));
    }
    stressTestBuilder.build().run();
    assertThat(sdkMeterReader.collectAllMetrics()).satisfiesExactly(metric -> assertThat(metric).hasResource(RESOURCE).hasInstrumentationLibrary(INSTRUMENTATION_LIBRARY_INFO).hasName("testUpDownCounter").hasDoubleSum().isCumulative().isNotMonotonic().points().allSatisfy(point -> assertThat(point).hasStartEpochNanos(testClock.now()).hasEpochNanos(testClock.now()).hasValue(40_000)).extracting(PointData::getAttributes).containsExactlyInAnyOrder(Attributes.of(stringKey(keys[0]), values[0]), Attributes.of(stringKey(keys[1]), values[1]), Attributes.of(stringKey(keys[2]), values[2]), Attributes.of(stringKey(keys[3]), values[3])));
}
Also used : DoubleUpDownCounter(io.opentelemetry.api.metrics.DoubleUpDownCounter) Resource(io.opentelemetry.sdk.resources.Resource) Attributes(io.opentelemetry.api.common.Attributes) InstrumentationLibraryInfo(io.opentelemetry.sdk.common.InstrumentationLibraryInfo) OperationUpdater(io.opentelemetry.sdk.metrics.StressTestRunner.OperationUpdater) Test(org.junit.jupiter.api.Test) PointData(io.opentelemetry.sdk.metrics.data.PointData) InMemoryMetricReader(io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) AttributeKey.stringKey(io.opentelemetry.api.common.AttributeKey.stringKey) BoundDoubleUpDownCounter(io.opentelemetry.sdk.metrics.internal.instrument.BoundDoubleUpDownCounter) Duration(java.time.Duration) TestClock(io.opentelemetry.sdk.testing.time.TestClock) MetricAssertions.assertThat(io.opentelemetry.sdk.testing.assertj.MetricAssertions.assertThat) Meter(io.opentelemetry.api.metrics.Meter) DoubleUpDownCounter(io.opentelemetry.api.metrics.DoubleUpDownCounter) BoundDoubleUpDownCounter(io.opentelemetry.sdk.metrics.internal.instrument.BoundDoubleUpDownCounter) PointData(io.opentelemetry.sdk.metrics.data.PointData) Test(org.junit.jupiter.api.Test)

Example 5 with PointData

use of io.opentelemetry.sdk.metrics.data.PointData in project opentelemetry-java by open-telemetry.

the class SdkDoubleCounterTest method stressTest_WithDifferentLabelSet.

@Test
void stressTest_WithDifferentLabelSet() {
    String[] keys = { "Key_1", "Key_2", "Key_3", "Key_4" };
    String[] values = { "Value_1", "Value_2", "Value_3", "Value_4" };
    DoubleCounter doubleCounter = sdkMeter.counterBuilder("testCounter").ofDoubles().build();
    StressTestRunner.Builder stressTestBuilder = StressTestRunner.builder().setInstrument((SdkDoubleCounter) doubleCounter).setCollectionIntervalMs(100);
    for (int i = 0; i < 4; i++) {
        stressTestBuilder.addOperation(StressTestRunner.Operation.create(2_000, 1, new OperationUpdaterDirectCall(doubleCounter, keys[i], values[i])));
        stressTestBuilder.addOperation(StressTestRunner.Operation.create(2_000, 1, new OperationUpdaterWithBinding(((SdkDoubleCounter) doubleCounter).bind(Attributes.builder().put(keys[i], values[i]).build()))));
    }
    stressTestBuilder.build().run();
    assertThat(sdkMeterReader.collectAllMetrics()).satisfiesExactly(metric -> assertThat(metric).hasResource(RESOURCE).hasInstrumentationLibrary(INSTRUMENTATION_LIBRARY_INFO).hasDoubleSum().isCumulative().isMonotonic().points().allSatisfy(point -> assertThat(point).hasStartEpochNanos(testClock.now()).hasEpochNanos(testClock.now()).hasValue(40_000)).extracting(PointData::getAttributes).containsExactlyInAnyOrder(Attributes.of(stringKey(keys[0]), values[0]), Attributes.of(stringKey(keys[1]), values[1]), Attributes.of(stringKey(keys[2]), values[2]), Attributes.of(stringKey(keys[3]), values[3])));
}
Also used : Resource(io.opentelemetry.sdk.resources.Resource) Attributes(io.opentelemetry.api.common.Attributes) BoundDoubleCounter(io.opentelemetry.sdk.metrics.internal.instrument.BoundDoubleCounter) InstrumentationLibraryInfo(io.opentelemetry.sdk.common.InstrumentationLibraryInfo) OperationUpdater(io.opentelemetry.sdk.metrics.StressTestRunner.OperationUpdater) Test(org.junit.jupiter.api.Test) PointData(io.opentelemetry.sdk.metrics.data.PointData) InMemoryMetricReader(io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader) LogCapturer(io.github.netmikey.logunit.api.LogCapturer) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) AttributeKey.stringKey(io.opentelemetry.api.common.AttributeKey.stringKey) DoubleCounter(io.opentelemetry.api.metrics.DoubleCounter) Duration(java.time.Duration) TestClock(io.opentelemetry.sdk.testing.time.TestClock) MetricAssertions.assertThat(io.opentelemetry.sdk.testing.assertj.MetricAssertions.assertThat) Meter(io.opentelemetry.api.metrics.Meter) PointData(io.opentelemetry.sdk.metrics.data.PointData) BoundDoubleCounter(io.opentelemetry.sdk.metrics.internal.instrument.BoundDoubleCounter) DoubleCounter(io.opentelemetry.api.metrics.DoubleCounter) Test(org.junit.jupiter.api.Test)

Aggregations

PointData (io.opentelemetry.sdk.metrics.data.PointData)10 Attributes (io.opentelemetry.api.common.Attributes)7 AttributeKey.stringKey (io.opentelemetry.api.common.AttributeKey.stringKey)6 Meter (io.opentelemetry.api.metrics.Meter)6 InstrumentationLibraryInfo (io.opentelemetry.sdk.common.InstrumentationLibraryInfo)6 OperationUpdater (io.opentelemetry.sdk.metrics.StressTestRunner.OperationUpdater)6 Resource (io.opentelemetry.sdk.resources.Resource)6 MetricAssertions.assertThat (io.opentelemetry.sdk.testing.assertj.MetricAssertions.assertThat)6 InMemoryMetricReader (io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader)6 TestClock (io.opentelemetry.sdk.testing.time.TestClock)6 Duration (java.time.Duration)6 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)6 Test (org.junit.jupiter.api.Test)6 LogCapturer (io.github.netmikey.logunit.api.LogCapturer)4 DoublePointData (io.opentelemetry.sdk.metrics.data.DoublePointData)4 LongPointData (io.opentelemetry.sdk.metrics.data.LongPointData)4 RegisterExtension (org.junit.jupiter.api.extension.RegisterExtension)4 SuppressLogger (io.opentelemetry.internal.testing.slf4j.SuppressLogger)3 HistogramPointData (io.opentelemetry.sdk.metrics.data.HistogramPointData)2 SummaryPointData (io.opentelemetry.sdk.metrics.data.SummaryPointData)2