-
Notifications
You must be signed in to change notification settings - Fork 993
Histogram Aggregation - core SDK - data #2923
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
Merged
jkwatson
merged 4 commits into
open-telemetry:main
from
atlassian-forks:histogram-aggregation-core-data
Feb 25, 2021
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
3c4b3dd
add histogram related metric data types
beanliu 38a7557
update doc of histogram boundaries to make it compatible with latest …
beanliu 596c50b
remove unnecessary helper
beanliu 52de0be
simplify the create interface, add doc and validations
beanliu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleHistogramData.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| /* | ||
| * 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; | ||
|
|
||
| @Immutable | ||
| @AutoValue | ||
| public abstract class DoubleHistogramData implements Data<DoubleHistogramPointData> { | ||
| DoubleHistogramData() {} | ||
|
|
||
| public static DoubleHistogramData create( | ||
| AggregationTemporality temporality, Collection<DoubleHistogramPointData> points) { | ||
| return new AutoValue_DoubleHistogramData(temporality, points); | ||
| } | ||
|
|
||
| /** | ||
| * 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 | ||
| */ | ||
| public abstract AggregationTemporality getAggregationTemporality(); | ||
|
|
||
| @Override | ||
| public abstract Collection<DoubleHistogramPointData> getPoints(); | ||
| } |
93 changes: 93 additions & 0 deletions
93
sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleHistogramPointData.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| /* | ||
| * 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.metrics.common.Labels; | ||
| import java.util.ArrayList; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import javax.annotation.concurrent.Immutable; | ||
|
|
||
| /** | ||
| * DoubleHistogramPointData represents an approximate representation of the distribution of | ||
| * measurements. | ||
| */ | ||
| @Immutable | ||
| @AutoValue | ||
| public abstract class DoubleHistogramPointData implements PointData { | ||
| /** | ||
| * Functional interface for consuming bucket boundaries and counts as a sequence of pair values. | ||
| */ | ||
| public interface BucketConsumer { | ||
| void accept(double upperBound, long count); | ||
| } | ||
|
|
||
| /** | ||
| * Creates a DoubleHistogramPointData. | ||
| * | ||
| * @return a DoubleHistogramPointData. | ||
| */ | ||
| public static DoubleHistogramPointData create( | ||
| long startEpochNanos, | ||
| long epochNanos, | ||
| Labels labels, | ||
| double sum, | ||
| long count, | ||
| List<Double> boundaries, | ||
| List<Long> counts) { | ||
| return new AutoValue_DoubleHistogramPointData( | ||
| startEpochNanos, | ||
| epochNanos, | ||
| labels, | ||
| sum, | ||
| count, | ||
| Collections.unmodifiableList(new ArrayList<>(boundaries)), | ||
| Collections.unmodifiableList(new ArrayList<>(counts))); | ||
| } | ||
|
|
||
| DoubleHistogramPointData() {} | ||
|
|
||
| /** | ||
| * The sum of all measurements recorded. | ||
| * | ||
| * @return the sum of recorded measurements. | ||
| */ | ||
| public abstract double getSum(); | ||
|
|
||
| /** | ||
| * The number of measurements taken. | ||
| * | ||
| * @return the count of recorded measurements. | ||
| */ | ||
| public abstract long getCount(); | ||
|
|
||
| /** | ||
| * The bucket boundaries. For a Histogram with N defined boundaries, e.g, [x, y, z]. There are N+1 | ||
| * counts: [-inf, x), [x, y), [y, z), [z, +inf]. | ||
| * | ||
| * @return the read-only bucket boundaries in increasing order. <b>do not mutate</b> the returned | ||
| * object. | ||
| */ | ||
|
beanliu marked this conversation as resolved.
|
||
| public abstract List<Double> getBoundaries(); | ||
|
|
||
| /** | ||
| * The counts in each bucket. | ||
| * | ||
| * @return the read-only counts in each bucket. <b>do not mutate</b> the returned object. | ||
| */ | ||
| public abstract List<Long> getCounts(); | ||
|
|
||
| /** Iterates over all the bucket boundaries and counts in this histogram. */ | ||
| public void forEach(BucketConsumer action) { | ||
|
beanliu marked this conversation as resolved.
Outdated
|
||
| List<Double> boundaries = getBoundaries(); | ||
| List<Long> counts = getCounts(); | ||
| for (int i = 0; i < boundaries.size(); ++i) { | ||
| action.accept(boundaries.get(i), counts.get(i)); | ||
| } | ||
| action.accept(Double.POSITIVE_INFINITY, counts.get(boundaries.size())); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.