Skip to content

Commit 4cc1b5e

Browse files
committed
Expose buffered property for StatsdConfig
See micrometer-metrics/micrometer#1375
1 parent 7e089a6 commit 4cc1b5e

File tree

4 files changed

+120
-1
lines changed

4 files changed

+120
-1
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ public class StatsdProperties {
7676
*/
7777
private boolean publishUnchangedMeters = true;
7878

79+
/**
80+
* Whether measurements should be buffered before sending to the StatsD server.
81+
*/
82+
private boolean buffered = true;
83+
7984
public boolean isEnabled() {
8085
return this.enabled;
8186
}
@@ -140,4 +145,12 @@ public void setPublishUnchangedMeters(boolean publishUnchangedMeters) {
140145
this.publishUnchangedMeters = publishUnchangedMeters;
141146
}
142147

148+
public boolean isBuffered() {
149+
return this.buffered;
150+
}
151+
152+
public void setBuffered(boolean buffered) {
153+
this.buffered = buffered;
154+
}
155+
143156
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,9 @@ public boolean publishUnchangedMeters() {
8686
return get(StatsdProperties::isPublishUnchangedMeters, StatsdConfig.super::publishUnchangedMeters);
8787
}
8888

89+
@Override
90+
public boolean buffered() {
91+
return get(StatsdProperties::isBuffered, StatsdConfig.super::buffered);
92+
}
93+
8994
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
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 whenPropertiesPublishUnchangedMetersIsSetAdapterPublishUnchangedMetersReturnsIt() {
87+
StatsdProperties properties = new StatsdProperties();
88+
properties.setPublishUnchangedMeters(false);
89+
assertThat(new StatsdPropertiesConfigAdapter(properties).publishUnchangedMeters())
90+
.isEqualTo(properties.isPublishUnchangedMeters());
91+
}
92+
93+
@Test
94+
void whenPropertiesBufferedIsSetAdapterBufferedReturnsIt() {
95+
StatsdProperties properties = new StatsdProperties();
96+
properties.setBuffered(false);
97+
assertThat(new StatsdPropertiesConfigAdapter(properties).buffered()).isEqualTo(properties.isBuffered());
98+
}
99+
100+
}

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

Lines changed: 2 additions & 1 deletion
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.
@@ -40,6 +40,7 @@ void defaultValuesAreConsistent() {
4040
assertThat(properties.getMaxPacketLength()).isEqualTo(config.maxPacketLength());
4141
assertThat(properties.getPollingFrequency()).isEqualTo(config.pollingFrequency());
4242
assertThat(properties.isPublishUnchangedMeters()).isEqualTo(config.publishUnchangedMeters());
43+
assertThat(properties.isBuffered()).isEqualTo(config.buffered());
4344
}
4445

4546
}

0 commit comments

Comments
 (0)