-
Notifications
You must be signed in to change notification settings - Fork 921
Prototype exposing the exemplar reservoir for upcoming spec changes #5960
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
Closed
jsuereth
wants to merge
1
commit into
open-telemetry:main
from
jsuereth:wip-expose-exemplar-reservoir-experimental
Closed
Changes from all commits
Commits
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
96 changes: 96 additions & 0 deletions
96
...rc/main/java/io/opentelemetry/sdk/metrics/internal/exemplar/ExemplarReservoirFactory.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,96 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.sdk.metrics.internal.exemplar; | ||
|
|
||
| import io.opentelemetry.sdk.common.Clock; | ||
| import io.opentelemetry.sdk.metrics.data.DoubleExemplarData; | ||
| import io.opentelemetry.sdk.metrics.data.LongExemplarData; | ||
| import java.util.List; | ||
| import java.util.Random; | ||
| import java.util.function.Supplier; | ||
|
|
||
| /** | ||
| * An interface for constructing an appropriate ExemplarReservoir for a given metric "memory cell". | ||
| */ | ||
| public interface ExemplarReservoirFactory { | ||
| ExemplarReservoir<LongExemplarData> createLongExemplarReservoir(); | ||
|
|
||
| ExemplarReservoir<DoubleExemplarData> createDoubleExemplarReservoir(); | ||
|
|
||
| /** An exemplar reservoir that stores no exemplars. */ | ||
| static ExemplarReservoirFactory noSamples() { | ||
| return new ExemplarReservoirFactory() { | ||
| @Override | ||
| public ExemplarReservoir<LongExemplarData> createLongExemplarReservoir() { | ||
| return NoopExemplarReservoir.LONG_INSTANCE; | ||
| } | ||
|
|
||
| @Override | ||
| public ExemplarReservoir<DoubleExemplarData> createDoubleExemplarReservoir() { | ||
| return NoopExemplarReservoir.DOUBLE_INSTANCE; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "noSamples"; | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * A reservoir with fixed size that stores the given number of exemplars. | ||
| * | ||
| * @param clock The clock to use when annotating measurements with time. | ||
| * @param size The maximum number of exemplars to preserve. | ||
| * @param randomSupplier The random number generator to use for sampling. | ||
| */ | ||
| static ExemplarReservoirFactory fixedSize( | ||
| Clock clock, int size, Supplier<Random> randomSupplier) { | ||
| return new ExemplarReservoirFactory() { | ||
| @Override | ||
| public ExemplarReservoir<LongExemplarData> createLongExemplarReservoir() { | ||
| return RandomFixedSizeExemplarReservoir.createLong(clock, size, randomSupplier); | ||
| } | ||
|
|
||
| @Override | ||
| public ExemplarReservoir<DoubleExemplarData> createDoubleExemplarReservoir() { | ||
| return RandomFixedSizeExemplarReservoir.createDouble(clock, size, randomSupplier); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "fixedSize(" + size + ")"; | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * A Reservoir sampler that preserves the latest seen measurement per-histogram bucket. | ||
| * | ||
| * @param clock The clock to use when annotating measurements with time. | ||
| * @param boundaries A list of (inclusive) upper bounds for the histogram. Should be in order from | ||
| * lowest to highest. | ||
| */ | ||
| static ExemplarReservoirFactory histogramBucket(Clock clock, List<Double> boundaries) { | ||
| return new ExemplarReservoirFactory() { | ||
| @Override | ||
| public ExemplarReservoir<LongExemplarData> createLongExemplarReservoir() { | ||
| throw new UnsupportedOperationException( | ||
| "Cannot create long exemplars for histogram buckets"); | ||
| } | ||
|
|
||
| @Override | ||
| public ExemplarReservoir<DoubleExemplarData> createDoubleExemplarReservoir() { | ||
| return new HistogramExemplarReservoir(clock, boundaries); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "histogramBucket(" + boundaries + ")"; | ||
| } | ||
| }; | ||
| } | ||
| } | ||
21 changes: 21 additions & 0 deletions
21
...etrics/src/main/java/io/opentelemetry/sdk/metrics/internal/view/AggregationExtension.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,21 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.sdk.metrics.internal.view; | ||
|
|
||
| import io.opentelemetry.sdk.metrics.Aggregation; | ||
| import io.opentelemetry.sdk.metrics.internal.aggregator.AggregatorFactory; | ||
| import io.opentelemetry.sdk.metrics.internal.exemplar.ExemplarReservoirFactory; | ||
|
|
||
| /** | ||
| * An interface which allows customized configuration of aggregators. | ||
| * | ||
| * <p>This class is internal and is hence not for public use. Its APIs are unstable and can change | ||
| * at any time. | ||
| */ | ||
| public interface AggregationExtension extends Aggregation, AggregatorFactory { | ||
| /** Override the exemplar reservoir used for this aggregation. */ | ||
| AggregationExtension setExemplarReservoirFactory(ExemplarReservoirFactory reservoirFactory); | ||
| } |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to see this split out into a class so we can provide a more conventional toString implementation: