diff --git a/src/v/redpanda/admin/api-doc/debug.json b/src/v/redpanda/admin/api-doc/debug.json index 45c329571bf01..cadd89ec5064b 100644 --- a/src/v/redpanda/admin/api-doc/debug.json +++ b/src/v/redpanda/admin/api-doc/debug.json @@ -601,6 +601,13 @@ "required": false, "allowMultiple": false, "type": "long" + }, + { + "name": "wait_ms", + "in": "query", + "required": false, + "allowMultiple": false, + "type": "long" } ] } diff --git a/src/v/redpanda/admin_server.cc b/src/v/redpanda/admin_server.cc index ab2a4c778745b..dac5e03381941 100644 --- a/src/v/redpanda/admin_server.cc +++ b/src/v/redpanda/admin_server.cc @@ -5461,7 +5461,31 @@ admin_server::cpu_profile_handler(std::unique_ptr req) { } } - auto profiles = co_await _cpu_profiler.local().results(shard_id); + std::optional wait_ms; + if (auto e = req->get_query_param("wait_ms"); !e.empty()) { + try { + wait_ms = std::chrono::milliseconds( + boost::lexical_cast(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 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 response{ profiles.size()};