Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Promote exponential histogram data interfaces to stable package #5120

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions docs/apidiffs/current_vs_latest/opentelemetry-sdk-metrics.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -415,7 +416,7 @@ void exponentialHistogramDataPoints() {
assertThat(
toExponentialHistogramDataPoints(
ImmutableList.of(
ExponentialHistogramPointData.create(
ImmutableExponentialHistogramPointData.create(
0,
123.4,
1,
Expand All @@ -427,7 +428,7 @@ void exponentialHistogramDataPoints() {
456,
Attributes.empty(),
Collections.emptyList()),
ExponentialHistogramPointData.create(
ImmutableExponentialHistogramPointData.create(
0,
123.4,
1,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -646,7 +645,7 @@ static Collection<? extends PointData> getPoints(MetricData metricData) {
case HISTOGRAM:
return metricData.getHistogramData().getPoints();
case EXPONENTIAL_HISTOGRAM:
return ExponentialHistogramData.fromMetricData(metricData).getPoints();
return metricData.getExponentialHistogramData().getPoints();
}
return Collections.emptyList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -107,6 +106,6 @@ public ExponentialHistogramAssert hasExponentialHistogram() {
MetricDataType.EXPONENTIAL_HISTOGRAM,
actual.getType());
}
return new ExponentialHistogramAssert(ExponentialHistogramData.fromMetricData(actual));
return new ExponentialHistogramAssert(actual.getExponentialHistogramData());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,7 +33,7 @@ public class MetricAssertionsTest {
/* name= */ "exponential_histogram",
/* description= */ "description",
/* unit= */ "unit",
ExponentialHistogramData.create(
ImmutableExponentialHistogramData.create(
AggregationTemporality.CUMULATIVE,
// Points
Collections.emptyList()));
Expand All @@ -45,7 +45,7 @@ public class MetricAssertionsTest {
/* name= */ "exponential_histogram_delta",
/* description= */ "description",
/* unit= */ "unit",
ExponentialHistogramData.create(
ImmutableExponentialHistogramData.create(
AggregationTemporality.DELTA,
// Points
Collections.emptyList()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,8 +20,7 @@
* <code>offset</code> is -3, the bucket lower bounds would be 0.125, 0.25, 0.5, 1.0, 2,0, etc. If
* <code>offset</code> is +3, the bucket lower bounds would be 8.0, 16.0, 32.0, etc.
*
* <p>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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
*
* <p><i>Note: This is called "ExponentialHistogramData" to reflect which primitives are used to
* record it, however "ExponentialHistogram" is the equivalent OTLP type.</i>
*
* @see <a
* href="https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/data-model.md#exponentialhistogram">Exponential
* Histogram Data Model</a>
* @see ExponentialHistogramPointData
* @since 1.23.0
*/
@Immutable
public interface ExponentialHistogramData extends Data<ExponentialHistogramPointData> {

/**
* Returns the {@code AggregationTemporality} of this metric.
*
* <p>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<ExponentialHistogramPointData> getPoints();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -20,49 +16,14 @@
* <p>The bucket boundaries are calculated using both the scale {@link #getScale()}, and the offset
* {@link ExponentialHistogramBuckets#getOffset()}.
*
* <p>See <a
* href="https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/datamodel.md#exponentialhistogram">data
* model</a>.
*
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change
* at any time.
* @see <a
* href="https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/data-model.md#exponentialhistogram">Exponential
* Histogram Data Model</a>
* @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<DoubleExemplarData> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}
Loading