-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
config/stats: add udp statds address as config option #1019
Conversation
test/common/stats/udp_statsd_test.cc
Outdated
socklen_t sock_len = sizeof(sockaddress); | ||
|
||
EXPECT_EQ(0, getsockname(fd, reinterpret_cast<struct sockaddr*>(&sockaddress), &sock_len)); | ||
EXPECT_EQ("127.0.0.1", Network::Address::addressFromSockAddr(sockaddress, sizeof(sockaddr_in)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it expected that this is 127.0.0.1 and not 0.0.0.0?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I notice above we create the address as new Network::Address::Ipv4Instance(port)
(which it was also doing before). This actually sets the destination IP as 0.0.0.0, which doesn't seem to make that sense to me (unless I'm missing something about UDP and local interfaces). The fact that this passes though seems to indicate it does get rebound? Maybe someone with more insight can comment here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you ping 0.0.0.0 you get
PING 0.0.0.0 (127.0.0.1) 56(84) bytes of data. 64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.056 ms
So somehow it's getting converted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great @hennna, thanks.
include/envoy/server/configuration.h
Outdated
@@ -130,12 +130,18 @@ class Main { | |||
*/ | |||
virtual Optional<std::string> statsdTcpClusterName() PURE; | |||
|
|||
// TODO(hennna): Deprecate in release: 1.4.0. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: it's deprecated now, will be removed in 1.4.0.
DEPERECATED.md
Outdated
@@ -0,0 +1,3 @@ | |||
# DEPRECATED starting from 1.3.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe DEPRECATED (will be removed in 1.4.0)
. @RomanDzhabarov thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe put a top level description of what this file is for and what rules are (feature is removed starting from the specified version, etc)
And then having a list of features that will be removed in a specific version.
Description
Version 1.4.0:
- item 1
- item 2
Version 1.5.0:
- ..
etc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update the file name DEPERECATED.md -> DEPRECATED.md now, otherwise we will have to deprecate the DEPERECATED.md at a later date!
include/envoy/server/configuration.h
Outdated
/** | ||
* @return Optional<uint32_t> the optional local UDP statsd port to write to. | ||
*/ | ||
virtual Optional<uint32_t> statsdUdpPort() PURE; | ||
|
||
/** | ||
* @return Optional<uint32_t> the optional UDP statsd address to write to. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stale comment type.
include/envoy/server/configuration.h
Outdated
/** | ||
* @return Optional<uint32_t> the optional local UDP statsd port to write to. | ||
*/ | ||
virtual Optional<uint32_t> statsdUdpPort() PURE; | ||
|
||
/** | ||
* @return Optional<uint32_t> the optional UDP statsd address to write to. | ||
*/ | ||
virtual Optional<std::string> statsdUdpIpAddress() PURE; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be a string or Network::Address::InstanceConstSharedPtr
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is string and has to do with parsing the JSON config file.
source/common/stats/statsd.cc
Outdated
void Writer::shutdown() { | ||
shutdown_ = true; | ||
if (fd_ != -1) { | ||
ASSERT(close(fd_) == 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be RELEASE_ASSERT
or it will get compiled out in release builds.
source/server/server.cc
Outdated
log().info("statsd UDP port: {}", config_->statsdUdpPort().value()); | ||
stat_sinks_.emplace_back(new Stats::Statsd::UdpStatsdSink(config_->statsdUdpPort().value())); | ||
stat_sinks_.emplace_back( | ||
new Stats::Statsd::UdpStatsdSink(thread_local_, config_->statsdUdpPort().value())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could localize the deprecation to this method if you switch the UdpStatsdSink
constructor to just take an Address.
test/common/stats/udp_statsd_test.cc
Outdated
socklen_t sock_len = sizeof(sockaddress); | ||
|
||
EXPECT_EQ(0, getsockname(fd, reinterpret_cast<struct sockaddr*>(&sockaddress), &sock_len)); | ||
EXPECT_EQ("127.0.0.1", Network::Address::addressFromSockAddr(sockaddress, sizeof(sockaddr_in)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I notice above we create the address as new Network::Address::Ipv4Instance(port)
(which it was also doing before). This actually sets the destination IP as 0.0.0.0, which doesn't seem to make that sense to me (unless I'm missing something about UDP and local interfaces). The fact that this passes though seems to indicate it does get rebound? Maybe someone with more insight can comment here.
The following features have been DEPRECATED and will be removed in the specified release cycle. | ||
|
||
* Version 1.4.0 | ||
* Config option `statsd_local_udp_port` has been deprecated and has been replaced with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
source/common/stats/statsd.h
Outdated
~Writer(); | ||
|
||
void writeCounter(const std::string& name, uint64_t increment); | ||
void writeGauge(const std::string& name, uint64_t value); | ||
void writeTimer(const std::string& name, const std::chrono::milliseconds& ms); | ||
void shutdown() override; | ||
// Called in unit test to validate address. | ||
int getFdForTests() { return fd_; }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const
test/common/stats/udp_statsd_test.cc
Outdated
EXPECT_EQ("127.0.0.1", Network::Address::addressFromFd(fd)->ip()->addressAsString()); | ||
} else { | ||
EXPECT_EQ("::1", Network::Address::addressFromFd(fd)->ip()->addressAsString()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about checking expected port?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This need to be updated to getpeername. Will fix.
test/config/integration/server.json
Outdated
@@ -232,7 +232,7 @@ | |||
|
|||
"admin": { "access_log_path": "/dev/null", "profile_path": "{{ test_tmpdir }}/envoy.prof", "address": "tcp://127.0.0.1:0" }, | |||
"flags_path": "/invalid_flags", | |||
"statsd_local_udp_port": 8125, | |||
"statsd_udp_ip_address": "127.0.0.1:0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit weird specifying a 0 send port, but sure, why not, it at least points out this is distinguished.
@@ -45,9 +45,11 @@ flags_path | |||
*(optional, string)* The file system path to search for :ref:`startup flag files | |||
<operations_file_system_flags>`. | |||
|
|||
statsd_local_udp_port |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shall we keep this until it's removed from the code? (and add deprecation warning)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. Will add it back.
source/common/stats/statsd.h
Outdated
|
||
uint32_t port_; | ||
ThreadLocal::Instance& tls_; | ||
uint32_t tls_slot_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const
statsd_local_udp_port | ||
*(optional, integer)* The UDP port of a locally running statsd compliant listener. If specified, | ||
:ref:`statistics <arch_overview_statistics>` will be flushed to this port. | ||
statsd_udp_ip_address |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what happens if both specified?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will choose ip_address over port in server.cc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wondering if we just should throw to avoid confusion when we checked whether one or another is set.
https://github.com/lyft/envoy/pull/1019/files#diff-3eda0ff865e056f19775ad626a5c2920R321
source/common/stats/statsd.h
Outdated
|
||
private: | ||
void send(const std::string& message); | ||
|
||
int fd_; | ||
bool shutdown_ = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for consistency, bool shutdown_{};
+1 |
Does this patch support a DNS address instead of an IP? If so, maybe just statsd_udp_remote_address is a better option name. |
This doesn't support a DNS address, only IP:port. In general, Envoy only supports DNS resolutions today when redirecting via cluster resolution. |
OK, although then using this option sort of forces you into a bad practice of hard-coding IP addresses. Would it make sense to try to make the "statsd_tcp_cluster_name" then support UDP too (i.e. a "statsd_udp_cluster_name")? |
This seems reasonable from a config/API perspective, but will involve a bit of work to make work. Currently the cluster implementations such as |
This is also related to #492 - if there was general support for UDP proxying we would be able to leverage that to do have UDP addressable clusters for statsd. |
Tracking in #1028. |
Signed-off-by: Michael Rebello <[email protected]> Signed-off-by: JP Simard <[email protected]>
Signed-off-by: Michael Rebello <[email protected]> Signed-off-by: JP Simard <[email protected]>
This PR allows the statsd UDP server address to be set as a JSON config parameter.
To allow for unit testing, the udp statsd writer_ has been changed from a static thread_local object to being derived from the ThreadLocal object class.
In this PR,
statsd_local_udp_port
has been DEPRECATED and replaced withstatsd_udp_ip_address
.Fixes #948 . Fixes part of #979 .