Skip to content
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

feat(server): Add support for aliasing commands #4782

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

abhijat
Copy link
Contributor

@abhijat abhijat commented Mar 17, 2025

Support for aliasing a command is added with the command line flag command_alias. Multiple aliases of the same command are allowed.

Example run:

server

./dragonfly --command_alias __set=set,doset=set

client

127.0.0.1:6379> __set foo bar
OK
127.0.0.1:6379> get foo
"bar"
127.0.0.1:6379> doset a b
OK
127.0.0.1:6379> get a
"b"
127.0.0.1:6379>

commands which have been renamed using rename_command should be aliased with the renamed command name instead of original.

TODO: update docs

@abhijat abhijat force-pushed the abhijat/feat/allow-cmd-aliasing branch 6 times, most recently from 499fe92 to be23a1a Compare March 17, 2025 08:47
abhijat added 2 commits March 17, 2025 14:18
The helper will be used to parse renamed commands as well as aliases.

Signed-off-by: Abhijat Malviya <[email protected]>
A command can be aliased by supplying the flag:

--command_alias=__PING=PING

to the server startup.

A map of alias is retained. When finding a command id, first we look up
into the original command map, then if not found there we lookup through
the command alias map. This results in two find operations for an
aliased command.

Signed-off-by: Abhijat Malviya <[email protected]>
@abhijat abhijat force-pushed the abhijat/feat/allow-cmd-aliasing branch from be23a1a to dd40902 Compare March 17, 2025 08:48
Signed-off-by: Abhijat Malviya <[email protected]>
@abhijat abhijat force-pushed the abhijat/feat/allow-cmd-aliasing branch from dd40902 to cf015a7 Compare March 17, 2025 10:10
@abhijat abhijat changed the title [wip] feat(server): Add support for aliasing commands feat(server): Add support for aliasing commands Mar 17, 2025
@abhijat
Copy link
Contributor Author

abhijat commented Mar 17, 2025

PR can be reviewed now but will wait for merge for 1.29

@abhijat abhijat requested review from kostasrim and adiholden March 17, 2025 11:09
@kostasrim
Copy link
Contributor

Mostly LGTM -- minor comments. For me I need to validate aliases and ping tomorrow.

Signed-off-by: Abhijat Malviya <[email protected]>
Signed-off-by: Abhijat Malviya <[email protected]>
@abhijat abhijat requested a review from kostasrim March 18, 2025 08:29
@adiholden
Copy link
Collaborator

The goal of this task is to be able to filter commands from dashboard.
The suggested implementation is to use command alias. Please make sure that with your implementation when executing the command alias the metrics that are exposed to Prometheus are for the alias command string

@abhijat
Copy link
Contributor Author

abhijat commented Mar 18, 2025

The goal of this task is to be able to filter commands from dashboard. The suggested implementation is to use command alias. Please make sure that with your implementation when executing the command alias the metrics that are exposed to Prometheus are for the alias command string

This is missing in this PR right now. Is there a list of metrics that are used to count the commands? I will make changes to update them for the alias.

@abhijat
Copy link
Contributor Author

abhijat commented Mar 19, 2025

@adiholden after giving this more thought I suggest that this PR should be merged as it is (once reviewed and approved etc), it is self contained and adds the aliasing feature.

I can do a follow up PR to change metrics to be counted per alias or command.

I see the metrics with command name labels are

  • commands_total
  • commands_duration_seconds

Are there any other metrics to be updated?

@adiholden
Copy link
Collaborator

adiholden commented Mar 19, 2025

I can do a follow up PR to change metrics to be counted per alias or command.

Sure, I did not review the PR. I want you to think on the next step of the implementation and see that this PR will support this change need for metrics.

I see the metrics with command name labels are

  • commands_total
  • commands_duration_seconds

Are there any other metrics to be updated?

I believe that is all.

Also not sure what is the expected behaviour for info commandstats, maybe @romange can answer this

@adiholden
Copy link
Collaborator

I can do a follow up PR to change metrics to be counted per alias or command.

Sure, I did not review the PR. I want you to think on the next step of the implementation and see that this PR will support this change need for metrics.

I see the metrics with command name labels are

  • commands_total
  • commands_duration_seconds

Are there any other metrics to be updated?

I believe that is all.

Also not sure what is the expected behaviour for info commandstats, maybe @romange can answer this

Make sure you follow up on this and you know how you are going to implement the next step so this PR will supprot the change needed for the metrics

Signed-off-by: Abhijat Malviya <[email protected]>
@abhijat abhijat requested a review from adiholden March 21, 2025 06:01
Copy link
Contributor

@kostasrim kostasrim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM minor comments

@@ -2,29 +2,29 @@
// See LICENSE for licensing terms.
//

#include "absl/strings/str_split.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#include "absl/strings/str_split.h"
#include <absl/strings/str_split.h>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

}

if (const auto it = cmd_aliases_.find(cmd); it != cmd_aliases_.end()) {
if (const auto alias_lookup = cmd_map_.find(it->second); alias_lookup != cmd_map_.end()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we expect that it->second will exist in the cmd_map_? In other words shouldn't this if be a DCHECK + a find. The registry is not mutable and the alias map is initialized during bootstrap so I would expect that this alias_lookup == cmd_map_.end() can't be true right ?

Basically what I am trying to say is that the alias map should never point to a command that does not exist in the cmd_map correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The aliases are processed before commands are registered, in the ctor of command registry. It wouldn't be possible to validate if the alias is correct at that time.

Signed-off-by: Abhijat Malviya <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants