valkey-io / valkey

A flexible distributed key-value datastore that is optimized for caching and other realtime workloads.
https://valkey.io
Other
17.39k stars 656 forks source link

Extended Valkey client introspection functionality #668

Open madolson opened 5 months ago

madolson commented 5 months ago

We want to standardize the way that admin users can describe and interact with the client commands. We are proposing to generalize the filters introduced in CLIENT KILL so that it also works to count and list clients as well.

In the end, we will support the following 4 commands.

CLIENT COUNT <filters>
CLIENT KILL <filters>
CLIENT LIST <filters>

The supported filters will be:

TYPE [NORMAL|MASTER|PRIMARY|SLAVE|REPLICA|PUBSUB]
USER username
ADDR ip:port
LADDR ip:port
SKIPME [yes|no]
ID client-id
ID client-id [client-id ...], for compatibility reasons with client list, client-id must be specified last.
PATTERN pattern the client must subscribe to
CHANNEL channel the client must subscribe to
SHARD-CHANNEL `<shard channel the client must subscribe to>`
FLAGS Client must include this flag, this option can be repeated
NAME client name
MIN-IDLE minimum idle time of the client
CLIENT DESCRIBE will allow you specify what fields you want from the client. The supported selectors will be the same as the above mentioned filters, in addition to the fields currently supported from https://redis.io/commands/client-list/.

In Redis we also discussed adding a new command, CLIENT DESCRIBE, will also introduce the notion of selectors. Selectors allow you to scope down the fields you are interested in.

CLIENT DESCRIBE SELECT ID ADDR FILTER MIN-AGE 100 
madolson commented 5 months ago

Originally reference from https://github.com/redis/redis/issues/12311.

hpatro commented 5 months ago

Nit Title: Extended Client Introspection functionality

The default behavior for CLIENT LIST API is all filters, and with that the response payload can be pretty huge. I think valkey-cli kind of gets stuck. With CLIENT DESCRIBE we can look to move away from the text format and have RESP format and get paginated response or adding a default COUNT value to restrict the payload size. I had tried that here https://github.com/redis/redis/pull/11907.

The downside of introducing the new API is maintaining two set of API(s) and no guarantee of administrator(s) of moving to this.

madolson commented 5 months ago

Nit Title: Extended Client Introspection functionality

Old habits die hard.

The default behavior for CLIENT LIST API is all filters, and with that the response payload can be pretty huge. I think valkey-cli kind of gets stuck. With CLIENT DESCRIBE we can look to move away from the text format and have RESP format and get paginated response or adding a default COUNT value to restrict the payload size. I had tried that here https://github.com/redis/redis/pull/11907.

I think you raise a really good point. We could add a pagination functionality by doing client-list based off of ID, and add that to client list. I think we have seen that people generally don't migrate to new commands, so it probably makes more sense to enhanced the ones we have.

sarthakaggarwal97 commented 2 days ago

@valkey-io/core-team I'm happy to take this issue up if this is an approved change. Please let me know if I can proceed. We would be introducing some new filters to existing COUNT, KILL and LIST sub commands. Also, would like to know if we would want to paginate the results in the current list command?