Skip to content
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

prometheus: revert the condition for enabling aggregation #2232

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions src/core/prometheus.cc
Original file line number Diff line number Diff line change
Expand Up @@ -735,15 +735,15 @@ std::string get_value_as_string(std::stringstream& s, const mi::metric_value& va
return value_str;
}

future<> write_text_representation(output_stream<char>& out, const config& ctx, const metric_family_range& m, bool show_help, bool disable_aggregation, std::function<bool(const mi::labels_type&)> filter) {
return seastar::async([&ctx, &out, &m, show_help, disable_aggregation, filter] () mutable {
future<> write_text_representation(output_stream<char>& out, const config& ctx, const metric_family_range& m, bool show_help, bool enable_aggregation, std::function<bool(const mi::labels_type&)> filter) {
return seastar::async([&ctx, &out, &m, show_help, enable_aggregation, filter] () mutable {
bool found = false;
std::stringstream s;
for (metric_family& metric_family : m) {
auto name = ctx.prefix + "_" + metric_family.name();
found = false;
metric_aggregate_by_labels aggregated_values(metric_family.metadata().aggregate_labels);
bool should_aggregate = !disable_aggregation && !metric_family.metadata().aggregate_labels.empty();
bool should_aggregate = enable_aggregation && !metric_family.metadata().aggregate_labels.empty();
metric_family.foreach_metric([&s, &out, &ctx, &found, &name, &metric_family, &aggregated_values, should_aggregate, show_help, &filter](const mi::metric_value& value, const mi::metric_info& value_info) mutable {
s.clear();
s.str("");
Expand Down Expand Up @@ -788,12 +788,12 @@ future<> write_text_representation(output_stream<char>& out, const config& ctx,
});
}

future<> write_protobuf_representation(output_stream<char>& out, const config& ctx, metric_family_range& m, bool disable_aggregation, std::function<bool(const mi::labels_type&)> filter) {
return do_for_each(m, [&ctx, &out, disable_aggregation, filter=std::move(filter)](metric_family& metric_family) mutable {
future<> write_protobuf_representation(output_stream<char>& out, const config& ctx, metric_family_range& m, bool enable_aggregation, std::function<bool(const mi::labels_type&)> filter) {
return do_for_each(m, [&ctx, &out, enable_aggregation, filter=std::move(filter)](metric_family& metric_family) mutable {
std::string s;
google::protobuf::io::StringOutputStream os(&s);
metric_aggregate_by_labels aggregated_values(metric_family.metadata().aggregate_labels);
bool should_aggregate = !disable_aggregation && !metric_family.metadata().aggregate_labels.empty();
bool should_aggregate = enable_aggregation && !metric_family.metadata().aggregate_labels.empty();
auto& name = metric_family.name();
pm::MetricFamily mtf;
bool empty_metric = true;
Expand Down Expand Up @@ -896,16 +896,16 @@ class metrics_handler : public httpd::handler_base {
sstring metric_family_name = req->get_query_param("__name__");
bool prefix = trim_asterisk(metric_family_name);
bool show_help = req->get_query_param("__help__") != "false";
bool disable_aggregation = req->get_query_param("__aggregate__") != "false";
bool enable_aggregation = req->get_query_param("__aggregate__") != "false";
Copy link
Contributor

Choose a reason for hiding this comment

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

Please note that you could have fixed this bug by a one-line change - changing != to ==, and that's it. The renaming (and flipping) the variable wasn't necessary. But I agree it looks better.

Copy link
Contributor Author

@tchaikov tchaikov May 9, 2024

Choose a reason for hiding this comment

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

i knew. but i was not after a single-liner fix.

std::function<bool(const mi::labels_type&)> filter = make_filter(*req);
rep->write_body(is_protobuf_format ? "proto" : "txt", [this, is_protobuf_format, metric_family_name, prefix, show_help, disable_aggregation, filter] (output_stream<char>&& s) {
rep->write_body(is_protobuf_format ? "proto" : "txt", [this, is_protobuf_format, metric_family_name, prefix, show_help, enable_aggregation, filter] (output_stream<char>&& s) {
return do_with(metrics_families_per_shard(), output_stream<char>(std::move(s)),
[this, is_protobuf_format, prefix, &metric_family_name, show_help, disable_aggregation, filter] (metrics_families_per_shard& families, output_stream<char>& s) mutable {
return get_map_value(families).then([&s, &families, this, is_protobuf_format, prefix, &metric_family_name, show_help, disable_aggregation, filter]() mutable {
[this, is_protobuf_format, prefix, &metric_family_name, show_help, enable_aggregation, filter] (metrics_families_per_shard& families, output_stream<char>& s) mutable {
return get_map_value(families).then([&s, &families, this, is_protobuf_format, prefix, &metric_family_name, show_help, enable_aggregation, filter]() mutable {
return do_with(get_range(families, metric_family_name, prefix),
[&s, this, is_protobuf_format, show_help, disable_aggregation, filter](metric_family_range& m) {
return (is_protobuf_format) ? write_protobuf_representation(s, _ctx, m, disable_aggregation, filter) :
write_text_representation(s, _ctx, m, show_help, disable_aggregation, filter);
[&s, this, is_protobuf_format, show_help, enable_aggregation, filter](metric_family_range& m) {
return (is_protobuf_format) ? write_protobuf_representation(s, _ctx, m, enable_aggregation, filter) :
write_text_representation(s, _ctx, m, show_help, enable_aggregation, filter);
});
}).finally([&s] () mutable {
return s.close();
Expand Down
Loading