Browse Source

Polish "Add support for configuring publishMaxGaugeForHistograms"

See gh-49242
pull/49278/head
Stéphane Nicoll 4 weeks ago
parent
commit
53e7503fd4
  1. 27
      module/spring-boot-micrometer-metrics/src/main/java/org/springframework/boot/micrometer/metrics/autoconfigure/export/otlp/OtlpMetricsProperties.java
  2. 12
      module/spring-boot-micrometer-metrics/src/main/java/org/springframework/boot/micrometer/metrics/autoconfigure/export/otlp/OtlpMetricsPropertiesConfigAdapter.java
  3. 36
      module/spring-boot-micrometer-metrics/src/test/java/org/springframework/boot/micrometer/metrics/autoconfigure/export/otlp/OtlpMetricsPropertiesConfigAdapterTests.java

27
module/spring-boot-micrometer-metrics/src/main/java/org/springframework/boot/micrometer/metrics/autoconfigure/export/otlp/OtlpMetricsProperties.java

@ -65,6 +65,11 @@ public class OtlpMetricsProperties extends StepRegistryProperties { @@ -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 { @@ -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 { @@ -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 { @@ -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.
*/

12
module/spring-boot-micrometer-metrics/src/main/java/org/springframework/boot/micrometer/metrics/autoconfigure/export/otlp/OtlpMetricsPropertiesConfigAdapter.java

@ -106,6 +106,12 @@ class OtlpMetricsPropertiesConfigAdapter extends StepRegistryPropertiesConfigAda @@ -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 @@ -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())) {

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

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

Loading…
Cancel
Save