From 230f116282d3d118ec2db74d3e9ccf6df1fbeeea Mon Sep 17 00:00:00 2001 From: James Moessis Date: Mon, 20 Sep 2021 12:10:48 +1000 Subject: [PATCH 01/12] Data classes for exponential histogram prototype (#3550) --- .../DoubleExponentialHistogramBuckets.java | 45 +++++++++ .../data/DoubleExponentialHistogramData.java | 44 +++++++++ .../DoubleExponentialHistogramPointData.java | 91 +++++++++++++++++++ 3 files changed, 180 insertions(+) create mode 100644 sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleExponentialHistogramBuckets.java create mode 100644 sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleExponentialHistogramData.java create mode 100644 sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleExponentialHistogramPointData.java diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleExponentialHistogramBuckets.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleExponentialHistogramBuckets.java new file mode 100644 index 00000000000..118f2581e11 --- /dev/null +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleExponentialHistogramBuckets.java @@ -0,0 +1,45 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.sdk.metrics.data; + +import com.google.auto.value.AutoValue; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import javax.annotation.concurrent.Immutable; + +/** + * DoubleExponentialHistogramBuckets represents either the positive or negative measurements taken + * for a {@link DoubleExponentialHistogramPointData}. + */ +@AutoValue +@Immutable +public abstract class DoubleExponentialHistogramBuckets { + DoubleExponentialHistogramBuckets() {} + + /** + * Create DoubleExponentialHistogramBuckets. + * + * @param offset Signed integer representing the bucket index of the first entry in bucketCounts. + * @param bucketCounts List of counts representing number of measurements that fall into each + * bucket. + * @return a DoubleExponentialHistogramBuckets. + */ + public DoubleExponentialHistogramBuckets create(int offset, List bucketCounts) { + long totalCount = 0; + for (long count : bucketCounts) { + totalCount += count; + } + return new AutoValue_DoubleExponentialHistogramBuckets( + offset, Collections.unmodifiableList(new ArrayList<>(bucketCounts)), totalCount); + } + + public abstract int getOffset(); + + public abstract List getBucketCounts(); + + public abstract long getTotalCount(); +} diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleExponentialHistogramData.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleExponentialHistogramData.java new file mode 100644 index 00000000000..7f9b2ce6be8 --- /dev/null +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleExponentialHistogramData.java @@ -0,0 +1,44 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.sdk.metrics.data; + +import com.google.auto.value.AutoValue; +import java.util.Collection; +import javax.annotation.concurrent.Immutable; + +/** + * An exponential histogram metric point, as defined by the OpenTelemetry Exponential Histogram. + * + *

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

Note: This is called "DoubleExponentialHistogramData" to reflect which primitives are used + * to record it, however "ExponentialHistogram" is the equivalent OTLP type. + */ +@Immutable +@AutoValue +public abstract class DoubleExponentialHistogramData + implements Data { + DoubleExponentialHistogramData() {} + + public static DoubleExponentialHistogramData create( + AggregationTemporality temporality, Collection points) { + return new AutoValue_DoubleExponentialHistogramData(temporality, points); + } + + /** + * 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 + */ + public abstract AggregationTemporality getAggregationTemporality(); + + @Override + public abstract Collection getPoints(); +} diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleExponentialHistogramPointData.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleExponentialHistogramPointData.java new file mode 100644 index 00000000000..681096eecac --- /dev/null +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleExponentialHistogramPointData.java @@ -0,0 +1,91 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.sdk.metrics.data; + +import com.google.auto.value.AutoValue; +import io.opentelemetry.api.common.Attributes; +import java.util.List; +import javax.annotation.concurrent.Immutable; + +/** + * DoubleExponentialHistogramPointData represents an approximate distribution of measurements across + * exponentially increasing bucket boundaries, taken for a {@link DoubleExponentialHistogramData}. + * It also contains the necessary information to calculate bucket boundaries and perform + * aggregation. + * + *

The bucket boundaries increase exponentially according to the scale and the offset. See: + * https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/datamodel.md#exponentialhistogram + */ +@Immutable +@AutoValue +public abstract class DoubleExponentialHistogramPointData implements PointData { + + DoubleExponentialHistogramPointData() {} + + /** + * Creates a DoubleExponentialHistogramPointData. + * + * @param scale Scale is used to calculate bucket boundaries as outlined in the OTLP. + * @param sum The sum of all measurements in the histogram. + * @param zeroCount Number of values that are zero. + * @param positiveBuckets Buckets with positive values. + * @param negativeBuckets Buckets with negative values. + * @return a DoubleExponentialHistogramPointData + */ + public static DoubleExponentialHistogramPointData create( + long startEpochNanos, + long epochNanos, + Attributes attributes, + int scale, + double sum, + long zeroCount, + DoubleExponentialHistogramBuckets positiveBuckets, + DoubleExponentialHistogramBuckets negativeBuckets, + List exemplars) { + + long count = zeroCount + positiveBuckets.getTotalCount() + negativeBuckets.getTotalCount(); + double base = Math.pow(2, Math.pow(2, -scale)); + + return new AutoValue_DoubleExponentialHistogramPointData( + startEpochNanos, + epochNanos, + attributes, + scale, + sum, + count, + base, + zeroCount, + positiveBuckets, + negativeBuckets, + exemplars); + } + + @Override + public abstract long getStartEpochNanos(); + + @Override + public abstract long getEpochNanos(); + + @Override + public abstract Attributes getAttributes(); + + public abstract int getScale(); + + public abstract double getSum(); + + public abstract long getCount(); + + public abstract double getBase(); + + public abstract long getZeroCount(); + + public abstract DoubleExponentialHistogramBuckets getPositiveBuckets(); + + public abstract DoubleExponentialHistogramBuckets getNegativeBuckets(); + + @Override + public abstract List getExemplars(); +} From 0cf7ff4955ffb4a440c26f7b47e1bb7ac0dbfa39 Mon Sep 17 00:00:00 2001 From: James Moessis Date: Tue, 21 Sep 2021 12:16:53 +1000 Subject: [PATCH 02/12] add javadoc to DoubleExponentialHistogramData.create() --- .../sdk/metrics/data/DoubleExponentialHistogramData.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleExponentialHistogramData.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleExponentialHistogramData.java index 7f9b2ce6be8..dbdad68e689 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleExponentialHistogramData.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleExponentialHistogramData.java @@ -24,6 +24,13 @@ public abstract class DoubleExponentialHistogramData implements Data { DoubleExponentialHistogramData() {} + /** + * Creates a DoubleExponentialHistogramData. + * + * @param temporality The {@link AggregationTemporality} + * @param points A collection of {@link DoubleExponentialHistogramPointData} to hold measurements + * @return + */ public static DoubleExponentialHistogramData create( AggregationTemporality temporality, Collection points) { return new AutoValue_DoubleExponentialHistogramData(temporality, points); From 9105a6382f2a2f49d3c51b02073f542282fbb522 Mon Sep 17 00:00:00 2001 From: James Moessis Date: Tue, 21 Sep 2021 13:44:18 +1000 Subject: [PATCH 03/12] appease linter --- .../sdk/metrics/data/DoubleExponentialHistogramData.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleExponentialHistogramData.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleExponentialHistogramData.java index dbdad68e689..bf110b6043c 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleExponentialHistogramData.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleExponentialHistogramData.java @@ -29,7 +29,7 @@ public abstract class DoubleExponentialHistogramData * * @param temporality The {@link AggregationTemporality} * @param points A collection of {@link DoubleExponentialHistogramPointData} to hold measurements - * @return + * @return a DoubleExponentialHistogramData */ public static DoubleExponentialHistogramData create( AggregationTemporality temporality, Collection points) { From 09ca9b540a21691b2e7e5945669308b3dec6544b Mon Sep 17 00:00:00 2001 From: James Moessis Date: Wed, 22 Sep 2021 15:52:52 +1000 Subject: [PATCH 04/12] more javadoc for exponential histogram --- .../DoubleExponentialHistogramBuckets.java | 18 +++++++++++++++++- .../data/DoubleExponentialHistogramData.java | 5 ++++- .../DoubleExponentialHistogramPointData.java | 15 ++++++++++++--- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleExponentialHistogramBuckets.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleExponentialHistogramBuckets.java index 118f2581e11..e4eb43d9806 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleExponentialHistogramBuckets.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleExponentialHistogramBuckets.java @@ -14,6 +14,15 @@ /** * DoubleExponentialHistogramBuckets represents either the positive or negative measurements taken * for a {@link DoubleExponentialHistogramPointData}. + * + *

The bucket boundaries are lower-bound inclusive, and are calculated using the {@link + * DoubleExponentialHistogramPointData#getScale()} and the {@link #getOffset()}. + * + *

For example, assume {@link DoubleExponentialHistogramPointData#getScale()} is 0, implying + * {@link DoubleExponentialHistogramPointData#getBase()} is 2.0. Then, if offset is 0, + * the bucket lower bounds would be 1.0, 2.0, 4.0, 8.0, etc. If 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. */ @AutoValue @Immutable @@ -23,7 +32,8 @@ public abstract class DoubleExponentialHistogramBuckets { /** * Create DoubleExponentialHistogramBuckets. * - * @param offset Signed integer representing the bucket index of the first entry in bucketCounts. + * @param offset Signed integer which shifts the bucket boundaries according to + * lower_bound = base^(offset+i). * @param bucketCounts List of counts representing number of measurements that fall into each * bucket. * @return a DoubleExponentialHistogramBuckets. @@ -37,6 +47,12 @@ public DoubleExponentialHistogramBuckets create(int offset, List bucketCou offset, Collections.unmodifiableList(new ArrayList<>(bucketCounts)), totalCount); } + /** + * The offset shifts the bucket boundaries according to lower_bound = base^(offset+i). + * . + * + * @return the offset. + */ public abstract int getOffset(); public abstract List getBucketCounts(); diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleExponentialHistogramData.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleExponentialHistogramData.java index bf110b6043c..2b6e783f0da 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleExponentialHistogramData.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleExponentialHistogramData.java @@ -10,7 +10,10 @@ import javax.annotation.concurrent.Immutable; /** - * An exponential histogram metric point, as defined by the OpenTelemetry Exponential Histogram. + * A base-2 exponential histogram metric point, as defined by the OpenTelemetry Exponential + * Histogram specification. + * + *

See {@link DoubleExponentialHistogramPointData} for more information. * *

See: * https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/datamodel.md#exponentialhistogram diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleExponentialHistogramPointData.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleExponentialHistogramPointData.java index 681096eecac..d810d6ddb43 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleExponentialHistogramPointData.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleExponentialHistogramPointData.java @@ -13,10 +13,12 @@ /** * DoubleExponentialHistogramPointData represents an approximate distribution of measurements across * exponentially increasing bucket boundaries, taken for a {@link DoubleExponentialHistogramData}. - * It also contains the necessary information to calculate bucket boundaries and perform - * aggregation. + * It contains the necessary information to calculate bucket boundaries and perform aggregation. * - *

The bucket boundaries increase exponentially according to the scale and the offset. See: + *

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

See: * https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/datamodel.md#exponentialhistogram */ @Immutable @@ -72,6 +74,13 @@ public static DoubleExponentialHistogramPointData create( @Override public abstract Attributes getAttributes(); + /** + * 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 + * base, where base = Math.pow(2, Math.pow(2, -scale)). + * + * @return the scale. + */ public abstract int getScale(); public abstract double getSum(); From 8960a6d48fa283ea34beac59988932bbf5688270 Mon Sep 17 00:00:00 2001 From: James Moessis Date: Wed, 22 Sep 2021 16:04:24 +1000 Subject: [PATCH 05/12] more verbose param description of expo histogram scale --- .../sdk/metrics/data/DoubleExponentialHistogramPointData.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleExponentialHistogramPointData.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleExponentialHistogramPointData.java index d810d6ddb43..16921f99cd3 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleExponentialHistogramPointData.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleExponentialHistogramPointData.java @@ -30,7 +30,9 @@ public abstract class DoubleExponentialHistogramPointData implements PointData { /** * Creates a DoubleExponentialHistogramPointData. * - * @param scale Scale is used to calculate bucket boundaries as outlined in the OTLP. + * @param scale 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 base, where base = Math.pow(2, Math.pow(2, -scale)). * @param sum The sum of all measurements in the histogram. * @param zeroCount Number of values that are zero. * @param positiveBuckets Buckets with positive values. From 3b72b19ff48732680606849b0cb65a6862535801 Mon Sep 17 00:00:00 2001 From: James Moessis Date: Thu, 23 Sep 2021 11:26:34 +1000 Subject: [PATCH 06/12] add java doc to all public methods, remove unnecessary overrides --- .../DoubleExponentialHistogramBuckets.java | 11 ++++ .../data/DoubleExponentialHistogramData.java | 5 ++ .../DoubleExponentialHistogramPointData.java | 62 ++++++++++++++----- 3 files changed, 62 insertions(+), 16 deletions(-) diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleExponentialHistogramBuckets.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleExponentialHistogramBuckets.java index e4eb43d9806..c264ad7312e 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleExponentialHistogramBuckets.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleExponentialHistogramBuckets.java @@ -55,7 +55,18 @@ public DoubleExponentialHistogramBuckets create(int offset, List bucketCou */ public abstract int getOffset(); + /** + * The bucket counts is a of counts representing number of measurements that fall into each + * bucket. + * + * @return the bucket counts. + */ public abstract List getBucketCounts(); + /** + * The total count is the sum of all the values in the list {@link #getBucketCounts()}. + * + * @return the total count. + */ public abstract long getTotalCount(); } diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleExponentialHistogramData.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleExponentialHistogramData.java index 2b6e783f0da..adfcb0f9ddc 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleExponentialHistogramData.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleExponentialHistogramData.java @@ -49,6 +49,11 @@ public static DoubleExponentialHistogramData create( */ public abstract AggregationTemporality getAggregationTemporality(); + /** + * Returns the collection of {@link DoubleExponentialHistogramPointData} for this histogram. + * + * @return the collection of data points for this histogram. + */ @Override public abstract Collection getPoints(); } diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleExponentialHistogramPointData.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleExponentialHistogramPointData.java index 16921f99cd3..f106437bca1 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleExponentialHistogramPointData.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleExponentialHistogramPointData.java @@ -30,13 +30,18 @@ public abstract class DoubleExponentialHistogramPointData implements PointData { /** * Creates a DoubleExponentialHistogramPointData. * + * @param startEpochNanos epoch timestamp in nanos indicating when the histogram was created. + * @param epochNanos epoch timestamp in nanos indicating when the data was collected. + * @param attributes attributes associated with this data point. * @param scale 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 base, where base = Math.pow(2, Math.pow(2, -scale)). * @param sum The sum of all measurements in the histogram. * @param zeroCount Number of values that are zero. - * @param positiveBuckets Buckets with positive values. - * @param negativeBuckets Buckets with negative values. + * @param positiveBuckets Buckets that measure positive values. + * @param negativeBuckets Buckets that measure negative values. + * @param exemplars List of exemplars collected from measurements that were used to form the data + * point. * @return a DoubleExponentialHistogramPointData */ public static DoubleExponentialHistogramPointData create( @@ -57,25 +62,16 @@ public static DoubleExponentialHistogramPointData create( startEpochNanos, epochNanos, attributes, + exemplars, scale, sum, count, base, zeroCount, positiveBuckets, - negativeBuckets, - exemplars); + negativeBuckets); } - @Override - public abstract long getStartEpochNanos(); - - @Override - public abstract long getEpochNanos(); - - @Override - public abstract Attributes getAttributes(); - /** * 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 @@ -85,18 +81,52 @@ public static DoubleExponentialHistogramPointData create( */ public abstract int getScale(); + /** + * Returns the sum of all measurements in the data point. The sum should be disregarded if there + * are both positive and negative measurements. + * + * @return the sum of all measurements in this data point. + */ public abstract double getSum(); + /** + * Returns the number of measurements taken for this data point, including the positive bucket + * counts, negative bucket counts, and the zero count. + * + * @return the number of measurements in this data point. + */ public abstract long getCount(); + /** + * Returns the base, which is calculated via the scale {@link #getScale()}. The larger the base, + * the further away bucket boundaries are from each other. + * + *

base = 2^(2^-scale) + * + * @return the base. + */ public abstract double getBase(); + /** + * Returns the number of measurements equal to zero in this data point. + * + * @return the number of values equal to zero. + */ public abstract long getZeroCount(); + /** + * Return the {@link DoubleExponentialHistogramBuckets} representing the positive measurements + * taken for this histogram. + * + * @return the positive buckets. + */ public abstract DoubleExponentialHistogramBuckets getPositiveBuckets(); + /** + * Return the {@link DoubleExponentialHistogramBuckets} representing the negative measurements + * taken for this histogram. + * + * @return the negative buckets. + */ public abstract DoubleExponentialHistogramBuckets getNegativeBuckets(); - - @Override - public abstract List getExemplars(); } From b94a6e170777868d06436fadcec3f573f37796e5 Mon Sep 17 00:00:00 2001 From: James Moessis Date: Mon, 27 Sep 2021 11:43:02 +1000 Subject: [PATCH 07/12] change expo histogram data to pure interface --- .../DoubleExponentialHistogramBuckets.java | 72 ---------- .../data/DoubleExponentialHistogramData.java | 59 -------- .../DoubleExponentialHistogramPointData.java | 132 ------------------ .../data/ExponentialHistogramBuckets.java | 49 +++++++ .../data/ExponentialHistogramData.java | 43 ++++++ .../data/ExponentialHistogramPointData.java | 81 +++++++++++ 6 files changed, 173 insertions(+), 263 deletions(-) delete mode 100644 sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleExponentialHistogramBuckets.java delete mode 100644 sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleExponentialHistogramData.java delete mode 100644 sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleExponentialHistogramPointData.java create mode 100644 sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/ExponentialHistogramBuckets.java create mode 100644 sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/ExponentialHistogramData.java create mode 100644 sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/ExponentialHistogramPointData.java diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleExponentialHistogramBuckets.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleExponentialHistogramBuckets.java deleted file mode 100644 index c264ad7312e..00000000000 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleExponentialHistogramBuckets.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.sdk.metrics.data; - -import com.google.auto.value.AutoValue; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import javax.annotation.concurrent.Immutable; - -/** - * DoubleExponentialHistogramBuckets represents either the positive or negative measurements taken - * for a {@link DoubleExponentialHistogramPointData}. - * - *

The bucket boundaries are lower-bound inclusive, and are calculated using the {@link - * DoubleExponentialHistogramPointData#getScale()} and the {@link #getOffset()}. - * - *

For example, assume {@link DoubleExponentialHistogramPointData#getScale()} is 0, implying - * {@link DoubleExponentialHistogramPointData#getBase()} is 2.0. Then, if offset is 0, - * the bucket lower bounds would be 1.0, 2.0, 4.0, 8.0, etc. If 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. - */ -@AutoValue -@Immutable -public abstract class DoubleExponentialHistogramBuckets { - DoubleExponentialHistogramBuckets() {} - - /** - * Create DoubleExponentialHistogramBuckets. - * - * @param offset Signed integer which shifts the bucket boundaries according to - * lower_bound = base^(offset+i). - * @param bucketCounts List of counts representing number of measurements that fall into each - * bucket. - * @return a DoubleExponentialHistogramBuckets. - */ - public DoubleExponentialHistogramBuckets create(int offset, List bucketCounts) { - long totalCount = 0; - for (long count : bucketCounts) { - totalCount += count; - } - return new AutoValue_DoubleExponentialHistogramBuckets( - offset, Collections.unmodifiableList(new ArrayList<>(bucketCounts)), totalCount); - } - - /** - * The offset shifts the bucket boundaries according to lower_bound = base^(offset+i). - * . - * - * @return the offset. - */ - public abstract int getOffset(); - - /** - * The bucket counts is a of counts representing number of measurements that fall into each - * bucket. - * - * @return the bucket counts. - */ - public abstract List getBucketCounts(); - - /** - * The total count is the sum of all the values in the list {@link #getBucketCounts()}. - * - * @return the total count. - */ - public abstract long getTotalCount(); -} diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleExponentialHistogramData.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleExponentialHistogramData.java deleted file mode 100644 index adfcb0f9ddc..00000000000 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleExponentialHistogramData.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.sdk.metrics.data; - -import com.google.auto.value.AutoValue; -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 DoubleExponentialHistogramPointData} for more information. - * - *

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

Note: This is called "DoubleExponentialHistogramData" to reflect which primitives are used - * to record it, however "ExponentialHistogram" is the equivalent OTLP type. - */ -@Immutable -@AutoValue -public abstract class DoubleExponentialHistogramData - implements Data { - DoubleExponentialHistogramData() {} - - /** - * Creates a DoubleExponentialHistogramData. - * - * @param temporality The {@link AggregationTemporality} - * @param points A collection of {@link DoubleExponentialHistogramPointData} to hold measurements - * @return a DoubleExponentialHistogramData - */ - public static DoubleExponentialHistogramData create( - AggregationTemporality temporality, Collection points) { - return new AutoValue_DoubleExponentialHistogramData(temporality, points); - } - - /** - * 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 - */ - public abstract AggregationTemporality getAggregationTemporality(); - - /** - * Returns the collection of {@link DoubleExponentialHistogramPointData} for this histogram. - * - * @return the collection of data points for this histogram. - */ - @Override - public abstract Collection getPoints(); -} diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleExponentialHistogramPointData.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleExponentialHistogramPointData.java deleted file mode 100644 index f106437bca1..00000000000 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleExponentialHistogramPointData.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.sdk.metrics.data; - -import com.google.auto.value.AutoValue; -import io.opentelemetry.api.common.Attributes; -import java.util.List; -import javax.annotation.concurrent.Immutable; - -/** - * DoubleExponentialHistogramPointData represents an approximate distribution of measurements across - * exponentially increasing bucket boundaries, taken for a {@link DoubleExponentialHistogramData}. - * It contains the necessary information to calculate bucket boundaries and perform aggregation. - * - *

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

See: - * https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/datamodel.md#exponentialhistogram - */ -@Immutable -@AutoValue -public abstract class DoubleExponentialHistogramPointData implements PointData { - - DoubleExponentialHistogramPointData() {} - - /** - * Creates a DoubleExponentialHistogramPointData. - * - * @param startEpochNanos epoch timestamp in nanos indicating when the histogram was created. - * @param epochNanos epoch timestamp in nanos indicating when the data was collected. - * @param attributes attributes associated with this data point. - * @param scale 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 base, where base = Math.pow(2, Math.pow(2, -scale)). - * @param sum The sum of all measurements in the histogram. - * @param zeroCount Number of values that are zero. - * @param positiveBuckets Buckets that measure positive values. - * @param negativeBuckets Buckets that measure negative values. - * @param exemplars List of exemplars collected from measurements that were used to form the data - * point. - * @return a DoubleExponentialHistogramPointData - */ - public static DoubleExponentialHistogramPointData create( - long startEpochNanos, - long epochNanos, - Attributes attributes, - int scale, - double sum, - long zeroCount, - DoubleExponentialHistogramBuckets positiveBuckets, - DoubleExponentialHistogramBuckets negativeBuckets, - List exemplars) { - - long count = zeroCount + positiveBuckets.getTotalCount() + negativeBuckets.getTotalCount(); - double base = Math.pow(2, Math.pow(2, -scale)); - - return new AutoValue_DoubleExponentialHistogramPointData( - startEpochNanos, - epochNanos, - attributes, - exemplars, - scale, - sum, - count, - base, - zeroCount, - positiveBuckets, - negativeBuckets); - } - - /** - * 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 - * base, where base = Math.pow(2, Math.pow(2, -scale)). - * - * @return the scale. - */ - public abstract int getScale(); - - /** - * Returns the sum of all measurements in the data point. The sum should be disregarded if there - * are both positive and negative measurements. - * - * @return the sum of all measurements in this data point. - */ - public abstract double getSum(); - - /** - * Returns the number of measurements taken for this data point, including the positive bucket - * counts, negative bucket counts, and the zero count. - * - * @return the number of measurements in this data point. - */ - public abstract long getCount(); - - /** - * Returns the base, which is calculated via the scale {@link #getScale()}. The larger the base, - * the further away bucket boundaries are from each other. - * - *

base = 2^(2^-scale) - * - * @return the base. - */ - public abstract double getBase(); - - /** - * Returns the number of measurements equal to zero in this data point. - * - * @return the number of values equal to zero. - */ - public abstract long getZeroCount(); - - /** - * Return the {@link DoubleExponentialHistogramBuckets} representing the positive measurements - * taken for this histogram. - * - * @return the positive buckets. - */ - public abstract DoubleExponentialHistogramBuckets getPositiveBuckets(); - - /** - * Return the {@link DoubleExponentialHistogramBuckets} representing the negative measurements - * taken for this histogram. - * - * @return the negative buckets. - */ - public abstract DoubleExponentialHistogramBuckets getNegativeBuckets(); -} diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/ExponentialHistogramBuckets.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/ExponentialHistogramBuckets.java new file mode 100644 index 00000000000..b2fcb698463 --- /dev/null +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/ExponentialHistogramBuckets.java @@ -0,0 +1,49 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.sdk.metrics.data; + +import java.util.List; +import javax.annotation.concurrent.Immutable; + +/** + * ExponentialHistogramBuckets represents either the positive or negative measurements taken for a + * {@link ExponentialHistogramPointData}. + * + *

The bucket boundaries are lower-bound inclusive, and are calculated using the {@link + * ExponentialHistogramPointData#getScale()} and the {@link #getOffset()}. + * + *

For example, assume {@link ExponentialHistogramPointData#getScale()} is 0, implying {@link + * ExponentialHistogramPointData#getBase()} is 2.0. Then, if offset is 0, the bucket + * lower bounds would be 1.0, 2.0, 4.0, 8.0, etc. If 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. + */ +@Immutable +public interface ExponentialHistogramBuckets { + + /** + * The offset shifts the bucket boundaries according to lower_bound = base^(offset+i). + * . + * + * @return the offset. + */ + int getOffset(); + + /** + * The bucket counts is a of counts representing number of measurements that fall into each + * bucket. + * + * @return the bucket counts. + */ + List getBucketCounts(); + + /** + * The total count is the sum of all the values in the list {@link #getBucketCounts()}. + * + * @return the total count. + */ + long getTotalCount(); +} 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..9a2910a2739 --- /dev/null +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/ExponentialHistogramData.java @@ -0,0 +1,43 @@ +/* + * 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. + * + *

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. + */ +@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/data/ExponentialHistogramPointData.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/ExponentialHistogramPointData.java new file mode 100644 index 00000000000..b2835ed1fa0 --- /dev/null +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/ExponentialHistogramPointData.java @@ -0,0 +1,81 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.sdk.metrics.data; + +import javax.annotation.concurrent.Immutable; + +/** + * ExponentialHistogramPointData represents an approximate distribution of measurements across + * exponentially increasing bucket boundaries, taken for a {@link ExponentialHistogramData}. It + * contains the necessary information to calculate bucket boundaries and perform aggregation. + * + *

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

See: + * https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/datamodel.md#exponentialhistogram + */ +@Immutable +public interface ExponentialHistogramPointData extends PointData { + + /** + * 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 + * base, where base = Math.pow(2, Math.pow(2, -scale)). + * + * @return the scale. + */ + int getScale(); + + /** + * Returns the sum of all measurements in the data point. The sum should be disregarded if there + * are both positive and negative measurements. + * + * @return the sum of all measurements in this data point. + */ + double getSum(); + + /** + * Returns the number of measurements taken for this data point, including the positive bucket + * counts, negative bucket counts, and the zero count. + * + * @return the number of measurements in this data point. + */ + long getCount(); + + /** + * Returns the base, which is calculated via the scale {@link #getScale()}. The larger the base, + * the further away bucket boundaries are from each other. + * + *

base = 2^(2^-scale) + * + * @return the base. + */ + double getBase(); + + /** + * Returns the number of measurements equal to zero in this data point. + * + * @return the number of values equal to zero. + */ + long getZeroCount(); + + /** + * Return the {@link ExponentialHistogramBuckets} representing the positive measurements taken for + * this histogram. + * + * @return the positive buckets. + */ + ExponentialHistogramBuckets getPositiveBuckets(); + + /** + * Return the {@link ExponentialHistogramBuckets} representing the negative measurements taken for + * this histogram. + * + * @return the negative buckets. + */ + ExponentialHistogramBuckets getNegativeBuckets(); +} From e7ec6b85ee7fb1fe8f23b1e9e384ba343fa1b516 Mon Sep 17 00:00:00 2001 From: James Moessis Date: Mon, 27 Sep 2021 22:46:04 +1000 Subject: [PATCH 08/12] add default method for getBase() --- .../sdk/metrics/data/ExponentialHistogramPointData.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/ExponentialHistogramPointData.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/ExponentialHistogramPointData.java index b2835ed1fa0..b384518f117 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/ExponentialHistogramPointData.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/ExponentialHistogramPointData.java @@ -54,7 +54,9 @@ public interface ExponentialHistogramPointData extends PointData { * * @return the base. */ - double getBase(); + default double getBase() { + return Math.pow(2, Math.pow(2, -getScale())); + } /** * Returns the number of measurements equal to zero in this data point. From 203d87ab68e494bab2bfd543e4d4250c03f6d7bf Mon Sep 17 00:00:00 2001 From: James Moessis Date: Tue, 28 Sep 2021 14:10:56 +1000 Subject: [PATCH 09/12] change from getBucketCounts() -> getBucketCountAt(idx) --- .../metrics/data/ExponentialHistogramBuckets.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/ExponentialHistogramBuckets.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/ExponentialHistogramBuckets.java index b2fcb698463..f7625ce8f68 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/ExponentialHistogramBuckets.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/ExponentialHistogramBuckets.java @@ -5,7 +5,6 @@ package io.opentelemetry.sdk.metrics.data; -import java.util.List; import javax.annotation.concurrent.Immutable; /** @@ -33,15 +32,19 @@ public interface ExponentialHistogramBuckets { int getOffset(); /** - * The bucket counts is a of counts representing number of measurements that fall into each - * bucket. + * The bucket count is the number of measurements that fall into a bucket corresponding to the + * given index. Index can be negative, in which case the bucket would be lower bounded somewhere + * between 0 and 1 (or 0 and -1 if these buckets represent negative measurements). * - * @return the bucket counts. + *

Bucket boundaries are inclusive lower bound and exclusive upper bound. + * + * @param index signed int corresponding to the relevant bucket. + * @return the number of measurements in the bucket. */ - List getBucketCounts(); + long getBucketCountAt(int index); /** - * The total count is the sum of all the values in the list {@link #getBucketCounts()}. + * The total count is the sum of all the values in the buckets. * * @return the total count. */ From bc5910a24b3746fa2e65ecc489f92d164839e753 Mon Sep 17 00:00:00 2001 From: James Moessis Date: Wed, 29 Sep 2021 11:39:19 +1000 Subject: [PATCH 10/12] add getNumBuckets() and getStartIndex() --- .../data/ExponentialHistogramBuckets.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/ExponentialHistogramBuckets.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/ExponentialHistogramBuckets.java index f7625ce8f68..8fd27fecaf4 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/ExponentialHistogramBuckets.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/ExponentialHistogramBuckets.java @@ -43,6 +43,24 @@ public interface ExponentialHistogramBuckets { */ long getBucketCountAt(int index); + /** + * Returns the index corresponding to the bucket that has the lower bound with the lowest absolute + * value. + * + *

Can be used to start iteration over the buckets, in combination with {@link + * #getNumBuckets()} and {@link #getBucketCountAt(int)}. + * + * @return the index of the lowest bucket. + */ + int getStartIndex(); + + /** + * Returns the number of buckets. + * + * @return the number of buckets. + */ + int getNumBuckets(); + /** * The total count is the sum of all the values in the buckets. * From bb6a10d71bbeba3f9c8a88e464d4b2018251ca90 Mon Sep 17 00:00:00 2001 From: James Moessis Date: Wed, 29 Sep 2021 11:40:03 +1000 Subject: [PATCH 11/12] remove getBase() because it is not required --- .../metrics/data/ExponentialHistogramBuckets.java | 9 ++++----- .../metrics/data/ExponentialHistogramPointData.java | 12 ------------ 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/ExponentialHistogramBuckets.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/ExponentialHistogramBuckets.java index 8fd27fecaf4..2b2e6c0a143 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/ExponentialHistogramBuckets.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/ExponentialHistogramBuckets.java @@ -14,11 +14,10 @@ *

The bucket boundaries are lower-bound inclusive, and are calculated using the {@link * ExponentialHistogramPointData#getScale()} and the {@link #getOffset()}. * - *

For example, assume {@link ExponentialHistogramPointData#getScale()} is 0, implying {@link - * ExponentialHistogramPointData#getBase()} is 2.0. Then, if offset is 0, the bucket - * lower bounds would be 1.0, 2.0, 4.0, 8.0, etc. If 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. + *

For example, assume {@link ExponentialHistogramPointData#getScale()} is 0, the base is 2.0. + * Then, if offset is 0, the bucket lower bounds would be 1.0, 2.0, 4.0, 8.0, etc. If + * 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. */ @Immutable public interface ExponentialHistogramBuckets { diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/ExponentialHistogramPointData.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/ExponentialHistogramPointData.java index b384518f117..31da82b50a0 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/ExponentialHistogramPointData.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/ExponentialHistogramPointData.java @@ -46,18 +46,6 @@ public interface ExponentialHistogramPointData extends PointData { */ long getCount(); - /** - * Returns the base, which is calculated via the scale {@link #getScale()}. The larger the base, - * the further away bucket boundaries are from each other. - * - *

base = 2^(2^-scale) - * - * @return the base. - */ - default double getBase() { - return Math.pow(2, Math.pow(2, -getScale())); - } - /** * Returns the number of measurements equal to zero in this data point. * From 59082357369defa2f70160996cf234ea9148ce9a Mon Sep 17 00:00:00 2001 From: James Moessis Date: Thu, 30 Sep 2021 09:49:12 +1000 Subject: [PATCH 12/12] go back to List for bucket counts --- .../data/ExponentialHistogramBuckets.java | 31 +++---------------- 1 file changed, 5 insertions(+), 26 deletions(-) diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/ExponentialHistogramBuckets.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/ExponentialHistogramBuckets.java index 2b2e6c0a143..235823fd4c7 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/ExponentialHistogramBuckets.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/ExponentialHistogramBuckets.java @@ -5,6 +5,7 @@ package io.opentelemetry.sdk.metrics.data; +import java.util.List; import javax.annotation.concurrent.Immutable; /** @@ -31,34 +32,12 @@ public interface ExponentialHistogramBuckets { int getOffset(); /** - * The bucket count is the number of measurements that fall into a bucket corresponding to the - * given index. Index can be negative, in which case the bucket would be lower bounded somewhere - * between 0 and 1 (or 0 and -1 if these buckets represent negative measurements). + * The bucket counts is a of counts representing number of measurements that fall into each + * bucket. * - *

Bucket boundaries are inclusive lower bound and exclusive upper bound. - * - * @param index signed int corresponding to the relevant bucket. - * @return the number of measurements in the bucket. - */ - long getBucketCountAt(int index); - - /** - * Returns the index corresponding to the bucket that has the lower bound with the lowest absolute - * value. - * - *

Can be used to start iteration over the buckets, in combination with {@link - * #getNumBuckets()} and {@link #getBucketCountAt(int)}. - * - * @return the index of the lowest bucket. - */ - int getStartIndex(); - - /** - * Returns the number of buckets. - * - * @return the number of buckets. + * @return the bucket counts. */ - int getNumBuckets(); + List getBucketCounts(); /** * The total count is the sum of all the values in the buckets.