Skip to content

stats: add support for custom prefixes #3029

Merged
mattklein123 merged 10 commits intoenvoyproxy:masterfrom
athampy:gh-2897
Apr 24, 2018
Merged

stats: add support for custom prefixes #3029
mattklein123 merged 10 commits intoenvoyproxy:masterfrom
athampy:gh-2897

Conversation

@athampy
Copy link
Member

@athampy athampy commented Apr 9, 2018

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:

  • config_test.cc:UdpSinkCustomPrefix
  • config_test.cc:UdpSinkDefaultPrefix
  • config_test.cc:TcpSinkCustomPrefix
  • config_test.cc:TcpSinkDefaultPrefix

Release Notes: TODO(?)

Fixes #2897

Data Plane PR

TODO

  • revert changes to repository_locations.bzl

@athampy
Copy link
Member Author

athampy commented Apr 10, 2018

@alyssawilk this is ready for review

Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, some comments to get started.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please update now that your change has been merged

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const std::string& prefix

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const std::string prefix_. Just initialize directly in the initializer list using the ternary operator.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const std::string&

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefix.empty(), initialize in init list per below.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed initialization to init list for both UdpStatsdSink and TcpStatsdSink

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

init in init list

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use CONSTRUCT_ON_FIRST_USE so should be a function

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced with static const std::string& getDefaultPrefix()

@dnoe
Copy link
Contributor

dnoe commented Apr 12, 2018

@mrice32 might also want to review since this deals with stats

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The assert below could fail if the prefix is really long.

Copy link
Member

@mrice32 mrice32 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Just a few small implementation comments and one interface question.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM - I didn't realize this was coming directly from the proto, so there is no way to specify a default.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two comments:

  1. Same as above, I think this should be ASSERT_NE since you'll get a segfault below if it's nullptr.
  2. 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)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in all four tests.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be ASSERT_NE since if it's nullptr, you'll get a segfault below (same for other tests below).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

athampy added 8 commits April 20, 2018 16:10
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>
Copy link
Member

@mrice32 mrice32 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for adding this!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM - I didn't realize this was coming directly from the proto, so there is no way to specify a default.

Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const std::string&

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

std::chrono::milliseconds(value));
}

const std::string getPrefix() { return prefix_; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const std::string&

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

// 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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be + 34 now?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, updated.

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you update this comment to:
34 > 4 (postfix chars, e.g., "|ms\n") + 30 for number (bigger than it will ever be)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

alyssawilk
alyssawilk previously approved these changes Apr 23, 2018
Copy link
Contributor

@alyssawilk alyssawilk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM modulo Matt's comments

Signed-off-by: Akhil Thampy <akhil@akhilthampy.com>
Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_ = '.';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@mattklein123 mattklein123 merged commit 51663a1 into envoyproxy:master Apr 24, 2018
ramaraochavali pushed a commit to ramaraochavali/envoy that referenced this pull request May 3, 2018
Signed-off-by: Akhil Thampy <akhil@akhilthampy.com>

Signed-off-by: Rama <rama.rao@salesforce.com>
snowp pushed a commit to snowp/envoy that referenced this pull request May 11, 2018
This seems to have been implemented in
envoyproxy#3029.

Signed-off-by: Snow Pettersen <snowp@squareup.com>
mattklein123 pushed a commit that referenced this pull request May 11, 2018
This seems to have been implemented in
#3029.

Signed-off-by: Snow Pettersen <snowp@squareup.com>
mattklein123 pushed a commit to envoyproxy/data-plane-api that referenced this pull request May 11, 2018
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Statsd global prefix

5 participants