mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-09-17 12:09:16 +00:00
Add support for configuring publishMaxGaugeForHistograms
See https://github.com/micrometer-metrics/micrometer/pull/6159 See gh-49242
This commit is contained in:
committed by
Stéphane Nicoll
parent
d70d6e863a
commit
3c028759a2
+14
@@ -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.
|
||||
*/
|
||||
|
||||
+6
@@ -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
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user