-
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
Pass regexp filter to /stats/prometheus #7182
Pass regexp filter to /stats/prometheus #7182
Conversation
3c37e48
to
cf72608
Compare
@mattklein123 Hi, Can you help review this pr? |
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.
Thanks for working on this! Would you mind adding a test case that exercises the filtering?
source/server/http/admin.cc
Outdated
@@ -753,8 +753,13 @@ Http::Code AdminImpl::handlerPrometheusStats(absl::string_view path_and_query, H | |||
Buffer::Instance& response, AdminStream&) { | |||
const Http::Utility::QueryParams params = Http::Utility::parseQueryString(path_and_query); | |||
const bool used_only = params.find("usedonly") != params.end(); | |||
const absl::optional<std::regex> regex = | |||
(params.find("filter") != params.end()) | |||
? absl::optional<std::regex>{std::regex(params.at("filter"))} |
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'd probably split this up into multiple lines for the sake of readability
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.
Drive by, this is already computed above in handlerStats()
. I would just pass that computation to this function.
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.
@mattklein123 I was actually looking at https://github.com/envoyproxy/envoy/blob/89a82de7a8368cd93b1255dfb3818f497330faf2/source/server/http/admin.cc#L1208 and seems like there is no good way unless we want to change the definition of MAKE_ADMIN_HANDLER. It is when the method is called from top-level api handler.
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 see, OK. Maybe just make a smaller helper method?
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.
Helper method added.
source/server/http/admin.h
Outdated
@@ -437,6 +438,12 @@ class PrometheusStatsFormatter { | |||
static bool shouldShowMetric(const std::shared_ptr<Stats::Metric>& metric, const bool used_only) { |
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 this still used?
dbe161f
to
89a82de
Compare
@snowp Hi, thanks for reviewing! I pushed my code to address your comments, and also added a unit test to exercise the regex for prometheus stats. |
89a82de
to
1b93272
Compare
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.
One minor comment, otherwise this LGTM
source/server/http/admin.h
Outdated
@@ -220,6 +220,11 @@ class AdminImpl : public Admin, | |||
bool used_only, | |||
const absl::optional<std::regex> regex = absl::nullopt, | |||
bool pretty_print = false); | |||
static absl::optional<std::regex> filterParam(Http::Utility::QueryParams params) { |
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.
Minor thing but I'd probably put this in the anonymous namespace in the .cc file, no reason to put this on the class
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.
updated
Signed-off-by: Daishan Peng <daishan@rancher.com>
1b93272
to
86f9288
Compare
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, thanks!
For the future: please avoid force pushing, individual commits make it easier to review changes made to the PR. We squash the PR before merging, so the extra commits don't matter in the end.
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 other than small nit. Thank you!
/wait
source/server/http/admin.h
Outdated
@@ -413,7 +414,8 @@ class PrometheusStatsFormatter { | |||
static uint64_t statsAsPrometheus(const std::vector<Stats::CounterSharedPtr>& counters, | |||
const std::vector<Stats::GaugeSharedPtr>& gauges, | |||
const std::vector<Stats::ParentHistogramSharedPtr>& histograms, | |||
Buffer::Instance& response, const bool used_only); | |||
Buffer::Instance& response, const bool used_only, | |||
const absl::optional<std::regex> regex); |
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: const absl::optional<std::regex>&
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.
thanks, updated!
Signed-off-by: Daishan Peng <daishan@rancher.com>
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.
Thank you!
Description: Pass regexp parameter to /stats/prometheus handler
Risk Level: low
Issue: #7173