Skip to content

Commit

Permalink
redpanda: add wait_ms to cpu profiler admin API
Browse files Browse the repository at this point in the history
  • Loading branch information
ballard26 committed Nov 2, 2023
1 parent 8c91463 commit 4b7ea5a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/v/redpanda/admin/api-doc/debug.json
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,13 @@
"required": false,
"allowMultiple": false,
"type": "long"
},
{
"name": "wait_ms",
"in": "query",
"required": false,
"allowMultiple": false,
"type": "long"
}
]
}
Expand Down
26 changes: 25 additions & 1 deletion src/v/redpanda/admin_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5461,7 +5461,31 @@ admin_server::cpu_profile_handler(std::unique_ptr<ss::http::request> req) {
}
}

auto profiles = co_await _cpu_profiler.local().results(shard_id);
std::optional<std::chrono::milliseconds> wait_ms;
if (auto e = req->get_query_param("wait_ms"); !e.empty()) {
try {
wait_ms = std::chrono::milliseconds(
boost::lexical_cast<uint64_t>(e));
} catch (const boost::bad_lexical_cast&) {
throw ss::httpd::bad_param_exception(
fmt::format("Invalid parameter 'wait_ms' value {{{}}}", e));
}
}

if (wait_ms.has_value()) {
if (*wait_ms < 1ms || *wait_ms > 15min) {
throw ss::httpd::bad_param_exception(
"wait_ms must be between 1ms and 15min");
}
}

std::vector<resources::cpu_profiler::shard_samples> profiles;
if (!wait_ms) {
profiles = co_await _cpu_profiler.local().results(shard_id);
} else {
profiles = co_await _cpu_profiler.local().override_and_get_results(
*wait_ms, shard_id);
}

std::vector<ss::httpd::debug_json::cpu_profile_shard_samples> response{
profiles.size()};
Expand Down

0 comments on commit 4b7ea5a

Please sign in to comment.