Skip to content

Commit

Permalink
admin/server: ensure that a true expire-never logger is never expired
Browse files Browse the repository at this point in the history
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 d781fb1)
  • Loading branch information
andijcr authored and vbotbuildovich committed May 13, 2024
1 parent 81f4a4e commit 14fbcfa
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/v/redpanda/admin/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<level_reset::time_point> {
// 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;
Expand Down

0 comments on commit 14fbcfa

Please sign in to comment.