Skip to content

Commit

Permalink
Hide DistributionStatisticsConfig changes behind a config flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Rzeszutek authored and jonatan-ivanov committed Mar 18, 2022
1 parent 09f2c52 commit 79693ed
Show file tree
Hide file tree
Showing 3 changed files with 219 additions and 158 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@

import static io.micrometer.core.instrument.config.MeterRegistryConfigValidator.checkAll;
import static io.micrometer.core.instrument.config.MeterRegistryConfigValidator.checkRequired;
import static io.micrometer.core.instrument.config.validate.PropertyValidator.*;
import static io.micrometer.core.instrument.config.validate.PropertyValidator.getBoolean;
import static io.micrometer.core.instrument.config.validate.PropertyValidator.getDuration;
import static io.micrometer.core.instrument.config.validate.PropertyValidator.getSecret;
import static io.micrometer.core.instrument.config.validate.PropertyValidator.getString;
import static io.micrometer.core.instrument.config.validate.PropertyValidator.getUrlString;

/**
* Configuration for {@link SignalFxMeterRegistry}.
Expand All @@ -43,14 +47,10 @@ default String accessToken() {
}

/**
* Returns {@code true} if the signalfx registry should emit histogram buckets as
* CumulativeCounter instead of Gauge (as it is by default).
*
* @return {@code true} if the signalfx registry should emit histogram buckets as
* CumulativeCounter instead of Gauge (as it is by default).
* @return {@code true} if the SignalFx registry should emit cumulative histogram buckets.
*/
default Boolean fixHistogramBucketsType() {
return getBoolean(this, "fixHistogramBucketsType").orElse(false);
default boolean publishCumulativeHistogram() {
return getBoolean(this, "publishCumulativeHistogram").orElse(false);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public class SignalFxMeterRegistry extends StepMeterRegistry {
private final HttpEventProtobufReceiverFactory eventReceiverFactory;
private final Set<OnSendErrorHandler> onSendErrorHandlerCollection = Collections.singleton(
metricError -> this.logger.warn("failed to send metrics: {}", metricError.getMessage()));
private final boolean fixHistogramBucketsType;
private final boolean publishCumulativeHistograms;

public SignalFxMeterRegistry(SignalFxConfig config, Clock clock) {
this(config, clock, DEFAULT_THREAD_FACTORY);
Expand All @@ -96,7 +96,7 @@ public SignalFxMeterRegistry(SignalFxConfig config, Clock clock, ThreadFactory t
SignalFxReceiverEndpoint signalFxEndpoint = new SignalFxEndpoint(apiUri.getScheme(), apiUri.getHost(), port);
this.dataPointReceiverFactory = new HttpDataPointProtobufReceiverFactory(signalFxEndpoint);
this.eventReceiverFactory = new HttpEventProtobufReceiverFactory(signalFxEndpoint);
this.fixHistogramBucketsType = config.fixHistogramBucketsType();
this.publishCumulativeHistograms = config.publishCumulativeHistogram();

config().namingConvention(new SignalFxNamingConvention());

Expand Down Expand Up @@ -136,13 +136,19 @@ protected void publish() {

@Override
protected Timer newTimer(Meter.Id id, DistributionStatisticConfig distributionStatisticConfig, PauseDetector pauseDetector) {
if (!publishCumulativeHistograms) {
return super.newTimer(id, distributionStatisticConfig, pauseDetector);
}
Timer timer = new SignalfxTimer(id, clock, distributionStatisticConfig, pauseDetector, getBaseTimeUnit(), config.step().toMillis());
HistogramGauges.registerWithCommonFormat(timer, this);
return timer;
}

@Override
protected DistributionSummary newDistributionSummary(Meter.Id id, DistributionStatisticConfig distributionStatisticConfig, double scale) {
if (!publishCumulativeHistograms) {
return super.newDistributionSummary(id, distributionStatisticConfig, scale);
}
DistributionSummary summary = new SignalfxDistributionSummary(id, clock, distributionStatisticConfig, scale, config.step().toMillis());
HistogramGauges.registerWithCommonFormat(summary, this);
return summary;
Expand Down Expand Up @@ -205,7 +211,7 @@ Stream<SignalFxProtocolBuffers.DataPoint.Builder> addTimeGauge(TimeGauge timeGau
}

Stream<SignalFxProtocolBuffers.DataPoint.Builder> addGauge(Gauge gauge) {
if (fixHistogramBucketsType
if (publishCumulativeHistograms
&& gauge.getId().syntheticAssociation() != null
&& gauge.getId().getName().endsWith(".histogram")) {
return Stream.of(addDatapoint(gauge, CUMULATIVE_COUNTER, null, gauge.value()));
Expand Down
Loading

0 comments on commit 79693ed

Please sign in to comment.