Skip to content

Commit 1a93066

Browse files
committed
Merge pull request #22125 from lndobryden
* gh-22125: Polish "Add StatsD transport protocol configuration option" Add StatsD transport protocol configuration option Closes gh-22125
2 parents 5de67e9 + 77eb5f7 commit 1a93066

File tree

5 files changed

+29
-3
lines changed

5 files changed

+29
-3
lines changed

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 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.
@@ -19,6 +19,7 @@
1919
import java.time.Duration;
2020

2121
import io.micrometer.statsd.StatsdFlavor;
22+
import io.micrometer.statsd.StatsdProtocol;
2223

2324
import org.springframework.boot.context.properties.ConfigurationProperties;
2425

@@ -53,6 +54,11 @@ public class StatsdProperties {
5354
*/
5455
private Integer port = 8125;
5556

57+
/**
58+
* Protocol of the StatsD server to receive exported metrics.
59+
*/
60+
private StatsdProtocol protocol = StatsdProtocol.UDP;
61+
5662
/**
5763
* Total length of a single payload should be kept within your network's MTU.
5864
*/
@@ -102,6 +108,14 @@ public void setPort(Integer port) {
102108
this.port = port;
103109
}
104110

111+
public StatsdProtocol getProtocol() {
112+
return this.protocol;
113+
}
114+
115+
public void setProtocol(StatsdProtocol protocol) {
116+
this.protocol = protocol;
117+
}
118+
105119
public Integer getMaxPacketLength() {
106120
return this.maxPacketLength;
107121
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import io.micrometer.statsd.StatsdConfig;
2222
import io.micrometer.statsd.StatsdFlavor;
23+
import io.micrometer.statsd.StatsdProtocol;
2324

2425
import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.PropertiesConfigAdapter;
2526

@@ -65,6 +66,11 @@ public int port() {
6566
return get(StatsdProperties::getPort, StatsdConfig.super::port);
6667
}
6768

69+
@Override
70+
public StatsdProtocol protocol() {
71+
return get(StatsdProperties::getProtocol, StatsdConfig.super::protocol);
72+
}
73+
6874
@Override
6975
public int maxPacketLength() {
7076
return get(StatsdProperties::getMaxPacketLength, StatsdConfig.super::maxPacketLength);

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,10 @@
463463
"name": "management.metrics.export.statsd.flavor",
464464
"defaultValue": "datadog"
465465
},
466+
{
467+
"name": "management.metrics.export.statsd.protocol",
468+
"defaultValue": "udp"
469+
},
466470
{
467471
"name": "management.metrics.export.statsd.queue-size",
468472
"defaultValue": 2147483647,

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-2019 the original author or authors.
2+
* Copyright 2012-2020 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.
@@ -36,6 +36,7 @@ void defaultValuesAreConsistent() {
3636
assertThat(properties.getFlavor()).isEqualTo(config.flavor());
3737
assertThat(properties.getHost()).isEqualTo(config.host());
3838
assertThat(properties.getPort()).isEqualTo(config.port());
39+
assertThat(properties.getProtocol()).isEqualTo(config.protocol());
3940
assertThat(properties.getMaxPacketLength()).isEqualTo(config.maxPacketLength());
4041
assertThat(properties.getPollingFrequency()).isEqualTo(config.pollingFrequency());
4142
assertThat(properties.isPublishUnchangedMeters()).isEqualTo(config.publishUnchangedMeters());

spring-boot-project/spring-boot-docs/src/docs/asciidoc/production-ready-features.adoc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1764,12 +1764,13 @@ You can also change the interval at which metrics are sent to Stackdriver:
17641764
==== StatsD
17651765
The StatsD registry pushes metrics over UDP to a StatsD agent eagerly.
17661766
By default, metrics are exported to a {micrometer-registry-docs}/statsd[StatsD] agent running on your local machine.
1767-
The StatsD agent host and port to use can be provided using:
1767+
The StatsD agent host, port, and protocol to use can be provided using:
17681768

17691769
[source,properties,indent=0,configprops]
17701770
----
17711771
management.metrics.export.statsd.host=statsd.example.com
17721772
management.metrics.export.statsd.port=9125
1773+
management.metrics.export.statsd.protocol=udp
17731774
----
17741775

17751776
You can also change the StatsD line protocol to use (default to Datadog):

0 commit comments

Comments
 (0)