diff --git a/docs/apidiffs/current_vs_latest/opentelemetry-sdk-metrics.txt b/docs/apidiffs/current_vs_latest/opentelemetry-sdk-metrics.txt index 9fa38661470..b6b2dfb647e 100644 --- a/docs/apidiffs/current_vs_latest/opentelemetry-sdk-metrics.txt +++ b/docs/apidiffs/current_vs_latest/opentelemetry-sdk-metrics.txt @@ -1,4 +1,35 @@ Comparing source compatibility of against ++++ NEW INTERFACE: PUBLIC(+) ABSTRACT(+) io.opentelemetry.sdk.metrics.data.ExponentialHistogramBuckets (not serializable) + +++ CLASS FILE FORMAT VERSION: 52.0 <- n.a. + +++ NEW SUPERCLASS: java.lang.Object + +++ NEW METHOD: PUBLIC(+) ABSTRACT(+) java.util.List getBucketCounts() + +++ NEW METHOD: PUBLIC(+) ABSTRACT(+) int getOffset() + +++ NEW METHOD: PUBLIC(+) ABSTRACT(+) int getScale() + +++ NEW METHOD: PUBLIC(+) ABSTRACT(+) long getTotalCount() ++++ NEW INTERFACE: PUBLIC(+) ABSTRACT(+) io.opentelemetry.sdk.metrics.data.ExponentialHistogramData (not serializable) + +++ CLASS FILE FORMAT VERSION: 52.0 <- n.a. + +++ NEW INTERFACE: io.opentelemetry.sdk.metrics.data.Data + +++ NEW SUPERCLASS: java.lang.Object + +++ NEW METHOD: PUBLIC(+) ABSTRACT(+) io.opentelemetry.sdk.metrics.data.AggregationTemporality getAggregationTemporality() + +++ NEW METHOD: PUBLIC(+) ABSTRACT(+) java.util.Collection getPoints() ++++ NEW INTERFACE: PUBLIC(+) ABSTRACT(+) io.opentelemetry.sdk.metrics.data.ExponentialHistogramPointData (not serializable) + +++ CLASS FILE FORMAT VERSION: 52.0 <- n.a. + +++ NEW INTERFACE: io.opentelemetry.sdk.metrics.data.PointData + +++ NEW SUPERCLASS: java.lang.Object + +++ NEW METHOD: PUBLIC(+) ABSTRACT(+) long getCount() + +++ NEW METHOD: PUBLIC(+) ABSTRACT(+) java.util.List getExemplars() + +++ NEW METHOD: PUBLIC(+) ABSTRACT(+) double getMax() + +++ NEW METHOD: PUBLIC(+) ABSTRACT(+) double getMin() + +++ NEW METHOD: PUBLIC(+) ABSTRACT(+) io.opentelemetry.sdk.metrics.data.ExponentialHistogramBuckets getNegativeBuckets() + +++ NEW METHOD: PUBLIC(+) ABSTRACT(+) io.opentelemetry.sdk.metrics.data.ExponentialHistogramBuckets getPositiveBuckets() + +++ NEW METHOD: PUBLIC(+) ABSTRACT(+) int getScale() + +++ NEW METHOD: PUBLIC(+) ABSTRACT(+) double getSum() + +++ NEW METHOD: PUBLIC(+) ABSTRACT(+) long getZeroCount() + +++ NEW METHOD: PUBLIC(+) ABSTRACT(+) boolean hasMax() + +++ NEW METHOD: PUBLIC(+) ABSTRACT(+) boolean hasMin() +*** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.sdk.metrics.data.MetricData (not serializable) + === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 + +++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.metrics.data.ExponentialHistogramData getExponentialHistogramData() *** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.sdk.metrics.export.MetricReader (not serializable) === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 +++ NEW INTERFACE: java.io.Closeable diff --git a/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/metrics/ExponentialHistogramBucketsMarshaler.java b/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/metrics/ExponentialHistogramBucketsMarshaler.java index be88437d370..54bb047398c 100644 --- a/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/metrics/ExponentialHistogramBucketsMarshaler.java +++ b/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/metrics/ExponentialHistogramBucketsMarshaler.java @@ -10,7 +10,7 @@ import io.opentelemetry.exporter.internal.marshal.Serializer; import io.opentelemetry.proto.metrics.v1.internal.ExponentialHistogramDataPoint; import io.opentelemetry.sdk.internal.PrimitiveLongList; -import io.opentelemetry.sdk.metrics.internal.data.exponentialhistogram.ExponentialHistogramBuckets; +import io.opentelemetry.sdk.metrics.data.ExponentialHistogramBuckets; import java.io.IOException; import java.util.List; diff --git a/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/metrics/ExponentialHistogramDataPointMarshaler.java b/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/metrics/ExponentialHistogramDataPointMarshaler.java index 05f70010f78..e7ac8dcd68b 100644 --- a/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/metrics/ExponentialHistogramDataPointMarshaler.java +++ b/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/metrics/ExponentialHistogramDataPointMarshaler.java @@ -10,7 +10,7 @@ import io.opentelemetry.exporter.internal.marshal.Serializer; import io.opentelemetry.exporter.internal.otlp.KeyValueMarshaler; import io.opentelemetry.proto.metrics.v1.internal.ExponentialHistogramDataPoint; -import io.opentelemetry.sdk.metrics.internal.data.exponentialhistogram.ExponentialHistogramPointData; +import io.opentelemetry.sdk.metrics.data.ExponentialHistogramPointData; import java.io.IOException; import java.util.Collection; diff --git a/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/metrics/ExponentialHistogramMarshaler.java b/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/metrics/ExponentialHistogramMarshaler.java index c07096ee8ae..9ad9b10296a 100644 --- a/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/metrics/ExponentialHistogramMarshaler.java +++ b/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/metrics/ExponentialHistogramMarshaler.java @@ -10,7 +10,7 @@ import io.opentelemetry.exporter.internal.marshal.ProtoEnumInfo; import io.opentelemetry.exporter.internal.marshal.Serializer; import io.opentelemetry.proto.metrics.v1.internal.ExponentialHistogram; -import io.opentelemetry.sdk.metrics.internal.data.exponentialhistogram.ExponentialHistogramData; +import io.opentelemetry.sdk.metrics.data.ExponentialHistogramData; import java.io.IOException; /** diff --git a/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/metrics/MetricMarshaler.java b/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/metrics/MetricMarshaler.java index b09f59c18b3..6b91a407c5f 100644 --- a/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/metrics/MetricMarshaler.java +++ b/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/metrics/MetricMarshaler.java @@ -12,7 +12,6 @@ import io.opentelemetry.exporter.internal.marshal.Serializer; import io.opentelemetry.proto.metrics.v1.internal.Metric; import io.opentelemetry.sdk.metrics.data.MetricData; -import io.opentelemetry.sdk.metrics.internal.data.exponentialhistogram.ExponentialHistogramData; import java.io.IOException; final class MetricMarshaler extends MarshalerWithSize { @@ -57,8 +56,7 @@ static Marshaler create(MetricData metric) { dataField = Metric.HISTOGRAM; break; case EXPONENTIAL_HISTOGRAM: - dataMarshaler = - ExponentialHistogramMarshaler.create(ExponentialHistogramData.fromMetricData(metric)); + dataMarshaler = ExponentialHistogramMarshaler.create(metric.getExponentialHistogramData()); dataField = Metric.EXPONENTIAL_HISTOGRAM; } diff --git a/exporters/otlp/common/src/test/java/io/opentelemetry/exporter/internal/otlp/metrics/MetricsRequestMarshalerTest.java b/exporters/otlp/common/src/test/java/io/opentelemetry/exporter/internal/otlp/metrics/MetricsRequestMarshalerTest.java index a80d2b0f52d..ea02d0c30e8 100644 --- a/exporters/otlp/common/src/test/java/io/opentelemetry/exporter/internal/otlp/metrics/MetricsRequestMarshalerTest.java +++ b/exporters/otlp/common/src/test/java/io/opentelemetry/exporter/internal/otlp/metrics/MetricsRequestMarshalerTest.java @@ -41,12 +41,16 @@ import io.opentelemetry.proto.metrics.v1.SummaryDataPoint; import io.opentelemetry.sdk.common.InstrumentationScopeInfo; import io.opentelemetry.sdk.metrics.data.AggregationTemporality; +import io.opentelemetry.sdk.metrics.data.ExponentialHistogramBuckets; +import io.opentelemetry.sdk.metrics.data.ExponentialHistogramPointData; import io.opentelemetry.sdk.metrics.data.HistogramPointData; import io.opentelemetry.sdk.metrics.data.MetricData; import io.opentelemetry.sdk.metrics.data.PointData; import io.opentelemetry.sdk.metrics.data.SummaryPointData; import io.opentelemetry.sdk.metrics.internal.data.ImmutableDoubleExemplarData; import io.opentelemetry.sdk.metrics.internal.data.ImmutableDoublePointData; +import io.opentelemetry.sdk.metrics.internal.data.ImmutableExponentialHistogramData; +import io.opentelemetry.sdk.metrics.internal.data.ImmutableExponentialHistogramPointData; import io.opentelemetry.sdk.metrics.internal.data.ImmutableGaugeData; import io.opentelemetry.sdk.metrics.internal.data.ImmutableHistogramData; import io.opentelemetry.sdk.metrics.internal.data.ImmutableHistogramPointData; @@ -57,9 +61,6 @@ import io.opentelemetry.sdk.metrics.internal.data.ImmutableSummaryData; import io.opentelemetry.sdk.metrics.internal.data.ImmutableSummaryPointData; import io.opentelemetry.sdk.metrics.internal.data.ImmutableValueAtQuantile; -import io.opentelemetry.sdk.metrics.internal.data.exponentialhistogram.ExponentialHistogramBuckets; -import io.opentelemetry.sdk.metrics.internal.data.exponentialhistogram.ExponentialHistogramData; -import io.opentelemetry.sdk.metrics.internal.data.exponentialhistogram.ExponentialHistogramPointData; import io.opentelemetry.sdk.resources.Resource; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -415,7 +416,7 @@ void exponentialHistogramDataPoints() { assertThat( toExponentialHistogramDataPoints( ImmutableList.of( - ExponentialHistogramPointData.create( + ImmutableExponentialHistogramPointData.create( 0, 123.4, 1, @@ -427,7 +428,7 @@ void exponentialHistogramDataPoints() { 456, Attributes.empty(), Collections.emptyList()), - ExponentialHistogramPointData.create( + ImmutableExponentialHistogramPointData.create( 0, 123.4, 1, @@ -827,10 +828,10 @@ void toProtoMetric_exponentialHistogram() { "name", "description", "1", - ExponentialHistogramData.create( + ImmutableExponentialHistogramData.create( AggregationTemporality.CUMULATIVE, singletonList( - ExponentialHistogramPointData.create( + ImmutableExponentialHistogramPointData.create( 20, 123.4, 257, diff --git a/exporters/prometheus/src/main/java/io/opentelemetry/exporter/prometheus/Serializer.java b/exporters/prometheus/src/main/java/io/opentelemetry/exporter/prometheus/Serializer.java index 165776b4095..5053f9aedbd 100644 --- a/exporters/prometheus/src/main/java/io/opentelemetry/exporter/prometheus/Serializer.java +++ b/exporters/prometheus/src/main/java/io/opentelemetry/exporter/prometheus/Serializer.java @@ -37,7 +37,6 @@ import io.opentelemetry.sdk.metrics.data.PointData; import io.opentelemetry.sdk.metrics.data.SummaryPointData; import io.opentelemetry.sdk.metrics.data.ValueAtQuantile; -import io.opentelemetry.sdk.metrics.internal.data.exponentialhistogram.ExponentialHistogramData; import io.opentelemetry.sdk.resources.Resource; import java.io.BufferedWriter; import java.io.IOException; @@ -646,7 +645,7 @@ static Collection getPoints(MetricData metricData) { case HISTOGRAM: return metricData.getHistogramData().getPoints(); case EXPONENTIAL_HISTOGRAM: - return ExponentialHistogramData.fromMetricData(metricData).getPoints(); + return metricData.getExponentialHistogramData().getPoints(); } return Collections.emptyList(); } diff --git a/sdk/metrics-testing/src/main/java/io/opentelemetry/sdk/testing/assertj/ExponentialHistogramAssert.java b/sdk/metrics-testing/src/main/java/io/opentelemetry/sdk/testing/assertj/ExponentialHistogramAssert.java index 268fc672bef..9c5009a5674 100644 --- a/sdk/metrics-testing/src/main/java/io/opentelemetry/sdk/testing/assertj/ExponentialHistogramAssert.java +++ b/sdk/metrics-testing/src/main/java/io/opentelemetry/sdk/testing/assertj/ExponentialHistogramAssert.java @@ -6,8 +6,8 @@ package io.opentelemetry.sdk.testing.assertj; import io.opentelemetry.sdk.metrics.data.AggregationTemporality; -import io.opentelemetry.sdk.metrics.internal.data.exponentialhistogram.ExponentialHistogramData; -import io.opentelemetry.sdk.metrics.internal.data.exponentialhistogram.ExponentialHistogramPointData; +import io.opentelemetry.sdk.metrics.data.ExponentialHistogramData; +import io.opentelemetry.sdk.metrics.data.ExponentialHistogramPointData; import org.assertj.core.api.AbstractAssert; import org.assertj.core.api.AbstractIterableAssert; import org.assertj.core.api.Assertions; diff --git a/sdk/metrics-testing/src/main/java/io/opentelemetry/sdk/testing/assertj/ExponentialHistogramBucketsAssert.java b/sdk/metrics-testing/src/main/java/io/opentelemetry/sdk/testing/assertj/ExponentialHistogramBucketsAssert.java index 28b0e345499..c78438fff64 100644 --- a/sdk/metrics-testing/src/main/java/io/opentelemetry/sdk/testing/assertj/ExponentialHistogramBucketsAssert.java +++ b/sdk/metrics-testing/src/main/java/io/opentelemetry/sdk/testing/assertj/ExponentialHistogramBucketsAssert.java @@ -5,7 +5,7 @@ package io.opentelemetry.sdk.testing.assertj; -import io.opentelemetry.sdk.metrics.internal.data.exponentialhistogram.ExponentialHistogramBuckets; +import io.opentelemetry.sdk.metrics.data.ExponentialHistogramBuckets; import java.util.List; import org.assertj.core.api.AbstractAssert; import org.assertj.core.api.Assertions; diff --git a/sdk/metrics-testing/src/main/java/io/opentelemetry/sdk/testing/assertj/ExponentialHistogramPointDataAssert.java b/sdk/metrics-testing/src/main/java/io/opentelemetry/sdk/testing/assertj/ExponentialHistogramPointDataAssert.java index cd5680b5c5a..5dc4e42754e 100644 --- a/sdk/metrics-testing/src/main/java/io/opentelemetry/sdk/testing/assertj/ExponentialHistogramPointDataAssert.java +++ b/sdk/metrics-testing/src/main/java/io/opentelemetry/sdk/testing/assertj/ExponentialHistogramPointDataAssert.java @@ -5,7 +5,7 @@ package io.opentelemetry.sdk.testing.assertj; -import io.opentelemetry.sdk.metrics.internal.data.exponentialhistogram.ExponentialHistogramPointData; +import io.opentelemetry.sdk.metrics.data.ExponentialHistogramPointData; import org.assertj.core.api.Assertions; /** Test assertions for {@link ExponentialHistogramPointData}. */ diff --git a/sdk/metrics-testing/src/main/java/io/opentelemetry/sdk/testing/assertj/MetricAssertions.java b/sdk/metrics-testing/src/main/java/io/opentelemetry/sdk/testing/assertj/MetricAssertions.java index b096f8ef640..9cd30280583 100644 --- a/sdk/metrics-testing/src/main/java/io/opentelemetry/sdk/testing/assertj/MetricAssertions.java +++ b/sdk/metrics-testing/src/main/java/io/opentelemetry/sdk/testing/assertj/MetricAssertions.java @@ -6,9 +6,9 @@ package io.opentelemetry.sdk.testing.assertj; import io.opentelemetry.sdk.metrics.data.ExemplarData; +import io.opentelemetry.sdk.metrics.data.ExponentialHistogramBuckets; +import io.opentelemetry.sdk.metrics.data.ExponentialHistogramPointData; import io.opentelemetry.sdk.metrics.data.MetricData; -import io.opentelemetry.sdk.metrics.internal.data.exponentialhistogram.ExponentialHistogramBuckets; -import io.opentelemetry.sdk.metrics.internal.data.exponentialhistogram.ExponentialHistogramPointData; import org.assertj.core.api.Assertions; /** Test assertions for data heading to exporters within the Metrics SDK. */ diff --git a/sdk/metrics-testing/src/main/java/io/opentelemetry/sdk/testing/assertj/MetricDataAssert.java b/sdk/metrics-testing/src/main/java/io/opentelemetry/sdk/testing/assertj/MetricDataAssert.java index d4e57b4c5a9..6c088c99a0d 100644 --- a/sdk/metrics-testing/src/main/java/io/opentelemetry/sdk/testing/assertj/MetricDataAssert.java +++ b/sdk/metrics-testing/src/main/java/io/opentelemetry/sdk/testing/assertj/MetricDataAssert.java @@ -8,7 +8,6 @@ import io.opentelemetry.sdk.common.InstrumentationScopeInfo; import io.opentelemetry.sdk.metrics.data.MetricData; import io.opentelemetry.sdk.metrics.data.MetricDataType; -import io.opentelemetry.sdk.metrics.internal.data.exponentialhistogram.ExponentialHistogramData; import io.opentelemetry.sdk.resources.Resource; import org.assertj.core.api.AbstractAssert; @@ -107,6 +106,6 @@ public ExponentialHistogramAssert hasExponentialHistogram() { MetricDataType.EXPONENTIAL_HISTOGRAM, actual.getType()); } - return new ExponentialHistogramAssert(ExponentialHistogramData.fromMetricData(actual)); + return new ExponentialHistogramAssert(actual.getExponentialHistogramData()); } } diff --git a/sdk/metrics-testing/src/test/java/io/opentelemetry/sdk/testing/assertj/MetricAssertionsTest.java b/sdk/metrics-testing/src/test/java/io/opentelemetry/sdk/testing/assertj/MetricAssertionsTest.java index 2cf03935f71..ba76008a11b 100644 --- a/sdk/metrics-testing/src/test/java/io/opentelemetry/sdk/testing/assertj/MetricAssertionsTest.java +++ b/sdk/metrics-testing/src/test/java/io/opentelemetry/sdk/testing/assertj/MetricAssertionsTest.java @@ -13,9 +13,9 @@ import io.opentelemetry.sdk.common.InstrumentationScopeInfo; import io.opentelemetry.sdk.metrics.data.AggregationTemporality; import io.opentelemetry.sdk.metrics.data.MetricData; +import io.opentelemetry.sdk.metrics.internal.data.ImmutableExponentialHistogramData; import io.opentelemetry.sdk.metrics.internal.data.ImmutableGaugeData; import io.opentelemetry.sdk.metrics.internal.data.ImmutableMetricData; -import io.opentelemetry.sdk.metrics.internal.data.exponentialhistogram.ExponentialHistogramData; import io.opentelemetry.sdk.resources.Resource; import java.util.Collections; import org.junit.jupiter.api.Test; @@ -33,7 +33,7 @@ public class MetricAssertionsTest { /* name= */ "exponential_histogram", /* description= */ "description", /* unit= */ "unit", - ExponentialHistogramData.create( + ImmutableExponentialHistogramData.create( AggregationTemporality.CUMULATIVE, // Points Collections.emptyList())); @@ -45,7 +45,7 @@ public class MetricAssertionsTest { /* name= */ "exponential_histogram_delta", /* description= */ "description", /* unit= */ "unit", - ExponentialHistogramData.create( + ImmutableExponentialHistogramData.create( AggregationTemporality.DELTA, // Points Collections.emptyList())); diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/data/exponentialhistogram/ExponentialHistogramBuckets.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/ExponentialHistogramBuckets.java similarity index 89% rename from sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/data/exponentialhistogram/ExponentialHistogramBuckets.java rename to sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/ExponentialHistogramBuckets.java index 556ea311ca1..71ad13f899f 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/data/exponentialhistogram/ExponentialHistogramBuckets.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/ExponentialHistogramBuckets.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.sdk.metrics.internal.data.exponentialhistogram; +package io.opentelemetry.sdk.metrics.data; import java.util.List; import javax.annotation.concurrent.Immutable; @@ -20,8 +20,7 @@ * offset is -3, the bucket lower bounds would be 0.125, 0.25, 0.5, 1.0, 2,0, etc. If * offset is +3, the bucket lower bounds would be 8.0, 16.0, 32.0, etc. * - *

This class is internal and is hence not for public use. Its APIs are unstable and can change - * at any time. + * @since 1.23.0 */ @Immutable public interface ExponentialHistogramBuckets { diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/ExponentialHistogramData.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/ExponentialHistogramData.java new file mode 100644 index 00000000000..68db6f5c6e5 --- /dev/null +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/ExponentialHistogramData.java @@ -0,0 +1,44 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.sdk.metrics.data; + +import java.util.Collection; +import javax.annotation.concurrent.Immutable; + +/** + * A base-2 exponential histogram metric point, as defined by the OpenTelemetry Exponential + * Histogram specification. + * + *

Note: This is called "ExponentialHistogramData" to reflect which primitives are used to + * record it, however "ExponentialHistogram" is the equivalent OTLP type. + * + * @see Exponential + * Histogram Data Model + * @see ExponentialHistogramPointData + * @since 1.23.0 + */ +@Immutable +public interface ExponentialHistogramData extends Data { + + /** + * Returns the {@code AggregationTemporality} of this metric. + * + *

AggregationTemporality describes if the aggregator reports delta changes since last report + * time, or cumulative changes since a fixed start time. + * + * @return the {@code AggregationTemporality} of this metric + */ + AggregationTemporality getAggregationTemporality(); + + /** + * Returns the collection of {@link ExponentialHistogramPointData} for this histogram. + * + * @return the collection of data points for this histogram. + */ + @Override + Collection getPoints(); +} diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/data/exponentialhistogram/ExponentialHistogramPointData.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/ExponentialHistogramPointData.java similarity index 67% rename from sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/data/exponentialhistogram/ExponentialHistogramPointData.java rename to sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/ExponentialHistogramPointData.java index 808ca97d70c..841c2bc62e2 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/data/exponentialhistogram/ExponentialHistogramPointData.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/ExponentialHistogramPointData.java @@ -3,13 +3,9 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.sdk.metrics.internal.data.exponentialhistogram; +package io.opentelemetry.sdk.metrics.data; -import io.opentelemetry.api.common.Attributes; -import io.opentelemetry.sdk.metrics.data.DoubleExemplarData; -import io.opentelemetry.sdk.metrics.data.PointData; import java.util.List; -import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; /** @@ -20,49 +16,14 @@ *

The bucket boundaries are calculated using both the scale {@link #getScale()}, and the offset * {@link ExponentialHistogramBuckets#getOffset()}. * - *

See data - * model. - * - *

This class is internal and is hence not for public use. Its APIs are unstable and can change - * at any time. + * @see Exponential + * Histogram Data Model + * @since 1.23.0 */ @Immutable public interface ExponentialHistogramPointData extends PointData { - /** - * Create an ExponentialHistogramPointData. - * - * @return an ExponentialHistogramPointData. - */ - @SuppressWarnings("TooManyParameters") - static ExponentialHistogramPointData create( - int scale, - double sum, - long zeroCount, - @Nullable Double min, - @Nullable Double max, - ExponentialHistogramBuckets positiveBuckets, - ExponentialHistogramBuckets negativeBuckets, - long startEpochNanos, - long epochNanos, - Attributes attributes, - List exemplars) { - - return ImmutableExponentialHistogramPointData.create( - scale, - sum, - zeroCount, - min, - max, - positiveBuckets, - negativeBuckets, - startEpochNanos, - epochNanos, - attributes, - exemplars); - } - /** * Scale characterises the resolution of the histogram, with larger values of scale offering * greater precision. Bucket boundaries of the histogram are located at integer powers of the diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/MetricData.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/MetricData.java index 060daa2cd32..f30b7ccbb84 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/MetricData.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/MetricData.java @@ -10,6 +10,7 @@ import io.opentelemetry.sdk.common.InstrumentationScopeInfo; import io.opentelemetry.sdk.metrics.SdkMeterProviderBuilder; import io.opentelemetry.sdk.metrics.View; +import io.opentelemetry.sdk.metrics.internal.data.ImmutableExponentialHistogramData; import io.opentelemetry.sdk.metrics.internal.data.ImmutableGaugeData; import io.opentelemetry.sdk.metrics.internal.data.ImmutableHistogramData; import io.opentelemetry.sdk.metrics.internal.data.ImmutableSumData; @@ -159,4 +160,15 @@ default HistogramData getHistogramData() { } return ImmutableHistogramData.empty(); } + + /** + * Returns the {@link ExponentialHistogramData} if type is {@link + * MetricDataType#EXPONENTIAL_HISTOGRAM}, otherwise a default empty data. + */ + default ExponentialHistogramData getExponentialHistogramData() { + if (getType() == MetricDataType.EXPONENTIAL_HISTOGRAM) { + return (ExponentialHistogramData) getData(); + } + return ImmutableExponentialHistogramData.empty(); + } } diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/aggregator/DoubleExponentialHistogramAggregator.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/aggregator/DoubleExponentialHistogramAggregator.java index 15afebc439a..38242b8bab9 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/aggregator/DoubleExponentialHistogramAggregator.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/aggregator/DoubleExponentialHistogramAggregator.java @@ -10,10 +10,10 @@ import io.opentelemetry.sdk.common.InstrumentationScopeInfo; import io.opentelemetry.sdk.metrics.data.AggregationTemporality; import io.opentelemetry.sdk.metrics.data.DoubleExemplarData; +import io.opentelemetry.sdk.metrics.data.ExponentialHistogramBuckets; import io.opentelemetry.sdk.metrics.data.MetricData; +import io.opentelemetry.sdk.metrics.internal.data.ImmutableExponentialHistogramData; import io.opentelemetry.sdk.metrics.internal.data.ImmutableMetricData; -import io.opentelemetry.sdk.metrics.internal.data.exponentialhistogram.ExponentialHistogramBuckets; -import io.opentelemetry.sdk.metrics.internal.data.exponentialhistogram.ExponentialHistogramData; import io.opentelemetry.sdk.metrics.internal.descriptor.MetricDescriptor; import io.opentelemetry.sdk.metrics.internal.exemplar.ExemplarReservoir; import io.opentelemetry.sdk.resources.Resource; @@ -165,7 +165,7 @@ public MetricData toMetricData( metricDescriptor.getName(), metricDescriptor.getDescription(), metricDescriptor.getSourceInstrument().getUnit(), - ExponentialHistogramData.create( + ImmutableExponentialHistogramData.create( temporality, MetricDataUtils.toExponentialHistogramPointList( accumulationByLabels, diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/aggregator/DoubleExponentialHistogramBuckets.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/aggregator/DoubleExponentialHistogramBuckets.java index 09dc75903cc..770d08b9538 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/aggregator/DoubleExponentialHistogramBuckets.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/aggregator/DoubleExponentialHistogramBuckets.java @@ -6,7 +6,7 @@ package io.opentelemetry.sdk.metrics.internal.aggregator; import io.opentelemetry.sdk.internal.PrimitiveLongList; -import io.opentelemetry.sdk.metrics.internal.data.exponentialhistogram.ExponentialHistogramBuckets; +import io.opentelemetry.sdk.metrics.data.ExponentialHistogramBuckets; import java.util.Collections; import java.util.List; import javax.annotation.Nullable; diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/aggregator/ExponentialHistogramAccumulation.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/aggregator/ExponentialHistogramAccumulation.java index 86c328bef82..bac2ef1476b 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/aggregator/ExponentialHistogramAccumulation.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/aggregator/ExponentialHistogramAccumulation.java @@ -7,7 +7,7 @@ import com.google.auto.value.AutoValue; import io.opentelemetry.sdk.metrics.data.DoubleExemplarData; -import io.opentelemetry.sdk.metrics.internal.data.exponentialhistogram.ExponentialHistogramBuckets; +import io.opentelemetry.sdk.metrics.data.ExponentialHistogramBuckets; import java.util.List; @AutoValue diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/aggregator/MetricDataUtils.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/aggregator/MetricDataUtils.java index 39968fc7b24..57aa7879a41 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/aggregator/MetricDataUtils.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/aggregator/MetricDataUtils.java @@ -9,12 +9,13 @@ import io.opentelemetry.sdk.internal.PrimitiveLongList; import io.opentelemetry.sdk.metrics.InstrumentType; import io.opentelemetry.sdk.metrics.data.DoublePointData; +import io.opentelemetry.sdk.metrics.data.ExponentialHistogramPointData; import io.opentelemetry.sdk.metrics.data.HistogramPointData; import io.opentelemetry.sdk.metrics.data.LongPointData; import io.opentelemetry.sdk.metrics.internal.data.ImmutableDoublePointData; +import io.opentelemetry.sdk.metrics.internal.data.ImmutableExponentialHistogramPointData; import io.opentelemetry.sdk.metrics.internal.data.ImmutableHistogramPointData; import io.opentelemetry.sdk.metrics.internal.data.ImmutableLongPointData; -import io.opentelemetry.sdk.metrics.internal.data.exponentialhistogram.ExponentialHistogramPointData; import io.opentelemetry.sdk.metrics.internal.descriptor.InstrumentDescriptor; import java.util.ArrayList; import java.util.List; @@ -93,7 +94,7 @@ static List toExponentialHistogramPointList( accumulationMap.forEach( (attributes, aggregator) -> points.add( - ExponentialHistogramPointData.create( + ImmutableExponentialHistogramPointData.create( aggregator.getScale(), aggregator.getSum(), aggregator.getZeroCount(), diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/data/exponentialhistogram/ImmutableExponentialHistogramData.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/data/ImmutableExponentialHistogramData.java similarity index 59% rename from sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/data/exponentialhistogram/ImmutableExponentialHistogramData.java rename to sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/data/ImmutableExponentialHistogramData.java index 08264d22f9b..6690c207dc5 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/data/exponentialhistogram/ImmutableExponentialHistogramData.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/data/ImmutableExponentialHistogramData.java @@ -3,28 +3,28 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.sdk.metrics.internal.data.exponentialhistogram; +package io.opentelemetry.sdk.metrics.internal.data; import com.google.auto.value.AutoValue; import io.opentelemetry.sdk.metrics.data.AggregationTemporality; +import io.opentelemetry.sdk.metrics.data.ExponentialHistogramData; +import io.opentelemetry.sdk.metrics.data.ExponentialHistogramPointData; import java.util.Collection; import java.util.Collections; +import javax.annotation.concurrent.Immutable; /** - * A simple, autovalue implementation of {@link ExponentialHistogramData}. For more detailed javadoc - * on the type, see {@link ExponentialHistogramData}. - * - *

See: - * https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/datamodel.md#exponentialhistogram + * Auto value implementation of {@link ExponentialHistogramData}. * *

This class is internal and is hence not for public use. Its APIs are unstable and can change * at any time. */ +@Immutable @AutoValue public abstract class ImmutableExponentialHistogramData implements ExponentialHistogramData { private static final ExponentialHistogramData EMPTY = - ExponentialHistogramData.create(AggregationTemporality.CUMULATIVE, Collections.emptyList()); + create(AggregationTemporality.CUMULATIVE, Collections.emptyList()); public static ExponentialHistogramData empty() { return EMPTY; @@ -37,10 +37,4 @@ public static ExponentialHistogramData create( } ImmutableExponentialHistogramData() {} - - @Override - public abstract AggregationTemporality getAggregationTemporality(); - - @Override - public abstract Collection getPoints(); } diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/data/exponentialhistogram/ImmutableExponentialHistogramPointData.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/data/ImmutableExponentialHistogramPointData.java similarity index 75% rename from sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/data/exponentialhistogram/ImmutableExponentialHistogramPointData.java rename to sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/data/ImmutableExponentialHistogramPointData.java index 1026410ccea..5aa8c46567a 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/data/exponentialhistogram/ImmutableExponentialHistogramPointData.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/data/ImmutableExponentialHistogramPointData.java @@ -3,25 +3,27 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.sdk.metrics.internal.data.exponentialhistogram; +package io.opentelemetry.sdk.metrics.internal.data; import com.google.auto.value.AutoValue; import io.opentelemetry.api.common.Attributes; import io.opentelemetry.sdk.metrics.data.DoubleExemplarData; +import io.opentelemetry.sdk.metrics.data.ExponentialHistogramBuckets; +import io.opentelemetry.sdk.metrics.data.ExponentialHistogramPointData; import java.util.List; import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; /** - * Simple auto value implementation of {@link ExponentialHistogramPointData}. For detailed javadoc - * on the type, see {@link ExponentialHistogramPointData}. + * Auto value implementation of {@link ExponentialHistogramPointData}. * *

This class is internal and is hence not for public use. Its APIs are unstable and can change * at any time. */ @AutoValue @Immutable -abstract class ImmutableExponentialHistogramPointData implements ExponentialHistogramPointData { +public abstract class ImmutableExponentialHistogramPointData + implements ExponentialHistogramPointData { ImmutableExponentialHistogramPointData() {} @@ -30,7 +32,8 @@ abstract class ImmutableExponentialHistogramPointData implements ExponentialHist * * @return a DoubleExponentialHistogramPointData. */ - static ImmutableExponentialHistogramPointData create( + @SuppressWarnings("TooManyParameters") + public static ImmutableExponentialHistogramPointData create( int scale, double sum, long zeroCount, diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/data/ImmutableMetricData.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/data/ImmutableMetricData.java index 070673180ce..037aba8867e 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/data/ImmutableMetricData.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/data/ImmutableMetricData.java @@ -9,6 +9,7 @@ import io.opentelemetry.sdk.common.InstrumentationScopeInfo; import io.opentelemetry.sdk.metrics.data.Data; import io.opentelemetry.sdk.metrics.data.DoublePointData; +import io.opentelemetry.sdk.metrics.data.ExponentialHistogramData; import io.opentelemetry.sdk.metrics.data.GaugeData; import io.opentelemetry.sdk.metrics.data.HistogramData; import io.opentelemetry.sdk.metrics.data.LongPointData; @@ -16,7 +17,6 @@ import io.opentelemetry.sdk.metrics.data.MetricDataType; import io.opentelemetry.sdk.metrics.data.SumData; import io.opentelemetry.sdk.metrics.data.SummaryData; -import io.opentelemetry.sdk.metrics.internal.data.exponentialhistogram.ExponentialHistogramData; import io.opentelemetry.sdk.resources.Resource; import javax.annotation.concurrent.Immutable; diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/data/exponentialhistogram/ExponentialHistogramData.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/data/exponentialhistogram/ExponentialHistogramData.java deleted file mode 100644 index 2cc0ff2826f..00000000000 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/data/exponentialhistogram/ExponentialHistogramData.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.sdk.metrics.internal.data.exponentialhistogram; - -import io.opentelemetry.sdk.metrics.data.AggregationTemporality; -import io.opentelemetry.sdk.metrics.data.Data; -import io.opentelemetry.sdk.metrics.data.MetricData; -import io.opentelemetry.sdk.metrics.data.MetricDataType; -import java.util.Collection; -import javax.annotation.concurrent.Immutable; - -/** - * A base-2 exponential histogram metric point, as defined by the OpenTelemetry Exponential - * Histogram specification. - * - *

See {@link ExponentialHistogramPointData} for more information. - * - *

See: - * https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/datamodel.md#exponentialhistogram - * - *

Note: This is called "ExponentialHistogramData" to reflect which primitives are used to - * record it, however "ExponentialHistogram" is the equivalent OTLP type. - * - *

This class is internal and is hence not for public use. Its APIs are unstable and can change - * at any time. - */ -@Immutable -public interface ExponentialHistogramData extends Data { - - /** - * Create a DoubleExponentialHistogramData. - * - * @return a DoubleExponentialHistogramData - */ - static ExponentialHistogramData create( - AggregationTemporality temporality, Collection points) { - return ImmutableExponentialHistogramData.create(temporality, points); - } - - /** - * Returns the {@link ExponentialHistogramData} if type is {@link - * MetricDataType#EXPONENTIAL_HISTOGRAM}, otherwise a default empty data. - * - * @return the {@link ExponentialHistogramData} if type is {@link - * MetricDataType#EXPONENTIAL_HISTOGRAM}, otherwise a default empty data. - */ - static ExponentialHistogramData fromMetricData(MetricData data) { - if (data.getType() == MetricDataType.EXPONENTIAL_HISTOGRAM) { - return (ExponentialHistogramData) data.getData(); - } - return ImmutableExponentialHistogramData.empty(); - } - - /** - * Returns the {@code AggregationTemporality} of this metric. - * - *

AggregationTemporality describes if the aggregator reports delta changes since last report - * time, or cumulative changes since a fixed start time. - * - * @return the {@code AggregationTemporality} of this metric - */ - AggregationTemporality getAggregationTemporality(); - - /** - * Returns the collection of {@link ExponentialHistogramPointData} for this histogram. - * - * @return the collection of data points for this histogram. - */ - @Override - Collection getPoints(); -} diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/data/exponentialhistogram/package-info.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/data/exponentialhistogram/package-info.java deleted file mode 100644 index fe1f2bd69b0..00000000000 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/data/exponentialhistogram/package-info.java +++ /dev/null @@ -1,10 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -/** The data format to model exponential histograms for export. */ -@ParametersAreNonnullByDefault -package io.opentelemetry.sdk.metrics.internal.data.exponentialhistogram; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/internal/aggregator/DoubleExponentialHistogramAggregatorTest.java b/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/internal/aggregator/DoubleExponentialHistogramAggregatorTest.java index 713fda8a93a..0398e831d71 100644 --- a/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/internal/aggregator/DoubleExponentialHistogramAggregatorTest.java +++ b/sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/internal/aggregator/DoubleExponentialHistogramAggregatorTest.java @@ -16,10 +16,10 @@ import io.opentelemetry.sdk.common.InstrumentationScopeInfo; import io.opentelemetry.sdk.metrics.data.AggregationTemporality; import io.opentelemetry.sdk.metrics.data.DoubleExemplarData; +import io.opentelemetry.sdk.metrics.data.ExponentialHistogramBuckets; import io.opentelemetry.sdk.metrics.data.MetricData; +import io.opentelemetry.sdk.metrics.data.MetricDataType; import io.opentelemetry.sdk.metrics.internal.data.ImmutableDoubleExemplarData; -import io.opentelemetry.sdk.metrics.internal.data.exponentialhistogram.ExponentialHistogramBuckets; -import io.opentelemetry.sdk.metrics.internal.data.exponentialhistogram.ExponentialHistogramData; import io.opentelemetry.sdk.metrics.internal.descriptor.MetricDescriptor; import io.opentelemetry.sdk.metrics.internal.exemplar.ExemplarReservoir; import io.opentelemetry.sdk.resources.Resource; @@ -496,7 +496,8 @@ void testToMetricData() { 0, 10, 100); - assertThat(ExponentialHistogramData.fromMetricData(metricDataDelta).getAggregationTemporality()) + assertThat(metricDataDelta.getType()).isEqualTo(MetricDataType.EXPONENTIAL_HISTOGRAM); + assertThat(metricDataDelta.getExponentialHistogramData().getAggregationTemporality()) .isEqualTo(AggregationTemporality.DELTA); }