-
Notifications
You must be signed in to change notification settings - Fork 851
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Memory mode: Adding support for synchronous instruments - explicit hi…
…stogram (#6153) Co-authored-by: jack-berg <[email protected]>
- Loading branch information
Showing
13 changed files
with
659 additions
and
55 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
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
62 changes: 62 additions & 0 deletions
62
...ava/io/opentelemetry/sdk/metrics/internal/state/tester/ExplicitBucketHistogramTester.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,62 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.sdk.metrics.internal.state.tester; | ||
|
||
import io.opentelemetry.api.common.Attributes; | ||
import io.opentelemetry.api.metrics.DoubleHistogram; | ||
import io.opentelemetry.sdk.metrics.Aggregation; | ||
import io.opentelemetry.sdk.metrics.SdkMeterProvider; | ||
import io.opentelemetry.sdk.metrics.internal.aggregator.ExplicitBucketHistogramUtils; | ||
import io.opentelemetry.sdk.metrics.internal.state.TestInstrumentType.InstrumentTester; | ||
import io.opentelemetry.sdk.metrics.internal.state.TestInstrumentType.TestInstrumentsState; | ||
import java.util.List; | ||
import java.util.Random; | ||
|
||
public class ExplicitBucketHistogramTester implements InstrumentTester { | ||
|
||
static class ExplicitHistogramState implements TestInstrumentsState { | ||
public double maxBucketValue; | ||
DoubleHistogram doubleHistogram; | ||
} | ||
|
||
private static final int measurementsPerAttributeSet = 1_000; | ||
|
||
@Override | ||
public Aggregation testedAggregation() { | ||
return Aggregation.explicitBucketHistogram(); | ||
} | ||
|
||
@Override | ||
public TestInstrumentsState buildInstruments( | ||
double instrumentCount, | ||
SdkMeterProvider sdkMeterProvider, | ||
List<Attributes> attributesList, | ||
Random random) { | ||
ExplicitHistogramState state = new ExplicitHistogramState(); | ||
state.doubleHistogram = | ||
sdkMeterProvider.get("meter").histogramBuilder("test.explicit.histogram").build(); | ||
state.maxBucketValue = | ||
ExplicitBucketHistogramUtils.DEFAULT_HISTOGRAM_BUCKET_BOUNDARIES.get( | ||
ExplicitBucketHistogramUtils.DEFAULT_HISTOGRAM_BUCKET_BOUNDARIES.size() - 1); | ||
return state; | ||
} | ||
|
||
@SuppressWarnings("ForLoopReplaceableByForEach") // This is for GC sensitivity testing: no streams | ||
@Override | ||
public void recordValuesInInstruments( | ||
TestInstrumentsState testInstrumentsState, List<Attributes> attributesList, Random random) { | ||
|
||
ExplicitHistogramState state = (ExplicitHistogramState) testInstrumentsState; | ||
|
||
for (int j = 0; j < attributesList.size(); j++) { | ||
Attributes attributes = attributesList.get(j); | ||
for (int i = 0; i < measurementsPerAttributeSet; i++) { | ||
state.doubleHistogram.record( | ||
random.nextInt(Double.valueOf(state.maxBucketValue * 1.1).intValue()), attributes); | ||
} | ||
} | ||
} | ||
} |
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
35 changes: 35 additions & 0 deletions
35
...c/main/java/io/opentelemetry/sdk/metrics/internal/data/HistogramPointDataValidations.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,35 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.sdk.metrics.internal.data; | ||
|
||
import io.opentelemetry.sdk.metrics.data.HistogramPointData; | ||
import java.util.List; | ||
|
||
/** | ||
* Validations for {@link HistogramPointData}. | ||
* | ||
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change | ||
* at any time. | ||
*/ | ||
final class HistogramPointDataValidations { | ||
|
||
private HistogramPointDataValidations() {} | ||
|
||
static void validateIsStrictlyIncreasing(List<Double> xs) { | ||
for (int i = 0; i < xs.size() - 1; i++) { | ||
if (xs.get(i).compareTo(xs.get(i + 1)) >= 0) { | ||
throw new IllegalArgumentException("invalid boundaries: " + xs); | ||
} | ||
} | ||
} | ||
|
||
static void validateFiniteBoundaries(List<Double> boundaries) { | ||
if (!boundaries.isEmpty() | ||
&& (boundaries.get(0).isInfinite() || boundaries.get(boundaries.size() - 1).isInfinite())) { | ||
throw new IllegalArgumentException("invalid boundaries: contains explicit +/-Inf"); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.