Skip to content
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

Micrometer bridge: interpret no SLO config as no buckets advice #8856

Merged
merged 1 commit into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import io.opentelemetry.extension.incubator.metrics.ExtendedDoubleHistogramBuilder;
import java.util.ArrayList;
import java.util.List;
import java.util.NavigableSet;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;

Expand All @@ -27,22 +28,23 @@ static void setExplicitBucketsIfConfigured(
DoubleHistogramBuilder builder,
DistributionStatisticConfig config,
@Nullable TimeUnit timeUnit) {
double[] buckets = config.getServiceLevelObjectiveBoundaries();
if (buckets == null || !(builder instanceof ExtendedDoubleHistogramBuilder)) {
if (!(builder instanceof ExtendedDoubleHistogramBuilder)) {
return;
}
NavigableSet<Double> buckets = config.getHistogramBuckets(false);
ExtendedDoubleHistogramBuilder extendedBuilder = (ExtendedDoubleHistogramBuilder) builder;
extendedBuilder.setAdvice(
advice -> advice.setExplicitBucketBoundaries(computeBuckets(buckets, timeUnit)));
}

private static List<Double> computeBuckets(double[] buckets, @Nullable TimeUnit timeUnit) {
if (buckets.length == 0) {
private static List<Double> computeBuckets(
NavigableSet<Double> buckets, @Nullable TimeUnit timeUnit) {
if (buckets.isEmpty()) {
return emptyList();
}
// micrometer Timers always specify buckets in nanoseconds, we need to convert them to base unit
double timeUnitMultiplier = timeUnit == null ? 1.0 : TimeUtils.nanosToUnit(1, timeUnit);
List<Double> result = new ArrayList<>(buckets.length);
List<Double> result = new ArrayList<>(buckets.size());
for (double b : buckets) {
result.add(b * timeUnitMultiplier);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,13 @@
import io.micrometer.core.instrument.DistributionSummary;
import io.micrometer.core.instrument.Metrics;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import io.opentelemetry.sdk.metrics.internal.aggregator.ExplicitBucketHistogramUtils;
import org.assertj.core.api.AbstractIterableAssert;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public abstract class AbstractDistributionSummaryTest {

static final double[] DEFAULT_BUCKETS =
ExplicitBucketHistogramUtils.DEFAULT_HISTOGRAM_BUCKET_BOUNDARIES.stream()
.mapToDouble(d -> d)
.toArray();
static final double[] NO_BUCKETS = new double[0];

protected abstract InstrumentationExtension testing();

Expand Down Expand Up @@ -65,7 +61,7 @@ void testMicrometerDistributionSummary() {
.hasSum(7)
.hasCount(3)
.hasAttributes(attributeEntry("tag", "value"))
.hasBucketBoundaries(DEFAULT_BUCKETS)))));
.hasBucketBoundaries(NO_BUCKETS)))));
testing()
.waitAndAssertMetrics(
INSTRUMENTATION_NAME,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import io.opentelemetry.sdk.metrics.data.HistogramPointData;
import io.opentelemetry.sdk.metrics.internal.aggregator.ExplicitBucketHistogramUtils;
import java.time.Duration;
import java.util.concurrent.TimeUnit;
import org.assertj.core.api.AbstractIterableAssert;
Expand All @@ -25,10 +24,7 @@
@SuppressWarnings("PreferJavaTimeOverload")
public abstract class AbstractTimerTest {

static final double[] DEFAULT_BUCKETS =
ExplicitBucketHistogramUtils.DEFAULT_HISTOGRAM_BUCKET_BOUNDARIES.stream()
.mapToDouble(d -> d)
.toArray();
static final double[] NO_BUCKETS = new double[0];

protected abstract InstrumentationExtension testing();

Expand Down Expand Up @@ -63,7 +59,7 @@ void testTimer() {
.hasSum(42)
.hasCount(1)
.hasAttributes(attributeEntry("tag", "value"))
.hasBucketBoundaries(DEFAULT_BUCKETS)))));
.hasBucketBoundaries(NO_BUCKETS)))));
testing()
.waitAndAssertMetrics(
INSTRUMENTATION_NAME,
Expand Down