Skip to content

metrics service: make metric predicate overridable#16725

Merged
snowp merged 5 commits intoenvoyproxy:mainfrom
snowp:metrics-predicate
Jun 2, 2021
Merged

metrics service: make metric predicate overridable#16725
snowp merged 5 commits intoenvoyproxy:mainfrom
snowp:metrics-predicate

Conversation

@snowp
Copy link
Copy Markdown
Contributor

@snowp snowp commented May 30, 2021

Adds the predicate to use to determine whether to include a metric when flushing as a ctor parameter to MetrcsFlusher.
This allows custom sinks that reuse the metrics service components to override the predicate, allowing for modifcations
of which subset of metrics are flushed without having do tamper with the incoming snapshot.

Risk Level: Low, no behavior change
Testing: UTs
Docs Changes: n/a
Release Notes: n/a
Platform Specific Features: n/a

Snow Pettersen added 3 commits May 30, 2021 17:36
Adds a predicate parameter to the MetricsFlusher class, allowing classes that reuse this code to
override the predicate used to determine whether to include stats.

Signed-off-by: Snow Pettersen <snowp@lyft.com>
Signed-off-by: Snow Pettersen <snowp@lyft.com>
Signed-off-by: Snow Pettersen <snowp@lyft.com>
@snowp snowp requested a review from jmarantz as a code owner May 30, 2021 18:06
jmarantz
jmarantz previously approved these changes May 30, 2021
Copy link
Copy Markdown
Contributor

@jmarantz jmarantz 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 modulo some test suggestions if you agree.

TEST_F(MetricsServiceSinkTest, DefaultFlushPredicate) {
MetricsFlusher flusher(true, true);

auto used_counter = std::make_shared<NiceMock<Stats::MockCounter>>();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: suggest a helper function to factor out the 5-line stanzas making the mock counters (used 4x so far).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added out helper functions to all the metrics types since I was in here, I think this helped the overall readability of the whole file

}

TEST_F(MetricsServiceSinkTest, OverridenFlushPredicate) {
MetricsFlusher flusher(true, true, [](const auto&) { return true; });
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: suggest another test where predicate returns false, which would add another 2 uses of the helper function.

Snow Pettersen added 2 commits May 31, 2021 16:27
…e predicate

Signed-off-by: Snow Pettersen <snowp@lyft.com>
Signed-off-by: Snow Pettersen <snowp@lyft.com>
Copy link
Copy Markdown
Contributor

@jmarantz jmarantz left a comment

Choose a reason for hiding this comment

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

Thanks! Looks great.

@snowp snowp merged commit cd183e1 into envoyproxy:main Jun 2, 2021
leyao-daily pushed a commit to leyao-daily/envoy that referenced this pull request Sep 30, 2021
Adds a predicate parameter to the MetricsFlusher class, allowing classes that reuse this code to
override the predicate used to determine whether to include stats.

Signed-off-by: Snow Pettersen <snowp@lyft.com>
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.

2 participants