Skip to content

Commit

Permalink
chore: tune logs and improve restrict denied error (#4145)
Browse files Browse the repository at this point in the history
1. Now error stats show "restrict_denied" instead of "Cannot execute restricted command ..." error.
2. Increased verbosity level when loading a key with expired timestamp.
3. pulled helio with better logs coverage of tls_socket.cc code.

Signed-off-by: Roman Gershman <[email protected]>
  • Loading branch information
romange authored Nov 18, 2024
1 parent 907346e commit 794bd1c
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/facade/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,6 @@ extern const char kScriptErrType[];
extern const char kConfigErrType[];
extern const char kSearchErrType[];
extern const char kWrongTypeErrType[];
extern const char kRestrictDenied[];

} // namespace facade
1 change: 1 addition & 0 deletions src/facade/facade.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ const char kScriptErrType[] = "script_error";
const char kConfigErrType[] = "config_error";
const char kSearchErrType[] = "search_error";
const char kWrongTypeErrType[] = "wrong_type";
const char kRestrictDenied[] = "restrict_denied";

const char* RespExpr::TypeName(Type t) {
switch (t) {
Expand Down
4 changes: 2 additions & 2 deletions src/server/main_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1028,9 +1028,9 @@ std::optional<ErrorReply> Service::VerifyCommandState(const CommandId* cid, CmdA
// If there is no connection owner, it means the command it being called
// from another command or used internally, therefore is always permitted.
if (dfly_cntx.conn() != nullptr && !dfly_cntx.conn()->IsPrivileged() && cid->IsRestricted()) {
VLOG(1) << "Non-admin attempt to execute " << cid->name() << " "
VLOG(1) << "Non-admin attempt to execute " << cid->name() << " " << tail_args << " "
<< ConnectionLogContext(dfly_cntx.conn());
return ErrorReply{"Cannot execute restricted command (admin only)"};
return ErrorReply{"Cannot execute restricted command (admin only)", kRestrictDenied};
}

if (auto err = cid->Validate(tail_args); err)
Expand Down
2 changes: 1 addition & 1 deletion src/server/rdb_load.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2733,7 +2733,7 @@ void RdbLoader::LoadItemsBuffer(DbIndex db_ind, const ItemsBuf& ib) {
}

if (item->expire_ms > 0 && db_cntx.time_now_ms >= item->expire_ms) {
VLOG(1) << "Expire key on load: " << item->key;
VLOG(2) << "Expire key on load: " << item->key;
continue;
}

Expand Down

0 comments on commit 794bd1c

Please sign in to comment.