diff --git a/module/spring-boot-micrometer-metrics/src/main/java/org/springframework/boot/micrometer/metrics/autoconfigure/export/otlp/OtlpMetricsProperties.java b/module/spring-boot-micrometer-metrics/src/main/java/org/springframework/boot/micrometer/metrics/autoconfigure/export/otlp/OtlpMetricsProperties.java index 62577bdfdcb..770b824ef3e 100644 --- a/module/spring-boot-micrometer-metrics/src/main/java/org/springframework/boot/micrometer/metrics/autoconfigure/export/otlp/OtlpMetricsProperties.java +++ b/module/spring-boot-micrometer-metrics/src/main/java/org/springframework/boot/micrometer/metrics/autoconfigure/export/otlp/OtlpMetricsProperties.java @@ -86,6 +86,12 @@ public class OtlpMetricsProperties extends StepRegistryProperties { */ private final Map 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. */ diff --git a/module/spring-boot-micrometer-metrics/src/main/java/org/springframework/boot/micrometer/metrics/autoconfigure/export/otlp/OtlpMetricsPropertiesConfigAdapter.java b/module/spring-boot-micrometer-metrics/src/main/java/org/springframework/boot/micrometer/metrics/autoconfigure/export/otlp/OtlpMetricsPropertiesConfigAdapter.java index 80dfe0f2f7b..3a6bebeb146 100644 --- a/module/spring-boot-micrometer-metrics/src/main/java/org/springframework/boot/micrometer/metrics/autoconfigure/export/otlp/OtlpMetricsPropertiesConfigAdapter.java +++ b/module/spring-boot-micrometer-metrics/src/main/java/org/springframework/boot/micrometer/metrics/autoconfigure/export/otlp/OtlpMetricsPropertiesConfigAdapter.java @@ -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 Getter> perMeter(Getter getter) { return (properties) -> { if (CollectionUtils.isEmpty(properties.getMeter())) { diff --git a/module/spring-boot-micrometer-metrics/src/test/java/org/springframework/boot/micrometer/metrics/autoconfigure/export/otlp/OtlpMetricsPropertiesConfigAdapterTests.java b/module/spring-boot-micrometer-metrics/src/test/java/org/springframework/boot/micrometer/metrics/autoconfigure/export/otlp/OtlpMetricsPropertiesConfigAdapterTests.java index 2fe0e850b73..ba30cf1ec06 100644 --- a/module/spring-boot-micrometer-metrics/src/test/java/org/springframework/boot/micrometer/metrics/autoconfigure/export/otlp/OtlpMetricsPropertiesConfigAdapterTests.java +++ b/module/spring-boot-micrometer-metrics/src/test/java/org/springframework/boot/micrometer/metrics/autoconfigure/export/otlp/OtlpMetricsPropertiesConfigAdapterTests.java @@ -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);