Browse Source

Add support for configuring publishMaxGaugeForHistograms

See https://github.com/micrometer-metrics/micrometer/pull/6159
See gh-49242
pull/49278/head
Tommy Ludwig 4 weeks ago committed by Stéphane Nicoll
parent
commit
3c028759a2
  1. 14
      module/spring-boot-micrometer-metrics/src/main/java/org/springframework/boot/micrometer/metrics/autoconfigure/export/otlp/OtlpMetricsProperties.java
  2. 6
      module/spring-boot-micrometer-metrics/src/main/java/org/springframework/boot/micrometer/metrics/autoconfigure/export/otlp/OtlpMetricsPropertiesConfigAdapter.java
  3. 18
      module/spring-boot-micrometer-metrics/src/test/java/org/springframework/boot/micrometer/metrics/autoconfigure/export/otlp/OtlpMetricsPropertiesConfigAdapterTests.java

14
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 { @@ -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 { @@ -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.
*/

6
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 @@ -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())) {

18
module/spring-boot-micrometer-metrics/src/test/java/org/springframework/boot/micrometer/metrics/autoconfigure/export/otlp/OtlpMetricsPropertiesConfigAdapterTests.java

@ -219,6 +219,24 @@ class OtlpMetricsPropertiesConfigAdapterTests { @@ -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);

Loading…
Cancel
Save