Skip to content

Commit

Permalink
wip: bench access to prom write method
Browse files Browse the repository at this point in the history
  • Loading branch information
travisdowns committed Nov 22, 2024
1 parent 97e202a commit 2742fdc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 13 deletions.
10 changes: 10 additions & 0 deletions include/seastar/core/prometheus.hh
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ future<> start(httpd::http_server_control& http_server, config ctx);
future<> add_prometheus_routes(distributed<httpd::http_server>& server, config ctx);
future<> add_prometheus_routes(httpd::http_server& server, config ctx);
/// @}

namespace details {
using filter_t = std::function<bool(const metrics::impl::labels_type&)>;

class test_access {
future<> write_body(config cfg, sstring metric_family_name, bool prefix, bool show_help, bool enable_aggregation, filter_t filter, output_stream<char>&& s);

friend struct metrics_perf_fixture;
};
}
SEASTAR_MODULE_EXPORT_END
}
}
35 changes: 22 additions & 13 deletions src/core/prometheus.cc
Original file line number Diff line number Diff line change
Expand Up @@ -924,24 +924,33 @@ class metrics_handler : public httpd::handler_base {
bool show_help = req->get_query_param("__help__") != "false";
bool enable_aggregation = req->get_query_param("__aggregate__") != "false";
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, 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, 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, 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();
});
});
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 write_body(is_protobuf_format, metric_family_name, prefix, show_help, enable_aggregation, filter, std::move(s));
});
return make_ready_future<std::unique_ptr<http::reply>>(std::move(rep));
}

private:
future<> write_body(bool is_protobuf_format, sstring metric_family_name, bool prefix, bool show_help, bool enable_aggregation, details::filter_t filter, output_stream<char>&& out_stream) {
auto s = std::move(out_stream);
auto families = metrics_families_per_shard{};
co_await get_map_value(families);

auto m = get_range(families, metric_family_name, prefix);

co_return co_await ((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] { return s.close(); });

}

friend details::test_access;
};

future<> details::test_access::write_body(config cfg, sstring metric_family_name, bool prefix, bool show_help, bool enable_aggregation, filter_t filter, output_stream<char>&& s) {
metrics_handler handler(std::move(cfg));

co_return co_await handler.write_body(cfg.allow_protobuf, metric_family_name, prefix, show_help, enable_aggregation, filter, std::move(s));
}

std::function<bool(const mi::labels_type&)> metrics_handler::_true_function = [](const mi::labels_type&) {
return true;
};
Expand Down

0 comments on commit 2742fdc

Please sign in to comment.