Search in sources :

Example 11 with DoubleHistogram

use of io.opentelemetry.api.metrics.DoubleHistogram in project opentelemetry-java by open-telemetry.

the class SdkDoubleHistogramTest method collectMetrics_WithEmptyAttributes.

@Test
void collectMetrics_WithEmptyAttributes() {
    DoubleHistogram doubleRecorder = sdkMeter.histogramBuilder("testRecorder").setDescription("description").setUnit("ms").build();
    testClock.advance(Duration.ofNanos(SECOND_NANOS));
    doubleRecorder.record(12d, Attributes.empty());
    doubleRecorder.record(12d);
    assertThat(sdkMeterReader.collectAllMetrics()).satisfiesExactly(metric -> assertThat(metric).hasResource(RESOURCE).hasInstrumentationLibrary(INSTRUMENTATION_LIBRARY_INFO).hasName("testRecorder").hasDescription("description").hasUnit("ms").hasDoubleHistogram().isCumulative().points().satisfiesExactly(point -> assertThat(point).hasStartEpochNanos(testClock.now() - SECOND_NANOS).hasEpochNanos(testClock.now()).hasAttributes(Attributes.empty()).hasCount(2).hasSum(24).hasBucketBoundaries(5, 10, 25, 50, 75, 100, 250, 500, 750, 1_000, 2_500, 5_000, 7_500, 10_000).hasBucketCounts(0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)));
}
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) DoubleHistogram(io.opentelemetry.api.metrics.DoubleHistogram) BoundDoubleHistogram(io.opentelemetry.sdk.metrics.internal.instrument.BoundDoubleHistogram) Test(org.junit.jupiter.api.Test)

Example 12 with DoubleHistogram

use of io.opentelemetry.api.metrics.DoubleHistogram in project opentelemetry-java by open-telemetry.

the class SdkDoubleHistogramTest method stressTest.

@Test
void stressTest() {
    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(1_000, 2, new SdkDoubleHistogramTest.OperationUpdaterDirectCall(doubleRecorder, "K", "V")));
        stressTestBuilder.addOperation(StressTestRunner.Operation.create(1_000, 2, new OperationUpdaterWithBinding(((SdkDoubleHistogram) doubleRecorder).bind(Attributes.builder().put("K", "V").build()))));
    }
    stressTestBuilder.build().run();
    assertThat(sdkMeterReader.collectAllMetrics()).satisfiesExactly(metric -> assertThat(metric).hasResource(RESOURCE).hasInstrumentationLibrary(INSTRUMENTATION_LIBRARY_INFO).hasName("testRecorder").hasDoubleHistogram().points().satisfiesExactly(point -> assertThat(point).hasStartEpochNanos(testClock.now()).hasEpochNanos(testClock.now()).hasAttributes(Attributes.of(stringKey("K"), "V")).hasCount(8_000).hasSum(80_000)));
}
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) DoubleHistogram(io.opentelemetry.api.metrics.DoubleHistogram) BoundDoubleHistogram(io.opentelemetry.sdk.metrics.internal.instrument.BoundDoubleHistogram) Test(org.junit.jupiter.api.Test)

Aggregations

DoubleHistogram (io.opentelemetry.api.metrics.DoubleHistogram)12 Test (org.junit.jupiter.api.Test)12 Meter (io.opentelemetry.api.metrics.Meter)9 InMemoryMetricReader (io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader)8 Attributes (io.opentelemetry.api.common.Attributes)7 SuppressLogger (io.opentelemetry.internal.testing.slf4j.SuppressLogger)7 InstrumentationLibraryInfo (io.opentelemetry.sdk.common.InstrumentationLibraryInfo)7 BoundDoubleHistogram (io.opentelemetry.sdk.metrics.internal.instrument.BoundDoubleHistogram)7 MetricAssertions.assertThat (io.opentelemetry.sdk.testing.assertj.MetricAssertions.assertThat)7 Resource (io.opentelemetry.sdk.resources.Resource)6 TestClock (io.opentelemetry.sdk.testing.time.TestClock)6 Duration (java.time.Duration)6 LogCapturer (io.github.netmikey.logunit.api.LogCapturer)5 AttributeKey.stringKey (io.opentelemetry.api.common.AttributeKey.stringKey)4 DoubleCounter (io.opentelemetry.api.metrics.DoubleCounter)4 DoubleUpDownCounter (io.opentelemetry.api.metrics.DoubleUpDownCounter)4 LongCounter (io.opentelemetry.api.metrics.LongCounter)4 LongHistogram (io.opentelemetry.api.metrics.LongHistogram)4 LongUpDownCounter (io.opentelemetry.api.metrics.LongUpDownCounter)4 OperationUpdater (io.opentelemetry.sdk.metrics.StressTestRunner.OperationUpdater)4