From fcc327c1dd3ac32fd9ffdb24f6dfdabc7444faa6 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 27 Jan 2026 10:46:33 +0000 Subject: [PATCH] Simplify PropertiesMeterFilter lookupWithFallbackToAll is the only method that's called with a non-null default value. Default value support can be removed from the other lookup methods. Closes gh-48986 --- .../metrics/PropertiesMeterFilter.java | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/PropertiesMeterFilter.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/PropertiesMeterFilter.java index 085d3af48e1..5089fb1a398 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/PropertiesMeterFilter.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/PropertiesMeterFilter.java @@ -20,7 +20,6 @@ import java.util.Arrays; import java.util.Map; import java.util.Map.Entry; import java.util.Objects; -import java.util.function.Supplier; import io.micrometer.core.instrument.Meter; import io.micrometer.core.instrument.Meter.Id; @@ -86,12 +85,9 @@ public class PropertiesMeterFilter implements MeterFilter { return DistributionStatisticConfig.builder() .percentilesHistogram(lookupWithFallbackToAll(distribution.getPercentilesHistogram(), id, null)) .percentiles(lookupWithFallbackToAll(distribution.getPercentiles(), id, null)) - .serviceLevelObjectives( - convertServiceLevelObjectives(id.getType(), lookup(distribution.getSlo(), id, null))) - .minimumExpectedValue( - convertMeterValue(id.getType(), lookup(distribution.getMinimumExpectedValue(), id, null))) - .maximumExpectedValue( - convertMeterValue(id.getType(), lookup(distribution.getMaximumExpectedValue(), id, null))) + .serviceLevelObjectives(convertServiceLevelObjectives(id.getType(), lookup(distribution.getSlo(), id))) + .minimumExpectedValue(convertMeterValue(id.getType(), lookup(distribution.getMinimumExpectedValue(), id))) + .maximumExpectedValue(convertMeterValue(id.getType(), lookup(distribution.getMaximumExpectedValue(), id))) .expiry(lookupWithFallbackToAll(distribution.getExpiry(), id, null)) .bufferLength(lookupWithFallbackToAll(distribution.getBufferLength(), id, null)) .build() @@ -114,21 +110,22 @@ public class PropertiesMeterFilter implements MeterFilter { return (value != null) ? MeterValue.valueOf(value).getValue(meterType) : null; } - private T lookup(Map values, Id id, T defaultValue) { + private T lookup(Map values, Id id) { if (values.isEmpty()) { - return defaultValue; + return null; } - return doLookup(values, id, () -> defaultValue); + return doLookup(values, id); } private T lookupWithFallbackToAll(Map values, Id id, T defaultValue) { if (values.isEmpty()) { return defaultValue; } - return doLookup(values, id, () -> values.getOrDefault("all", defaultValue)); + T result = doLookup(values, id); + return (result != null) ? result : values.getOrDefault("all", defaultValue); } - private T doLookup(Map values, Id id, Supplier defaultValue) { + private T doLookup(Map values, Id id) { String name = id.getName(); while (StringUtils.hasLength(name)) { T result = values.get(name); @@ -139,7 +136,7 @@ public class PropertiesMeterFilter implements MeterFilter { name = (lastDot != -1) ? name.substring(0, lastDot) : ""; } - return defaultValue.get(); + return null; } }