forked from open-telemetry/opentelemetry-java
/
ExplicitBucketHistogramAggregation.java
78 lines (67 loc) · 2.78 KB
/
ExplicitBucketHistogramAggregation.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
package io.opentelemetry.sdk.metrics.internal.view;
import io.opentelemetry.sdk.common.Clock;
import io.opentelemetry.sdk.metrics.Aggregation;
import io.opentelemetry.sdk.metrics.data.ExemplarData;
import io.opentelemetry.sdk.metrics.internal.aggregator.Aggregator;
import io.opentelemetry.sdk.metrics.internal.aggregator.AggregatorFactory;
import io.opentelemetry.sdk.metrics.internal.aggregator.DoubleExplicitBucketHistogramAggregator;
import io.opentelemetry.sdk.metrics.internal.aggregator.ExplicitBucketHistogramUtils;
import io.opentelemetry.sdk.metrics.internal.descriptor.InstrumentDescriptor;
import io.opentelemetry.sdk.metrics.internal.exemplar.ExemplarFilter;
import io.opentelemetry.sdk.metrics.internal.exemplar.ExemplarReservoir;
import java.util.List;
/**
* Explicit bucket histogram aggregation configuration.
*
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change
* at any time.
*/
public final class ExplicitBucketHistogramAggregation implements Aggregation, AggregatorFactory {
private static final Aggregation DEFAULT =
new ExplicitBucketHistogramAggregation(
ExplicitBucketHistogramUtils.DEFAULT_HISTOGRAM_BUCKET_BOUNDARIES);
public static Aggregation getDefault() {
return DEFAULT;
}
public static Aggregation create(List<Double> bucketBoundaries) {
return new ExplicitBucketHistogramAggregation(bucketBoundaries);
}
private final List<Double> bucketBoundaries;
private final double[] bucketBoundaryArray;
private ExplicitBucketHistogramAggregation(List<Double> bucketBoundaries) {
this.bucketBoundaries = bucketBoundaries;
// We need to fail here if our bucket boundaries are ill-configured.
this.bucketBoundaryArray = ExplicitBucketHistogramUtils.createBoundaryArray(bucketBoundaries);
}
@Override
@SuppressWarnings("unchecked")
public <T, U extends ExemplarData> Aggregator<T, U> createAggregator(
InstrumentDescriptor instrumentDescriptor, ExemplarFilter exemplarFilter) {
return (Aggregator<T, U>)
new DoubleExplicitBucketHistogramAggregator(
bucketBoundaryArray,
() ->
ExemplarReservoir.filtered(
exemplarFilter,
ExemplarReservoir.histogramBucketReservoir(
Clock.getDefault(), bucketBoundaries)));
}
@Override
public boolean isCompatibleWithInstrument(InstrumentDescriptor instrumentDescriptor) {
switch (instrumentDescriptor.getType()) {
case COUNTER:
case HISTOGRAM:
return true;
default:
return false;
}
}
@Override
public String toString() {
return "ExplicitBucketHistogramAggregation(" + bucketBoundaries.toString() + ")";
}
}