stats: add support for custom prefixes #3029
stats: add support for custom prefixes #3029mattklein123 merged 10 commits intoenvoyproxy:masterfrom
Conversation
|
@alyssawilk this is ready for review |
mattklein123
left a comment
There was a problem hiding this comment.
Thanks, some comments to get started.
bazel/repository_locations.bzl
Outdated
There was a problem hiding this comment.
please update now that your change has been merged
There was a problem hiding this comment.
const std::string prefix_. Just initialize directly in the initializer list using the ternary operator.
There was a problem hiding this comment.
prefix.empty(), initialize in init list per below.
There was a problem hiding this comment.
Changed initialization to init list for both UdpStatsdSink and TcpStatsdSink
There was a problem hiding this comment.
This should use CONSTRUCT_ON_FIRST_USE so should be a function
There was a problem hiding this comment.
Replaced with static const std::string& getDefaultPrefix()
|
@mrice32 might also want to review since this deals with stats |
There was a problem hiding this comment.
The assert below could fail if the prefix is really long.
mrice32
left a comment
There was a problem hiding this comment.
Looks great! Just a few small implementation comments and one interface question.
There was a problem hiding this comment.
Is there a reason we want to disallow an empty prefix since the user already has the option to not provide the argument and get the default? (same for TCP)
There was a problem hiding this comment.
An empty prefix doesn't make sense, imo. If an empty prefix is passed in, we just use the default instead. Also, if a prefix isn't specified statsd_sink.prefix() in createStatsSink will be an empty string. We can avoid multiple checks for an empty string by doing it here.
There was a problem hiding this comment.
SGTM - I didn't realize this was coming directly from the proto, so there is no way to specify a default.
There was a problem hiding this comment.
Is there a particular reason that this needs to be a reference? It's usually assumed that when a const reference is passed in (via the constructor above, for instance) that it is only guaranteed to live for the duration of that function call - meaning it shouldn't be stored and used later (same for TCP).
There was a problem hiding this comment.
You're right. This shouldn't be a reference. I've changed this to const std::string The getPrefix() methods for both Udp & Tcp sinks have been changed to return const std::string
There was a problem hiding this comment.
Two comments:
- Same as above, I think this should be
ASSERT_NEsince you'll get a segfault below if it'snullptr. - nit: this is a little hard to read - can we just dynamic cast once, save to a local variable, and then use the resulting pointer to do both checks?
(Same comments for other test cases)
There was a problem hiding this comment.
Fixed in all four tests.
There was a problem hiding this comment.
I think this should be ASSERT_NE since if it's nullptr, you'll get a segfault below (same for other tests below).
Signed-off-by: Akhil Thampy <akhil@akhilthampy.com>
Signed-off-by: Akhil Thampy <akhil@akhilthampy.com>
Signed-off-by: Akhil Thampy <akhil@akhilthampy.com>
Signed-off-by: Akhil Thampy <akhil@akhilthampy.com>
Signed-off-by: Akhil Thampy <akhil@akhilthampy.com>
…d bump data-plane-api SHA Signed-off-by: Akhil Thampy <akhil@akhilthampy.com>
Signed-off-by: Akhil Thampy <akhil@akhilthampy.com>
Signed-off-by: Akhil Thampy <akhil@akhilthampy.com>
mrice32
left a comment
There was a problem hiding this comment.
LGTM. Thanks for adding this!
There was a problem hiding this comment.
SGTM - I didn't realize this was coming directly from the proto, so there is no way to specify a default.
mattklein123
left a comment
There was a problem hiding this comment.
LGTM, thanks. Just a couple of small comments.
| // Called in unit test to validate writer construction and address. | ||
| int getFdForTests() { return tls_->getTyped<Writer>().getFdForTests(); } | ||
| bool getUseTagForTest() { return use_tag_; } | ||
| const std::string getPrefix() { return prefix_; } |
| std::chrono::milliseconds(value)); | ||
| } | ||
|
|
||
| const std::string getPrefix() { return prefix_; } |
| // 40 > 6 (prefix) + 4 (random chars) + 30 for number (bigger than it will ever be) | ||
| const uint32_t max_size = name.size() + 40; | ||
| // 34 > 4 (random chars) + 30 for number (bigger than it will ever be) | ||
| const uint32_t max_size = name.size() + parent_.getPrefix().size() + 40; |
There was a problem hiding this comment.
Shouldn't this be + 34 now?
| ASSERT(current_slice_mem_ != nullptr); | ||
| // 40 > 6 (prefix) + 4 (random chars) + 30 for number (bigger than it will ever be) | ||
| const uint32_t max_size = name.size() + 40; | ||
| // 34 > 4 (random chars) + 30 for number (bigger than it will ever be) |
There was a problem hiding this comment.
Can you update this comment to:
34 > 4 (postfix chars, e.g., "|ms\n") + 30 for number (bigger than it will ever be)
alyssawilk
left a comment
There was a problem hiding this comment.
LGTM modulo Matt's comments
Signed-off-by: Akhil Thampy <akhil@akhilthampy.com>
mattklein123
left a comment
There was a problem hiding this comment.
LGTM, small nit I missed before. Please also add a release not and unhide any docs that may be hidden. Thanks!
| current_slice_mem_ += sizeof(STAT_PREFIX) - 1; | ||
| memcpy(current_slice_mem_, parent_.getPrefix().c_str(), parent_.getPrefix().size()); | ||
| current_slice_mem_ += parent_.getPrefix().size(); | ||
| *current_slice_mem_ = '.'; |
There was a problem hiding this comment.
nit: simplify to *current_slice_mem_++ = '.' like below. Also, technically you should modify the above space reservation comment to account for this dot.
Signed-off-by: Akhil Thampy <akhil@akhilthampy.com>
Signed-off-by: Akhil Thampy <akhil@akhilthampy.com> Signed-off-by: Rama <rama.rao@salesforce.com>
This seems to have been implemented in envoyproxy#3029. Signed-off-by: Snow Pettersen <snowp@squareup.com>
This seems to have been implemented in #3029. Signed-off-by: Snow Pettersen <snowp@squareup.com>
This seems to have been implemented in envoyproxy/envoy#3029. Signed-off-by: Snow Pettersen <snowp@squareup.com> Mirrored from https://github.com/envoyproxy/envoy @ 45d3e3f64074338fb8ac4e2e41226180b9c245b9
stats: Add support for specifying a custom prefix
Description:
This PR adds support for specifying custom prefixes for StatsdSinks.
Testing:
Ran unit tests locally and added the following unit tests:
Release Notes: TODO(?)
Fixes #2897
Data Plane PR
TODO