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

Add LongHistogramAdviceConfigurer to improve api surface types #5689

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
@@ -0,0 +1,16 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.extension.incubator.metrics;

import io.opentelemetry.api.metrics.DoubleHistogram;
import java.util.List;

/** Configure advice for implementations of {@link DoubleHistogram}. */
public interface DoubleHistogramAdviceConfigurer {

/** Specify recommended set of explicit bucket boundaries for this histogram. */
DoubleHistogramAdviceConfigurer setExplicitBucketBoundaries(List<Double> bucketBoundaries);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
public interface ExtendedDoubleHistogramBuilder extends DoubleHistogramBuilder {

/** Specify advice for histogram implementations. */
default DoubleHistogramBuilder setAdvice(Consumer<HistogramAdviceConfigurer> adviceConsumer) {
default DoubleHistogramBuilder setAdvice(
Consumer<DoubleHistogramAdviceConfigurer> adviceConsumer) {
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
public interface ExtendedLongHistogramBuilder extends LongHistogramBuilder {

/** Specify advice for histogram implementations. */
default LongHistogramBuilder setAdvice(Consumer<HistogramAdviceConfigurer> adviceConsumer) {
default LongHistogramBuilder setAdvice(Consumer<LongHistogramAdviceConfigurer> adviceConsumer) {
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@

package io.opentelemetry.extension.incubator.metrics;

import io.opentelemetry.api.metrics.DoubleHistogram;
import io.opentelemetry.api.metrics.LongHistogram;
import java.util.List;

/** Configure advice for implementations of {@link LongHistogram} and {@link DoubleHistogram}. */
public interface HistogramAdviceConfigurer {
/** Configure advice for implementations of {@link LongHistogram}. */
public interface LongHistogramAdviceConfigurer {

/** Specify recommended set of explicit bucket boundaries for this histogram. */
HistogramAdviceConfigurer setExplicitBucketBoundaries(List<Double> bucketBoundaries);
LongHistogramAdviceConfigurer setExplicitBucketBoundaries(List<Long> bucketBoundaries);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import io.opentelemetry.api.metrics.DoubleHistogram;
import io.opentelemetry.api.metrics.LongHistogramBuilder;
import io.opentelemetry.context.Context;
import io.opentelemetry.extension.incubator.metrics.DoubleHistogramAdviceConfigurer;
import io.opentelemetry.extension.incubator.metrics.ExtendedDoubleHistogramBuilder;
import io.opentelemetry.extension.incubator.metrics.HistogramAdviceConfigurer;
import io.opentelemetry.sdk.internal.ThrottlingLogger;
import io.opentelemetry.sdk.metrics.internal.descriptor.Advice;
import io.opentelemetry.sdk.metrics.internal.descriptor.InstrumentDescriptor;
Expand Down Expand Up @@ -58,7 +58,7 @@ public void record(double value) {

static final class SdkDoubleHistogramBuilder
extends AbstractInstrumentBuilder<SdkDoubleHistogramBuilder>
implements ExtendedDoubleHistogramBuilder, HistogramAdviceConfigurer {
implements ExtendedDoubleHistogramBuilder, DoubleHistogramAdviceConfigurer {

SdkDoubleHistogramBuilder(
MeterProviderSharedState meterProviderSharedState,
Expand All @@ -80,7 +80,8 @@ protected SdkDoubleHistogramBuilder getThis() {
}

@Override
public SdkDoubleHistogramBuilder setAdvice(Consumer<HistogramAdviceConfigurer> adviceConsumer) {
public SdkDoubleHistogramBuilder setAdvice(
Consumer<DoubleHistogramAdviceConfigurer> adviceConsumer) {
adviceConsumer.accept(this);
return this;
}
Expand All @@ -96,7 +97,8 @@ public LongHistogramBuilder ofLongs() {
}

@Override
public HistogramAdviceConfigurer setExplicitBucketBoundaries(List<Double> bucketBoundaries) {
public DoubleHistogramAdviceConfigurer setExplicitBucketBoundaries(
List<Double> bucketBoundaries) {
setAdvice(Advice.create(bucketBoundaries));
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import io.opentelemetry.api.metrics.LongHistogram;
import io.opentelemetry.context.Context;
import io.opentelemetry.extension.incubator.metrics.ExtendedLongHistogramBuilder;
import io.opentelemetry.extension.incubator.metrics.HistogramAdviceConfigurer;
import io.opentelemetry.extension.incubator.metrics.LongHistogramAdviceConfigurer;
import io.opentelemetry.sdk.internal.ThrottlingLogger;
import io.opentelemetry.sdk.metrics.internal.descriptor.Advice;
import io.opentelemetry.sdk.metrics.internal.descriptor.InstrumentDescriptor;
Expand All @@ -20,6 +20,7 @@
import java.util.function.Consumer;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;

final class SdkLongHistogram extends AbstractInstrument implements LongHistogram {
private static final Logger logger = Logger.getLogger(SdkLongHistogram.class.getName());
Expand Down Expand Up @@ -57,7 +58,7 @@ public void record(long value) {

static final class SdkLongHistogramBuilder
extends AbstractInstrumentBuilder<SdkLongHistogramBuilder>
implements ExtendedLongHistogramBuilder, HistogramAdviceConfigurer {
implements ExtendedLongHistogramBuilder, LongHistogramAdviceConfigurer {

SdkLongHistogramBuilder(
MeterProviderSharedState meterProviderSharedState,
Expand All @@ -83,7 +84,8 @@ protected SdkLongHistogramBuilder getThis() {
}

@Override
public SdkLongHistogramBuilder setAdvice(Consumer<HistogramAdviceConfigurer> adviceConsumer) {
public SdkLongHistogramBuilder setAdvice(
Consumer<LongHistogramAdviceConfigurer> adviceConsumer) {
adviceConsumer.accept(this);
return this;
}
Expand All @@ -94,8 +96,10 @@ public SdkLongHistogram build() {
}

@Override
public HistogramAdviceConfigurer setExplicitBucketBoundaries(List<Double> bucketBoundaries) {
setAdvice(Advice.create(bucketBoundaries));
public LongHistogramAdviceConfigurer setExplicitBucketBoundaries(List<Long> bucketBoundaries) {
List<Double> doubleBoundaries =
bucketBoundaries.stream().map(Long::doubleValue).collect(Collectors.toList());
setAdvice(Advice.create(doubleBoundaries));
return this;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,7 @@ private static Stream<Arguments> histogramsWithAdvice() {
meterProvider.get("meter").histogramBuilder("histogram").ofLongs())
.setAdvice(
advice ->
advice.setExplicitBucketBoundaries(
Arrays.asList(10.0, 20.0, 30.0)))
advice.setExplicitBucketBoundaries(Arrays.asList(10L, 20L, 30L)))
.build();
return build::record;
}));
Expand Down
Loading