Skip to content

Commit 1475309

Browse files
committed
Polish "Add expiry and bufferLength configuration properties"
See gh-27584
1 parent 888acb9 commit 1475309

File tree

4 files changed

+17
-16
lines changed

4 files changed

+17
-16
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsProperties.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
* @author Jon Schneider
3131
* @author Alexander Abramov
3232
* @author Tadaya Tsuyukubo
33-
* @author Leo Li
3433
* @since 2.0.0
3534
*/
3635
@ConfigurationProperties("management.metrics")
@@ -299,16 +298,16 @@ public static class Distribution {
299298
private final Map<String, String> maximumExpectedValue = new LinkedHashMap<>();
300299

301300
/**
302-
* Specific statistic's expiry for meter IDs starting-with the specified name.
303-
* Values should be a Duration value, the key `all` can also be used to configure
304-
* all meters.
301+
* Maximum amount of time that samples for meter IDs starting with the specified
302+
* name are accumulated to decaying distribution statistics before they are reset
303+
* and rotated. The longest match wins, the key `all` can also be used to
304+
* configure all meters.
305305
*/
306306
private final Map<String, Duration> expiry = new LinkedHashMap<>();
307307

308308
/**
309-
* Specific statistic's bufferLength for meter IDs starting-with the specified
310-
* name. Samples are accumulated to statistics in ring buffers, and bufferLength
311-
* is the number to keep in the ring buffer, the key `all` can also be used to
309+
* Number of histograms for meter IDs starting with the specified name to keep in
310+
* the ring buffer. The longest match wins, the key `all` can also be used to
312311
* configure all meters.
313312
*/
314313
private final Map<String, Integer> bufferLength = new LinkedHashMap<>();

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/PropertiesMeterFilter.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -42,7 +42,6 @@
4242
* @author Stephane Nicoll
4343
* @author Artsiom Yudovin
4444
* @author Alexander Abramov
45-
* @author Leo Li
4645
* @since 2.0.0
4746
*/
4847
public class PropertiesMeterFilter implements MeterFilter {
@@ -84,15 +83,14 @@ public DistributionStatisticConfig configure(Meter.Id id, DistributionStatisticC
8483
return DistributionStatisticConfig.builder()
8584
.percentilesHistogram(lookupWithFallbackToAll(distribution.getPercentilesHistogram(), id, null))
8685
.percentiles(lookupWithFallbackToAll(distribution.getPercentiles(), id, null))
87-
.expiry(lookupWithFallbackToAll(distribution.getExpiry(), id, null))
88-
.bufferLength(lookupWithFallbackToAll(distribution.getBufferLength(), id, null))
8986
.serviceLevelObjectives(
9087
convertServiceLevelObjectives(id.getType(), lookup(distribution.getSlo(), id, null)))
9188
.minimumExpectedValue(
9289
convertMeterValue(id.getType(), lookup(distribution.getMinimumExpectedValue(), id, null)))
9390
.maximumExpectedValue(
9491
convertMeterValue(id.getType(), lookup(distribution.getMaximumExpectedValue(), id, null)))
95-
.build().merge(config);
92+
.expiry(lookupWithFallbackToAll(distribution.getExpiry(), id, null))
93+
.bufferLength(lookupWithFallbackToAll(distribution.getBufferLength(), id, null)).build().merge(config);
9694
}
9795

9896
private double[] convertServiceLevelObjectives(Meter.Type meterType, ServiceLevelObjectiveBoundary[] slo) {

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/PropertiesMeterFilterTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ void configureWhenAllExpirySetShouldSetExpiryToValue() {
309309
@Test
310310
void configureWhenHasBufferLengthShouldSetBufferLengthToValue() {
311311
PropertiesMeterFilter filter = new PropertiesMeterFilter(
312-
createProperties("distribution.bufferLength[spring.boot]=3"));
312+
createProperties("distribution.buffer-length.spring.boot=3"));
313313
assertThat(
314314
filter.configure(createMeterId("spring.boot"), DistributionStatisticConfig.DEFAULT).getBufferLength())
315315
.isEqualTo(3);
@@ -318,7 +318,7 @@ void configureWhenHasBufferLengthShouldSetBufferLengthToValue() {
318318
@Test
319319
void configureWhenHasHigherBufferLengthShouldSetBufferLengthToValue() {
320320
PropertiesMeterFilter filter = new PropertiesMeterFilter(
321-
createProperties("distribution.bufferLength.spring=3"));
321+
createProperties("distribution.buffer-length.spring=3"));
322322
assertThat(
323323
filter.configure(createMeterId("spring.boot"), DistributionStatisticConfig.DEFAULT).getBufferLength())
324324
.isEqualTo(3);
@@ -327,15 +327,15 @@ void configureWhenHasHigherBufferLengthShouldSetBufferLengthToValue() {
327327
@Test
328328
void configureWhenHasHigherBufferLengthAndLowerShouldSetBufferLengthToHigher() {
329329
PropertiesMeterFilter filter = new PropertiesMeterFilter(
330-
createProperties("distribution.bufferLength.spring=2", "distribution.bufferLength[spring.boot]=3"));
330+
createProperties("distribution.buffer-length.spring=2", "distribution.buffer-length.spring.boot=3"));
331331
assertThat(
332332
filter.configure(createMeterId("spring.boot"), DistributionStatisticConfig.DEFAULT).getBufferLength())
333333
.isEqualTo(3);
334334
}
335335

336336
@Test
337337
void configureWhenAllBufferLengthSetShouldSetBufferLengthToValue() {
338-
PropertiesMeterFilter filter = new PropertiesMeterFilter(createProperties("distribution.bufferLength.all=3"));
338+
PropertiesMeterFilter filter = new PropertiesMeterFilter(createProperties("distribution.buffer-length.all=3"));
339339
assertThat(
340340
filter.configure(createMeterId("spring.boot"), DistributionStatisticConfig.DEFAULT).getBufferLength())
341341
.isEqualTo(3);

spring-boot-project/spring-boot-docs/src/docs/asciidoc/actuator/metrics.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,6 +1153,10 @@ The following properties allow per-meter customization:
11531153
| configprop:management.metrics.distribution.percentiles[]
11541154
| Publish percentile values computed in your application
11551155

1156+
| configprop:management.metrics.distribution.expiry[], configprop:management.metrics.distribution.buffer-length[]
1157+
| Give greater weight to recent samples by accumulating them in ring buffers which rotate after a configurable expiry, with a
1158+
configurable buffer length.
1159+
11561160
| configprop:management.metrics.distribution.slo[]
11571161
| Publish a cumulative histogram with buckets defined by your service-level objectives.
11581162
|===

0 commit comments

Comments
 (0)