Add support for configuring publishMaxGaugeForHistograms

See https://github.com/micrometer-metrics/micrometer/pull/6159
See gh-49242
This commit is contained in:
Tommy Ludwig
2026-02-18 13:52:30 +01:00
committed by Stéphane Nicoll
parent d70d6e863a
commit 3c028759a2
3 changed files with 38 additions and 0 deletions
@@ -86,6 +86,12 @@ 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;
}
@@ -154,6 +160,14 @@ 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.
*/
@@ -121,6 +121,12 @@ 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())) {
@@ -219,6 +219,24 @@ 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);