io.opentelemetry.sdk.metrics.internal.view.ExplicitBucketHistogramAggregation Maven / Gradle / Ivy
/*
* 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.data.PointData;
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.
*
* 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 bucketBoundaries) {
return new ExplicitBucketHistogramAggregation(bucketBoundaries);
}
private final List bucketBoundaries;
private final double[] bucketBoundaryArray;
private ExplicitBucketHistogramAggregation(List 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 Aggregator createAggregator(
InstrumentDescriptor instrumentDescriptor, ExemplarFilter exemplarFilter) {
return (Aggregator)
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() + ")";
}
}