-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat(metrics): Update metrics for aliased commands #4819
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
src/server/main_service.cc
Outdated
@@ -1234,7 +1234,7 @@ void Service::DispatchCommand(ArgSlice args, SinkReplyBuilder* builder, | |||
|
|||
dfly_cntx->cid = cid; | |||
|
|||
if (!InvokeCmd(cid, args_no_cmd, builder, dfly_cntx)) { | |||
if (!InvokeCmd(cid, args_no_cmd, builder, dfly_cntx, cmd)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this might break dual word registered commands like ACL ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed so that only aliases are handled specially when counting stats, all other commands use cmd.name
, by checking if the passed in command was part of alias map
62c9812
to
0099f42
Compare
When a call is made to server, its call count and call time is counted against the string it was called with, if the user supplied command was an alias to some other command. Signed-off-by: Abhijat Malviya <[email protected]>
0099f42
to
f5b7aea
Compare
std::optional<std::string_view> orig_cmd_name = std::nullopt; | ||
if (registry_.IsAlias(cmd)) { | ||
orig_cmd_name = cmd; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another alternative to this lookup would be to return more info from FindExtended
, maybe a struct with some flags like whether the input was alias or not.
This current approach seems to be simple, although it comes at the expense of an extra hashmap lookup in the command execution path.
The alias map would ideally be small though so this lookup shouldn't be too bad. I would be interested to know reviewers thoughts on this though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At the end of the day, swiss tables (flat_hash_map) will use flat storage and this table is relatively small (1-2 elements per command). I don't see how this would have any measurable/observable impact on the hot path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also I would move this:
std::optional<std::string_view> orig_cmd_name = std::nullopt;
if (registry_.IsAlias(cmd)) {
orig_cmd_name = cmd;
}
inside InvokeCmd
so you don't have to pass it explicitly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We lose the cmd
value which the command was invoked with by the time we get to InvokeCmd
so I added it here as an argument.
I used std::optional
as InvokeCmd
is called in many places so a default keeps changes from being spread out, in some other call sites (eg MultiCommandSquasher
) there is not even a string to use as no command has been issued.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep but that would be a bug right? So for example, if I use the original command name on a squashing context, we will miss/increment the wrong stat right? Basically, my making the argument nonoptional, it enforces to fix/check all those paths and be sure that we always do the right thing on any context
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, I will try to address this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, small comments
std::optional<std::string_view> orig_cmd_name = std::nullopt; | ||
if (registry_.IsAlias(cmd)) { | ||
orig_cmd_name = cmd; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At the end of the day, swiss tables (flat_hash_map) will use flat storage and this table is relatively small (1-2 elements per command). I don't see how this would have any measurable/observable impact on the hot path.
std::optional<std::string_view> orig_cmd_name = std::nullopt; | ||
if (registry_.IsAlias(cmd)) { | ||
orig_cmd_name = cmd; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also I would move this:
std::optional<std::string_view> orig_cmd_name = std::nullopt;
if (registry_.IsAlias(cmd)) {
orig_cmd_name = cmd;
}
inside InvokeCmd
so you don't have to pass it explicitly
src/server/command_registry.cc
Outdated
int64_t before = absl::GetCurrentTimeNanos(); | ||
handler_(args, cmd_cntx); | ||
int64_t after = absl::GetCurrentTimeNanos(); | ||
|
||
ServerState* ss = ServerState::tlocal(); // Might have migrated thread, read after invocation | ||
int64_t execution_time_usec = (after - before) / 1000; | ||
|
||
auto& ent = command_stats_[ss->thread_index()]; | ||
const std::string_view invoked_name = orig_cmd_name.value_or(name()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't you do this on the caller ? Then you can have this function accept a string_view
, which is the command name that you will collect stats. That way you can get rid of the optional and that value_or
thingy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed to do this in InvokeCmd
and pass in string_view
(although now the optional has to be handled by caller)
Signed-off-by: Abhijat Malviya <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed f2f, Abhi will follow up with a PR that fixes:
- multi/exec
- squashing
- other places where we call InvokeCmd with default arguments
created #4857 for follow up |
When a call is made to server, its call count and call time is counted against the string it was called with, if the command was found to be an alias.
Fixes #4068
Follow up PR to #4782