-
Notifications
You must be signed in to change notification settings - Fork 850
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add adaptable circular buffer implementation for ExponentialCounter. (#…
…4087) * Add adaptable circular buffer implementation for ExponentialCounter and expose hooks to test its use in Exponential Histogram aggregator. * Clean up some adapting circular buffer code. * Fix style issues. * Apply spotless. * Add tests for adapting integer array. * Finish wiring ability to remember previous integer cell size and expand testing. * Update array copy from code review. * Fixes/cleanups from review. - Fix a bug in equality where it was forcing ExponentialCounter to have the same offset, even if it had stored 0 counts in all buckets. This interacts negatively with merge/diff tests where creating a fresh exponential bucket would have different indexStart then diff-ing another. - Modify default exponential bucket counter to be adapting circular buffer. - Remove some not-well-though-out methods (like zeroOf, zeroFrom) in favor of a "clear" method on ExponentialCounter - Modify ExponentialBucketStrategy to be an actual implementation. * Improve testing of copy behavior across exponential-counter implementations. * Last fix/cleanup for PR. Remove remaining TODO around preserving runtime optimisations. * Fixes from review. * Add test to ensure 0 is returned from exponential counters outside popualted range. * Add a bunch of extra equality tests. * run spotless. * Add note about equality. * Add copy() method to AdaptingIntegerArray, update tests. * Fix checkstyle. * Add internal disclaimer, reduce visibility of test classes Co-authored-by: jack-berg <[email protected]>
- Loading branch information
Showing
15 changed files
with
892 additions
and
75 deletions.
There are no files selected for viewing
This file contains 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 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 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
36 changes: 36 additions & 0 deletions
36
...main/java/io/opentelemetry/sdk/metrics/internal/aggregator/ExponentialBucketStrategy.java
This file contains 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,36 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.sdk.metrics.internal.aggregator; | ||
|
||
import io.opentelemetry.sdk.metrics.internal.state.ExponentialCounterFactory; | ||
|
||
/** The configuration for how to create exponential histogram buckets. */ | ||
final class ExponentialBucketStrategy { | ||
/** Starting scale of exponential buckets. */ | ||
private final int scale; | ||
/** The maximum number of buckets that will be used for positive or negative recordings. */ | ||
private final int maxBuckets; | ||
/** The mechanism of constructing and copying buckets. */ | ||
private final ExponentialCounterFactory counterFactory; | ||
|
||
private ExponentialBucketStrategy( | ||
int scale, int maxBuckets, ExponentialCounterFactory counterFactory) { | ||
this.scale = scale; | ||
this.maxBuckets = maxBuckets; | ||
this.counterFactory = counterFactory; | ||
} | ||
|
||
/** Constructs fresh new buckets with default settings. */ | ||
DoubleExponentialHistogramBuckets newBuckets() { | ||
return new DoubleExponentialHistogramBuckets(scale, maxBuckets, counterFactory); | ||
} | ||
|
||
/** Create a new strategy for generating Exponential Buckets. */ | ||
static ExponentialBucketStrategy newStrategy( | ||
int scale, int maxBuckets, ExponentialCounterFactory counterFactory) { | ||
return new ExponentialBucketStrategy(scale, maxBuckets, counterFactory); | ||
} | ||
} |
Oops, something went wrong.