-
Notifications
You must be signed in to change notification settings - Fork 833
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
Prototype exposing the exemplar reservoir for upcoming spec changes #5960
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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"; | ||
Check warning on line 38 in sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/exemplar/ExemplarReservoirFactory.java Codecov / codecov/patchsdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/exemplar/ExemplarReservoirFactory.java#L38
|
||
} | ||
}; | ||
} | ||
|
||
/** | ||
* 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 + ")"; | ||
Check warning on line 65 in sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/exemplar/ExemplarReservoirFactory.java Codecov / codecov/patchsdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/exemplar/ExemplarReservoirFactory.java#L65
|
||
} | ||
}; | ||
} | ||
|
||
/** | ||
* 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( | ||
Check warning on line 81 in sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/exemplar/ExemplarReservoirFactory.java Codecov / codecov/patchsdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/exemplar/ExemplarReservoirFactory.java#L81
|
||
"Cannot create long exemplars for histogram buckets"); | ||
} | ||
|
||
@Override | ||
public ExemplarReservoir<DoubleExemplarData> createDoubleExemplarReservoir() { | ||
return new HistogramExemplarReservoir(clock, boundaries); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "histogramBucket(" + boundaries + ")"; | ||
Check warning on line 92 in sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/exemplar/ExemplarReservoirFactory.java Codecov / codecov/patchsdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/exemplar/ExemplarReservoirFactory.java#L92
|
||
} | ||
}; | ||
} | ||
} |
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); | ||
} |
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: