Commit ccb964e8 authored by artsiom's avatar artsiom Committed by Andy Wilkinson

Drop support for "all" from management.metrics.distribution.sla

See gh-14684
parent ef7c2bc6
...@@ -192,10 +192,9 @@ public class MetricsProperties { ...@@ -192,10 +192,9 @@ public class MetricsProperties {
/** /**
* Specific SLA boundaries for meter IDs starting-with the specified name. The * Specific SLA boundaries for meter IDs starting-with the specified name. The
* longest match wins, the key `all` can also be used to configure all meters. * longest match wins. Counters will be published for each specified boundary.
* Counters will be published for each specified boundary. Values can be specified * Values can be specified as a long or as a Duration value (for timer meters,
* as a long or as a Duration value (for timer meters, defaulting to ms if no unit * defaulting to ms if no unit specified).
* specified).
*/ */
private final Map<String, ServiceLevelAgreementBoundary[]> sla = new LinkedHashMap<>(); private final Map<String, ServiceLevelAgreementBoundary[]> sla = new LinkedHashMap<>();
......
...@@ -19,6 +19,7 @@ package org.springframework.boot.actuate.autoconfigure.metrics; ...@@ -19,6 +19,7 @@ package org.springframework.boot.actuate.autoconfigure.metrics;
import java.util.Arrays; import java.util.Arrays;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.function.Supplier;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import io.micrometer.core.instrument.Meter; import io.micrometer.core.instrument.Meter;
...@@ -39,6 +40,7 @@ import org.springframework.util.StringUtils; ...@@ -39,6 +40,7 @@ import org.springframework.util.StringUtils;
* @author Jon Schneider * @author Jon Schneider
* @author Phillip Webb * @author Phillip Webb
* @author Stephane Nicoll * @author Stephane Nicoll
* @author Artsiom Yudovin
* @since 2.0.0 * @since 2.0.0
*/ */
public class PropertiesMeterFilter implements MeterFilter { public class PropertiesMeterFilter implements MeterFilter {
...@@ -66,7 +68,7 @@ public class PropertiesMeterFilter implements MeterFilter { ...@@ -66,7 +68,7 @@ public class PropertiesMeterFilter implements MeterFilter {
@Override @Override
public MeterFilterReply accept(Meter.Id id) { public MeterFilterReply accept(Meter.Id id) {
boolean enabled = lookup(this.properties.getEnable(), id, true); boolean enabled = lookupWithFallbackToAll(this.properties.getEnable(), id, true);
return enabled ? MeterFilterReply.NEUTRAL : MeterFilterReply.DENY; return enabled ? MeterFilterReply.NEUTRAL : MeterFilterReply.DENY;
} }
...@@ -80,9 +82,10 @@ public class PropertiesMeterFilter implements MeterFilter { ...@@ -80,9 +82,10 @@ public class PropertiesMeterFilter implements MeterFilter {
DistributionStatisticConfig config) { DistributionStatisticConfig config) {
Distribution distribution = this.properties.getDistribution(); Distribution distribution = this.properties.getDistribution();
return DistributionStatisticConfig.builder() return DistributionStatisticConfig.builder()
.percentilesHistogram( .percentilesHistogram(lookupWithFallbackToAll(
lookup(distribution.getPercentilesHistogram(), id, null)) distribution.getPercentilesHistogram(), id, null))
.percentiles(lookup(distribution.getPercentiles(), id, null)) .percentiles(
lookupWithFallbackToAll(distribution.getPercentiles(), id, null))
.sla(convertSla(id.getType(), lookup(distribution.getSla(), id, null))) .sla(convertSla(id.getType(), lookup(distribution.getSla(), id, null)))
.build().merge(config); .build().merge(config);
} }
...@@ -101,6 +104,18 @@ public class PropertiesMeterFilter implements MeterFilter { ...@@ -101,6 +104,18 @@ public class PropertiesMeterFilter implements MeterFilter {
if (values.isEmpty()) { if (values.isEmpty()) {
return defaultValue; return defaultValue;
} }
return this.baseLookup(values, id, () -> defaultValue);
}
private <T> T lookupWithFallbackToAll(Map<String, T> values, Id id, T defaultValue) {
if (values.isEmpty()) {
return defaultValue;
}
return this.baseLookup(values, id,
() -> values.getOrDefault("all", defaultValue));
}
private <T> T baseLookup(Map<String, T> values, Id id, Supplier<T> defaultValue) {
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);
...@@ -110,7 +125,8 @@ public class PropertiesMeterFilter implements MeterFilter { ...@@ -110,7 +125,8 @@ public class PropertiesMeterFilter implements MeterFilter {
int lastDot = name.lastIndexOf('.'); int lastDot = name.lastIndexOf('.');
name = (lastDot != -1) ? name.substring(0, lastDot) : ""; name = (lastDot != -1) ? name.substring(0, lastDot) : "";
} }
return values.getOrDefault("all", defaultValue);
return defaultValue.get();
} }
} }
...@@ -42,6 +42,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException ...@@ -42,6 +42,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
* *
* @author Phillip Webb * @author Phillip Webb
* @author Jon Schneider * @author Jon Schneider
* @author Artsiom Yudovin
*/ */
public class PropertiesMeterFilterTests { public class PropertiesMeterFilterTests {
...@@ -261,45 +262,6 @@ public class PropertiesMeterFilterTests { ...@@ -261,45 +262,6 @@ public class PropertiesMeterFilterTests {
.containsExactly(4000000, 5000000, 6000000); .containsExactly(4000000, 5000000, 6000000);
} }
@Test
public void configureWhenAllSlaSetShouldSetSlaToValue() {
PropertiesMeterFilter filter = new PropertiesMeterFilter(
createProperties("distribution.sla.all=1,2,3"));
assertThat(filter.configure(createMeterId("spring.boot"),
DistributionStatisticConfig.DEFAULT).getSlaBoundaries())
.containsExactly(1000000, 2000000, 3000000);
}
@Test
public void configureWhenSlaDurationShouldOnlyApplyToTimer() {
PropertiesMeterFilter filter = new PropertiesMeterFilter(
createProperties("distribution.sla.all=1ms,2ms,3ms"));
Meter.Id timer = createMeterId("spring.boot", Meter.Type.TIMER);
Meter.Id summary = createMeterId("spring.boot", Meter.Type.DISTRIBUTION_SUMMARY);
Meter.Id counter = createMeterId("spring.boot", Meter.Type.COUNTER);
assertThat(filter.configure(timer, DistributionStatisticConfig.DEFAULT)
.getSlaBoundaries()).containsExactly(1000000, 2000000, 3000000);
assertThat(filter.configure(summary, DistributionStatisticConfig.DEFAULT)
.getSlaBoundaries()).isNullOrEmpty();
assertThat(filter.configure(counter, DistributionStatisticConfig.DEFAULT)
.getSlaBoundaries()).isNullOrEmpty();
}
@Test
public void configureWhenSlaLongShouldOnlyApplyToTimerAndDistributionSummary() {
PropertiesMeterFilter filter = new PropertiesMeterFilter(
createProperties("distribution.sla.all=1,2,3"));
Meter.Id timer = createMeterId("spring.boot", Meter.Type.TIMER);
Meter.Id summary = createMeterId("spring.boot", Meter.Type.DISTRIBUTION_SUMMARY);
Meter.Id counter = createMeterId("spring.boot", Meter.Type.COUNTER);
assertThat(filter.configure(timer, DistributionStatisticConfig.DEFAULT)
.getSlaBoundaries()).containsExactly(1000000, 2000000, 3000000);
assertThat(filter.configure(summary, DistributionStatisticConfig.DEFAULT)
.getSlaBoundaries()).containsExactly(1, 2, 3);
assertThat(filter.configure(counter, DistributionStatisticConfig.DEFAULT)
.getSlaBoundaries()).isNullOrEmpty();
}
private Id createMeterId(String name) { private Id createMeterId(String name) {
Meter.Type meterType = Type.TIMER; Meter.Type meterType = Type.TIMER;
return createMeterId(name, meterType); return createMeterId(name, meterType);
......
...@@ -1382,7 +1382,7 @@ content into your application. Rather, pick only the properties that you need. ...@@ -1382,7 +1382,7 @@ content into your application. Rather, pick only the properties that you need.
# METRICS # METRICS
management.metrics.distribution.percentiles-histogram.*= # Whether meter IDs starting with the specified name should publish percentile histograms. management.metrics.distribution.percentiles-histogram.*= # Whether meter IDs starting with the specified name should publish percentile histograms.
management.metrics.distribution.percentiles.*= # Specific computed non-aggregable percentiles to ship to the backend for meter IDs starting-with the specified name. management.metrics.distribution.percentiles.*= # Specific computed non-aggregable percentiles to ship to the backend for meter IDs starting-with the specified name.
management.metrics.distribution.sla.*= # Specific SLA boundaries for meter IDs starting-with the specified name. The longest match wins, the key `all` can also be used to configure all meters. management.metrics.distribution.sla.*= # Specific SLA boundaries for meter IDs starting-with the specified name. The longest match wins.
management.metrics.enable.*= # Whether meter IDs starting-with the specified name should be enabled. The longest match wins, the key `all` can also be used to configure all meters. management.metrics.enable.*= # Whether meter IDs starting-with the specified name should be enabled. The longest match wins, the key `all` can also be used to configure all meters.
management.metrics.export.atlas.batch-size=10000 # Number of measurements per request to use for this backend. If more measurements are found, then multiple requests will be made. management.metrics.export.atlas.batch-size=10000 # Number of measurements per request to use for this backend. If more measurements are found, then multiple requests will be made.
management.metrics.export.atlas.config-refresh-frequency=10s # Frequency for refreshing config settings from the LWC service. management.metrics.export.atlas.config-refresh-frequency=10s # Frequency for refreshing config settings from the LWC service.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment