Browse Source

Merge branch '3.5.x' into 4.0.x

Closes gh-48987
4.0.x
Andy Wilkinson 4 days ago
parent
commit
78fbd12510
  1. 25
      module/spring-boot-micrometer-metrics/src/main/java/org/springframework/boot/micrometer/metrics/autoconfigure/PropertiesMeterFilter.java

25
module/spring-boot-micrometer-metrics/src/main/java/org/springframework/boot/micrometer/metrics/autoconfigure/PropertiesMeterFilter.java

@ -20,7 +20,6 @@ import java.util.Arrays;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Objects; import java.util.Objects;
import java.util.function.Supplier;
import io.micrometer.core.instrument.Meter; import io.micrometer.core.instrument.Meter;
import io.micrometer.core.instrument.Meter.Id; import io.micrometer.core.instrument.Meter.Id;
@ -88,12 +87,9 @@ public class PropertiesMeterFilter implements MeterFilter {
return DistributionStatisticConfig.builder() return DistributionStatisticConfig.builder()
.percentilesHistogram(lookupWithFallbackToAll(distribution.getPercentilesHistogram(), id, null)) .percentilesHistogram(lookupWithFallbackToAll(distribution.getPercentilesHistogram(), id, null))
.percentiles(lookupWithFallbackToAll(distribution.getPercentiles(), id, null)) .percentiles(lookupWithFallbackToAll(distribution.getPercentiles(), id, null))
.serviceLevelObjectives( .serviceLevelObjectives(convertServiceLevelObjectives(id.getType(), lookup(distribution.getSlo(), id)))
convertServiceLevelObjectives(id.getType(), lookup(distribution.getSlo(), id, null))) .minimumExpectedValue(convertMeterValue(id.getType(), lookup(distribution.getMinimumExpectedValue(), id)))
.minimumExpectedValue( .maximumExpectedValue(convertMeterValue(id.getType(), lookup(distribution.getMaximumExpectedValue(), id)))
convertMeterValue(id.getType(), lookup(distribution.getMinimumExpectedValue(), id, null)))
.maximumExpectedValue(
convertMeterValue(id.getType(), lookup(distribution.getMaximumExpectedValue(), id, null)))
.expiry(lookupWithFallbackToAll(distribution.getExpiry(), id, null)) .expiry(lookupWithFallbackToAll(distribution.getExpiry(), id, null))
.bufferLength(lookupWithFallbackToAll(distribution.getBufferLength(), id, null)) .bufferLength(lookupWithFallbackToAll(distribution.getBufferLength(), id, null))
.build() .build()
@ -117,12 +113,11 @@ public class PropertiesMeterFilter implements MeterFilter {
return (value != null) ? MeterValue.valueOf(value).getValue(meterType) : null; return (value != null) ? MeterValue.valueOf(value).getValue(meterType) : null;
} }
private <T> @Nullable T lookup(Map<String, T> values, Id id, @Nullable T defaultValue) { private <T> @Nullable T lookup(Map<String, T> values, Id id) {
if (values.isEmpty()) { if (values.isEmpty()) {
return defaultValue; return null;
} }
Supplier<@Nullable T> getDefaultValue = () -> defaultValue; return doLookup(values, id);
return doLookup(values, id, getDefaultValue);
} }
@Contract("_, _, !null -> !null") @Contract("_, _, !null -> !null")
@ -130,11 +125,11 @@ public class PropertiesMeterFilter implements MeterFilter {
if (values.isEmpty()) { if (values.isEmpty()) {
return defaultValue; return defaultValue;
} }
Supplier<@Nullable T> getAllOrDefaultValue = () -> values.getOrDefault("all", defaultValue); @Nullable T result = doLookup(values, id);
return doLookup(values, id, getAllOrDefaultValue); return (result != null) ? result : values.getOrDefault("all", defaultValue);
} }
private <T> @Nullable T doLookup(Map<String, T> values, Id id, Supplier<@Nullable T> defaultValue) { private <T> @Nullable T doLookup(Map<String, T> values, Id id) {
String name = id.getName(); String name = id.getName();
while (StringUtils.hasLength(name)) { while (StringUtils.hasLength(name)) {
T result = values.get(name); T result = values.get(name);
@ -145,7 +140,7 @@ public class PropertiesMeterFilter implements MeterFilter {
name = (lastDot != -1) ? name.substring(0, lastDot) : ""; name = (lastDot != -1) ? name.substring(0, lastDot) : "";
} }
return defaultValue.get(); return null;
} }
} }

Loading…
Cancel
Save