Optimize prom stats endpoint#44658
Open
nshipilov wants to merge 2 commits intoenvoyproxy:mainfrom
Open
Conversation
Signed-off-by: Nick Shipilov <nick.shipilov.n@gmail.com>
Signed-off-by: Nick Shipilov <nick.shipilov.n@gmail.com>
|
Hi @nshipilov, welcome and thank you for your contribution. We will try to review your Pull Request as quickly as possible. In the meantime, please take a look at the contribution guidelines if you have not done so already. |
Contributor
|
@wbpcode you've been looking at stats recently so you're probably the most likely person to spot if there's something awful in here. I think it's okay - it looked like it was moving values out of stats but after some digging I came to the conclusion that it's only moving values out of snapshots, which I think are discarded when done. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Commit Message: Optimize prom stats endpoint.
Additional Description:
This PR optimizes the prometheus stats endpoint. In practice, at Uber, this takes us from ~250-300ms prom stat scrapes to ~125-150ms.
There are a few observations that are used throughout (from top to bottom as viewed in the diff)
(1)
::sanitizeNamereturns a new string, when we could sanitize names in place in certain scenarios, use a new function::sanitizeNameInPlacewhere appropriate.(2)
Primitive*Snapshottypes can be modified in place, as they are copies of the underlying metrics from the cluster manager.For instance, we can use this to modify the already copied, and soon to be destructed, Tags, instead of incurring additional copies in
formattedTags().Similarly, in
::addLabelsToMetricwe use this to move the tag name into the proto directly instead of incurring a copy.(3) Instead of maintaining a rb-tree
std::map<...> groupsto give a sorted presentation of the stats, we maintain a mapping ofstring/StatName -> vector<StatType*>, and iterate over the sorted set of keys instead. Creation of this map is significant for cases with lots of groups, and this is the biggest perf improvement in the diff.(4)
PrometheusStatsFormatter::metricNameis only ever called with newly allocated strings, so we can, again, sanitize it in place.Risk Level: Medium
Testing: Benchmark testing, confirming the improvement, and relevant tests in //test/server/admin/prometheus_stats_test.cc
Docs Changes: None
Release Notes: None
Platform Specific Features: None