Polish "Add support for configuring publishMaxGaugeForHistograms"

See gh-49242
This commit is contained in:
Stéphane Nicoll
2026-02-18 13:59:32 +01:00
parent 3c028759a2
commit 53e7503fd4
3 changed files with 37 additions and 38 deletions
@@ -65,6 +65,11 @@ public class OtlpMetricsProperties extends StepRegistryProperties {
*/
private HistogramFlavor histogramFlavor = HistogramFlavor.EXPLICIT_BUCKET_HISTOGRAM;
/**
* Whether to publish a separate gauge for the max value of histogram-based meters.
*/
private @Nullable Boolean publishMaxGaugeForHistograms;
/**
* Max scale to use for exponential histograms, if configured.
*/
@@ -86,12 +91,6 @@ public class OtlpMetricsProperties extends StepRegistryProperties {
*/
private final Map<String, Meter> meter = new LinkedHashMap<>();
/**
* Whether to publish a separate gauge for the max value of histogram-based meters. A
* null value defers to Micrometer's default.
*/
private @Nullable Boolean publishMaxGaugeForHistograms;
public @Nullable String getUrl() {
return this.url;
}
@@ -132,6 +131,14 @@ public class OtlpMetricsProperties extends StepRegistryProperties {
this.histogramFlavor = histogramFlavor;
}
public @Nullable Boolean getPublishMaxGaugeForHistograms() {
return this.publishMaxGaugeForHistograms;
}
public void setPublishMaxGaugeForHistograms(@Nullable Boolean publishMaxGaugeForHistograms) {
this.publishMaxGaugeForHistograms = publishMaxGaugeForHistograms;
}
public int getMaxScale() {
return this.maxScale;
}
@@ -160,14 +167,6 @@ public class OtlpMetricsProperties extends StepRegistryProperties {
return this.meter;
}
public @Nullable Boolean getPublishMaxGaugeForHistograms() {
return this.publishMaxGaugeForHistograms;
}
public void setPublishMaxGaugeForHistograms(@Nullable Boolean publishMaxGaugeForHistograms) {
this.publishMaxGaugeForHistograms = publishMaxGaugeForHistograms;
}
/**
* Per-meter settings.
*/
@@ -106,6 +106,12 @@ class OtlpMetricsPropertiesConfigAdapter extends StepRegistryPropertiesConfigAda
return obtain(perMeter(Meter::getMaxBucketCount), OtlpConfig.super::maxBucketsPerMeter);
}
@Override
public boolean publishMaxGaugeForHistograms() {
return obtain(OtlpMetricsProperties::getPublishMaxGaugeForHistograms,
OtlpConfig.super::publishMaxGaugeForHistograms);
}
@Override
public int maxScale() {
return obtain(OtlpMetricsProperties::getMaxScale, OtlpConfig.super::maxScale);
@@ -121,12 +127,6 @@ class OtlpMetricsPropertiesConfigAdapter extends StepRegistryPropertiesConfigAda
return obtain(OtlpMetricsProperties::getBaseTimeUnit, OtlpConfig.super::baseTimeUnit);
}
@Override
public boolean publishMaxGaugeForHistograms() {
return obtain(OtlpMetricsProperties::getPublishMaxGaugeForHistograms,
OtlpConfig.super::publishMaxGaugeForHistograms);
}
private <V> Getter<OtlpMetricsProperties, Map<String, V>> perMeter(Getter<Meter, V> getter) {
return (properties) -> {
if (CollectionUtils.isEmpty(properties.getMeter())) {
@@ -137,6 +137,24 @@ class OtlpMetricsPropertiesConfigAdapterTests {
HistogramFlavor.BASE2_EXPONENTIAL_BUCKET_HISTOGRAM);
}
@Test
void useDefaultPublishMaxGaugeForHistogramsWhenNotSet() {
assertThat(this.properties.getPublishMaxGaugeForHistograms()).isNull();
assertThat(createAdapter().publishMaxGaugeForHistograms()).isTrue();
}
@Test
void whenDefaultPublishMaxGaugeForHistogramsIsSetAdapterUsesIt() {
this.properties.setPublishMaxGaugeForHistograms(false);
assertThat(createAdapter().publishMaxGaugeForHistograms()).isFalse();
}
@Test
void whenAggregationTemporalityIsSetToDeltaThenPublishMaxGaugeForHistogramsDefaultChanges() {
this.properties.setAggregationTemporality(AggregationTemporality.DELTA);
assertThat(createAdapter().publishMaxGaugeForHistograms()).isFalse();
}
@Test
void whenPropertiesMaxScaleIsNotSetAdapterMaxScaleReturns20() {
assertThat(createAdapter().maxScale()).isEqualTo(20);
@@ -219,24 +237,6 @@ class OtlpMetricsPropertiesConfigAdapterTests {
assertThat(createAdapter().resourceAttributes()).doesNotContainKey("service.namespace");
}
@Test
void useDefaultPublishMaxGaugeForHistogramsWhenNotSet() {
assertThat(this.properties.getPublishMaxGaugeForHistograms()).isNull();
assertThat(createAdapter().publishMaxGaugeForHistograms()).isTrue();
}
@Test
void whenDefaultPublishMaxGaugeForHistogramsIsSetAdapterUsesIt() {
this.properties.setPublishMaxGaugeForHistograms(false);
assertThat(createAdapter().publishMaxGaugeForHistograms()).isFalse();
}
@Test
void whenAggregationTemporalityIsSetToDeltaThenPublishMaxGaugeForHistogramsDefaultChanges() {
this.properties.setAggregationTemporality(AggregationTemporality.DELTA);
assertThat(createAdapter().publishMaxGaugeForHistograms()).isFalse();
}
private OtlpMetricsPropertiesConfigAdapter createAdapter() {
return new OtlpMetricsPropertiesConfigAdapter(this.properties, this.openTelemetryProperties,
this.connectionDetails, this.environment);