From 14fbcfaaef11bfa1588b3dddaa2c671e6700cf90 Mon Sep 17 00:00:00 2001 From: Andrea Barbadoro Date: Fri, 10 May 2024 17:38:18 +0200 Subject: [PATCH] admin/server: ensure that a true expire-never logger is never expired previously, this sequence of actions set log-level raft trace 10 set log-level raft error 0 would result in raft logging at error level for only 10 seconds, despite the legit request to expire never. this is because in the code, the second request would not correctly reset the expire field if a previous name-level_reset was already in the map used for this operation (cherry picked from commit d781fb13e6051bf3b01821b9faac4687fa69f1c6) --- src/v/redpanda/admin/server.cc | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/v/redpanda/admin/server.cc b/src/v/redpanda/admin/server.cc index 453bc60e5bb2..b5533f81b68a 100644 --- a/src/v/redpanda/admin/server.cc +++ b/src/v/redpanda/admin/server.cc @@ -1437,17 +1437,20 @@ void admin_server::register_config_routes() { ss::global_logger_registry().set_logger_level(name, new_level); - // expires=0 is same as not specifying it at all - if (expires_v / 1s > 0) { - auto when = ss::timer<>::clock::now() + expires_v; - auto res = _log_level_resets.try_emplace(name, cur_level, when); - if (!res.second) { - res.first->second.expires = when; + auto when = [&]() -> std::optional { + // expires=0 is same as not specifying it at all + if (expires_v / 1s > 0) { + return ss::timer<>::clock::now() + expires_v; + } else { + // new log level never expires, but we still want an entry in + // the resets map as a record of the default + return std::nullopt; } - } else { - // new log level never expires, but we still want an entry in the - // resets map as a record of the default - _log_level_resets.try_emplace(name, cur_level, std::nullopt); + }(); + + auto res = _log_level_resets.try_emplace(name, cur_level, when); + if (!res.second) { + res.first->second.expires = when; } rsp.expiration = expires_v / 1s;