Skip to content

Commit cbf415b

Browse files
committed
Merge branch '2.7.x'
2 parents d1fddd7 + 285378e commit cbf415b

File tree

4 files changed

+147
-1
lines changed

4 files changed

+147
-1
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/statsd/StatsdProperties.java

+27
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,22 @@ public class StatsdProperties {
7171
*/
7272
private Duration pollingFrequency = Duration.ofSeconds(10);
7373

74+
/**
75+
* Step size to use in computing windowed statistics like max. To get the most out of
76+
* these statistics, align the step interval to be close to your scrape interval.
77+
*/
78+
private Duration step = Duration.ofMinutes(1);
79+
7480
/**
7581
* Whether to send unchanged meters to the StatsD server.
7682
*/
7783
private boolean publishUnchangedMeters = true;
7884

85+
/**
86+
* Whether measurements should be buffered before sending to the StatsD server.
87+
*/
88+
private boolean buffered = true;
89+
7990
public boolean isEnabled() {
8091
return this.enabled;
8192
}
@@ -132,6 +143,14 @@ public void setPollingFrequency(Duration pollingFrequency) {
132143
this.pollingFrequency = pollingFrequency;
133144
}
134145

146+
public Duration getStep() {
147+
return this.step;
148+
}
149+
150+
public void setStep(Duration step) {
151+
this.step = step;
152+
}
153+
135154
public boolean isPublishUnchangedMeters() {
136155
return this.publishUnchangedMeters;
137156
}
@@ -140,4 +159,12 @@ public void setPublishUnchangedMeters(boolean publishUnchangedMeters) {
140159
this.publishUnchangedMeters = publishUnchangedMeters;
141160
}
142161

162+
public boolean isBuffered() {
163+
return this.buffered;
164+
}
165+
166+
public void setBuffered(boolean buffered) {
167+
this.buffered = buffered;
168+
}
169+
143170
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/statsd/StatsdPropertiesConfigAdapter.java

+10
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,19 @@ public Duration pollingFrequency() {
8181
return get(StatsdProperties::getPollingFrequency, StatsdConfig.super::pollingFrequency);
8282
}
8383

84+
@Override
85+
public Duration step() {
86+
return get(StatsdProperties::getStep, StatsdConfig.super::step);
87+
}
88+
8489
@Override
8590
public boolean publishUnchangedMeters() {
8691
return get(StatsdProperties::isPublishUnchangedMeters, StatsdConfig.super::publishUnchangedMeters);
8792
}
8893

94+
@Override
95+
public boolean buffered() {
96+
return get(StatsdProperties::isBuffered, StatsdConfig.super::buffered);
97+
}
98+
8999
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
* Copyright 2012-2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.actuate.autoconfigure.metrics.export.statsd;
18+
19+
import java.time.Duration;
20+
21+
import io.micrometer.statsd.StatsdFlavor;
22+
import io.micrometer.statsd.StatsdProtocol;
23+
import org.junit.jupiter.api.Test;
24+
25+
import static org.assertj.core.api.Assertions.assertThat;
26+
27+
/**
28+
* Tests for {@link StatsdPropertiesConfigAdapter}.
29+
*
30+
* @author Johnny Lim
31+
*/
32+
class StatsdPropertiesConfigAdapterTests {
33+
34+
@Test
35+
void whenPropertiesEnabledIsSetAdapterEnabledReturnsIt() {
36+
StatsdProperties properties = new StatsdProperties();
37+
properties.setEnabled(false);
38+
assertThat(new StatsdPropertiesConfigAdapter(properties).enabled()).isEqualTo(properties.isEnabled());
39+
}
40+
41+
@Test
42+
void whenPropertiesFlavorIsSetAdapterFlavorReturnsIt() {
43+
StatsdProperties properties = new StatsdProperties();
44+
properties.setFlavor(StatsdFlavor.ETSY);
45+
assertThat(new StatsdPropertiesConfigAdapter(properties).flavor()).isEqualTo(properties.getFlavor());
46+
}
47+
48+
@Test
49+
void whenPropertiesHostIsSetAdapterHostReturnsIt() {
50+
StatsdProperties properties = new StatsdProperties();
51+
properties.setHost("my-host");
52+
assertThat(new StatsdPropertiesConfigAdapter(properties).host()).isEqualTo(properties.getHost());
53+
}
54+
55+
@Test
56+
void whenPropertiesPortIsSetAdapterPortReturnsIt() {
57+
StatsdProperties properties = new StatsdProperties();
58+
properties.setPort(1234);
59+
assertThat(new StatsdPropertiesConfigAdapter(properties).port()).isEqualTo(properties.getPort());
60+
}
61+
62+
@Test
63+
void whenPropertiesProtocolIsSetAdapterProtocolReturnsIt() {
64+
StatsdProperties properties = new StatsdProperties();
65+
properties.setProtocol(StatsdProtocol.TCP);
66+
assertThat(new StatsdPropertiesConfigAdapter(properties).protocol()).isEqualTo(properties.getProtocol());
67+
}
68+
69+
@Test
70+
void whenPropertiesMaxPacketLengthIsSetAdapterMaxPacketLengthReturnsIt() {
71+
StatsdProperties properties = new StatsdProperties();
72+
properties.setMaxPacketLength(1234);
73+
assertThat(new StatsdPropertiesConfigAdapter(properties).maxPacketLength())
74+
.isEqualTo(properties.getMaxPacketLength());
75+
}
76+
77+
@Test
78+
void whenPropertiesPollingFrequencyIsSetAdapterPollingFrequencyReturnsIt() {
79+
StatsdProperties properties = new StatsdProperties();
80+
properties.setPollingFrequency(Duration.ofSeconds(1));
81+
assertThat(new StatsdPropertiesConfigAdapter(properties).pollingFrequency())
82+
.isEqualTo(properties.getPollingFrequency());
83+
}
84+
85+
@Test
86+
void whenPropertiesStepIsSetAdapterStepReturnsIt() {
87+
StatsdProperties properties = new StatsdProperties();
88+
properties.setStep(Duration.ofSeconds(1));
89+
assertThat(new StatsdPropertiesConfigAdapter(properties).step()).isEqualTo(properties.getStep());
90+
}
91+
92+
@Test
93+
void whenPropertiesPublishUnchangedMetersIsSetAdapterPublishUnchangedMetersReturnsIt() {
94+
StatsdProperties properties = new StatsdProperties();
95+
properties.setPublishUnchangedMeters(false);
96+
assertThat(new StatsdPropertiesConfigAdapter(properties).publishUnchangedMeters())
97+
.isEqualTo(properties.isPublishUnchangedMeters());
98+
}
99+
100+
@Test
101+
void whenPropertiesBufferedIsSetAdapterBufferedReturnsIt() {
102+
StatsdProperties properties = new StatsdProperties();
103+
properties.setBuffered(false);
104+
assertThat(new StatsdPropertiesConfigAdapter(properties).buffered()).isEqualTo(properties.isBuffered());
105+
}
106+
107+
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/statsd/StatsdPropertiesTests.java

+3-1
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-2022 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.
@@ -39,7 +39,9 @@ void defaultValuesAreConsistent() {
3939
assertThat(properties.getProtocol()).isEqualTo(config.protocol());
4040
assertThat(properties.getMaxPacketLength()).isEqualTo(config.maxPacketLength());
4141
assertThat(properties.getPollingFrequency()).isEqualTo(config.pollingFrequency());
42+
assertThat(properties.getStep()).isEqualTo(config.step());
4243
assertThat(properties.isPublishUnchangedMeters()).isEqualTo(config.publishUnchangedMeters());
44+
assertThat(properties.isBuffered()).isEqualTo(config.buffered());
4345
}
4446

4547
}

0 commit comments

Comments
 (0)