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

Extended Valkey client introspection functionality #668

Open
madolson opened this issue Jun 19, 2024 · 19 comments · May be fixed by #1467
Open

Extended Valkey client introspection functionality #668

madolson opened this issue Jun 19, 2024 · 19 comments · May be fixed by #1467
Assignees
Labels
major-decision-pending Major decision pending by TSC team

Comments

@madolson
Copy link
Member

madolson commented Jun 19, 2024

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.

The following commands could work with the same set of filters.

  • CLIENT COUNT [filters...] (New command suggested)
  • CLIENT KILL [filters...]
  • CLIENT LIST [filters...]

The supported filters are to be decided. Suggestions, including already existing filters:

More filter suggestions that came up during discussions:

  • IP or CLIENT-IP, or allow overloaded ADDR ip. (The existing filter syntax ADDR ip:port is not very useful, because the client's port is ephemeral and will change for each connection.)
  • LIB-NAME
  • LIB-VER
  • DB number
  • TOT-NET-IN bytes
  • TOT-NET-OUT bytes

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
Copy link
Member Author

Originally reference from redis/redis#12311.

@madolson madolson changed the title Extended Redis client functionality Extended Redis client introspection functionality Jun 19, 2024
@hpatro
Copy link
Collaborator

hpatro commented Jun 21, 2024

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 redis/redis#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 madolson changed the title Extended Redis client introspection functionality Extended Valkey client introspection functionality Jun 21, 2024
@madolson
Copy link
Member Author

madolson commented Jun 21, 2024

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 redis/redis#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.

@hpatro hpatro self-assigned this Nov 20, 2024
@sarthakaggarwal97
Copy link
Contributor

@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?

@hpatro hpatro assigned sarthakaggarwal97 and unassigned hpatro Nov 22, 2024
@sarthakaggarwal97
Copy link
Contributor

sarthakaggarwal97 commented Nov 26, 2024

We can abstract the current filtering logic out (and add new filters) and then use it in different commands as required. In my opinion, CLIENT DESCRIBE (if approved) should be taken in a separate PR.

@hpatro
Copy link
Collaborator

hpatro commented Nov 26, 2024

I feel CLIENT LIST API would have the maximum benefit out of this filters extension as the response payload can be limited through it. @valkey-io/core-team Please add your thoughts on this. @sarthakaggarwal97 is trying to come up with a solution.

@zuiderkwast
Copy link
Contributor

CLIENT KILL has more filters than any other. Let's first add the missing ones of those to CLIENT LIST, to unify them. We can de-duplicate the parsing code too. That's a good PR to start with IMHO.

@hwware
Copy link
Member

hwware commented Nov 27, 2024

Sorry, is there the command CLIENT COUNT? new command?

@lyq2333
Copy link
Contributor

lyq2333 commented Dec 9, 2024

I like this idea. In #1398 , I hope we have a CLIENT KILL FLAGS command.

@sarthakaggarwal97
Copy link
Contributor

sarthakaggarwal97 commented Dec 10, 2024

I would like to summarize the issues that we are going to solve under #668. Please feel free to add any that I have missed.

  1. Implement KILL subcommand filters to LIST, and dedup parsing and filtering. (PR Adding Missing filters to CLIENT LIST and Dedup Parsing #1401 in progress)
  2. Extend the current filters to the list mentioned in the issue description.
  3. Introduce a new CLIENT COUNT command to return the count of clients based on the filters.
  4. Introduce a new CLIENT DESCRIBE command to scope down the fields from client info as requested by user.

@valkey-io/core-team are we good to proceed with all the above mentioned issues?

I can come with the separate issues for each, so this can be picked up by multiple people. We can even discuss in detail about each of these in their respective issues.

@zuiderkwast
Copy link
Contributor

To me, it seems safe to proceed with 1-3.

For 4, I think we should discuss it a bit more first. I don't want to add a new command that almost nobody will use (like CLUSTER SHARDS) so I want to have a good motivation about uses cases and the features (more fields? pagination?), the syntax, etc.

@zuiderkwast
Copy link
Contributor

The PR for unifying LIST and KILL is almost ready to be merged and there are already PRs for adding more filters and adding a CLIENT COUNT command.

@valkey-io/core-team Let's make a decision about which filters we actually want to add before we spend too much time on the PRs.

  1. I think CLIENT LIST PATTERN x* isn't very obvious that it's about PSUBSCRIBE patterns. Maybe we shall call it SUBSCRIBED-PATTERN instead, and similar for the other pubsub filters?

    SUBSCRIBED-PATTERN
    SUBSCRIBED-CHANNEL
    SUBSCRIBED-SHARD-CHANNEL
    
  2. Zhao mentioned that it can be useful to filter for negated flags, like client list flags !b, or maybe NOT-FLAGS b. (Mentioned in Adding Missing filters to CLIENT LIST and Dedup Parsing #1401.)

  3. Add LIB-NAME and LIB-VER filters? To detect clients from a particular application or part of application.

Can we also make a decision about adding CLIENT COUNT at the same time. With unified code for filters, it seems like very little extra code, apart from the JSON metadata of each command.

zuiderkwast pushed a commit that referenced this issue Jan 15, 2025
Adds filter options to CLIENT LIST:

    * USER <username>
      Return clients authenticated by <username>.
    * ADDR <ip:port>
      Return clients connected from the specified address.
    * LADDR <ip:port>
      Return clients connected to the specified local address.
    * SKIPME (YES|NO)
      Exclude the current client from the list (default: no).
    * MAXAGE <maxage>
      Only list connections older than the specified age.

Modifies the ID filter to CLIENT KILL to allow multiple IDs

    * ID <client-id> [<client-id>...]
      Kill connections by client ids.


This makes CLIENT LIST and CLIENT KILL accept the same options.

For backward compatibility, the default value for SKIPME is NO for
CLIENT LIST and YES for CLIENT KILL.

The MAXAGE comes from CLIENT KILL, where it *keeps* clients with the
given max age and kills the older ones. This logic becomes weird for
CLIENT LIST, but is kept for similary with CLIENT KILL, for the use case
of first testing manually using CLIENT LIST, and then running CLIENT
KILL with the same filters.

The `ID client-id [client-id ...]` no longer needs to be the last
filter. The parsing logic determines if an argument is an ID or not
based on whether it can be parsed as an integer or not.

Partly addresses: #668

---------

Signed-off-by: Sarthak Aggarwal <[email protected]>
@zuiderkwast zuiderkwast added the major-decision-pending Major decision pending by TSC team label Jan 15, 2025
@soloestoy
Copy link
Member

IP or CLIENT-IP is also a very useful filter.

@zuiderkwast
Copy link
Contributor

IP or CLIENT-IP is also a very useful filter.

We have ADDR but it is ip:port. The client port is random, not useful for filtering I think. Should we have IP instead of ADDR? Or let ADDR be used without port?

proost pushed a commit to proost/valkey that referenced this issue Jan 17, 2025
Adds filter options to CLIENT LIST:

    * USER <username>
      Return clients authenticated by <username>.
    * ADDR <ip:port>
      Return clients connected from the specified address.
    * LADDR <ip:port>
      Return clients connected to the specified local address.
    * SKIPME (YES|NO)
      Exclude the current client from the list (default: no).
    * MAXAGE <maxage>
      Only list connections older than the specified age.

Modifies the ID filter to CLIENT KILL to allow multiple IDs

    * ID <client-id> [<client-id>...]
      Kill connections by client ids.

This makes CLIENT LIST and CLIENT KILL accept the same options.

For backward compatibility, the default value for SKIPME is NO for
CLIENT LIST and YES for CLIENT KILL.

The MAXAGE comes from CLIENT KILL, where it *keeps* clients with the
given max age and kills the older ones. This logic becomes weird for
CLIENT LIST, but is kept for similary with CLIENT KILL, for the use case
of first testing manually using CLIENT LIST, and then running CLIENT
KILL with the same filters.

The `ID client-id [client-id ...]` no longer needs to be the last
filter. The parsing logic determines if an argument is an ID or not
based on whether it can be parsed as an integer or not.

Partly addresses: valkey-io#668

---------

Signed-off-by: Sarthak Aggarwal <[email protected]>
Signed-off-by: proost <[email protected]>
@hwware
Copy link
Member

hwware commented Jan 17, 2025

I propose the following candidates:

ADDR ip:port
LADDR ip:port
IDLE time
FLAG
DB
LIB-Name
tot-net-in
tot-net-out

@PingXie
Copy link
Member

PingXie commented Jan 20, 2025

I am directionally aligned with the proposal, more specifically, I like the following proposals

  1. COUNT is a good idea. I am surprised that we don't have that basic stat today and we have to resort to making the expensive INFO call.
  2. Lib name and version are very useful, which is essentially the browser's user-agent
  3. using RESP format for the client info is the right thing to do. I am not very concerned about the adoption of a new management comment. Valkey-cli is a sufficiently good distribution channel IMO.
  4. pagination for LIST or the new LIST like command is must have. The only caveat that I can think of is that we will be working with a dynamic client list across the calls.
  5. +1 on aligning the filters across the sub commands. The consistency will be a good boost for productivity and user-friendliness.
  6. negative filtering makes sense to me.

@soloestoy
Copy link
Member

We have ADDR but it is ip:port. The client port is random, not useful for filtering I think. Should we have IP instead of ADDR? Or let ADDR be used without port?

IMHO, ADDR(ip:port) is not a filter, but since it already exists, we have to continue maintaining it. We could consider adding a new filter, such as ADDR-IP.

@zuiderkwast
Copy link
Contributor

IMHO, ADDR(ip:port) is not a filter, but since it already exists, we have to continue maintaining it. We could consider adding a new filter, such as ADDR-IP.

How about overloading it and allow ADDR ip and ADDR ip:port? We can document ADDR ip as the main syntax and mention that for backward compatbibility ADDR ip:port is also supported.

Confusing? New filter is better?

kronwerk pushed a commit to kronwerk/valkey that referenced this issue Jan 27, 2025
Adds filter options to CLIENT LIST:

    * USER <username>
      Return clients authenticated by <username>.
    * ADDR <ip:port>
      Return clients connected from the specified address.
    * LADDR <ip:port>
      Return clients connected to the specified local address.
    * SKIPME (YES|NO)
      Exclude the current client from the list (default: no).
    * MAXAGE <maxage>
      Only list connections older than the specified age.

Modifies the ID filter to CLIENT KILL to allow multiple IDs

    * ID <client-id> [<client-id>...]
      Kill connections by client ids.


This makes CLIENT LIST and CLIENT KILL accept the same options.

For backward compatibility, the default value for SKIPME is NO for
CLIENT LIST and YES for CLIENT KILL.

The MAXAGE comes from CLIENT KILL, where it *keeps* clients with the
given max age and kills the older ones. This logic becomes weird for
CLIENT LIST, but is kept for similary with CLIENT KILL, for the use case
of first testing manually using CLIENT LIST, and then running CLIENT
KILL with the same filters.

The `ID client-id [client-id ...]` no longer needs to be the last
filter. The parsing logic determines if an argument is an ID or not
based on whether it can be parsed as an integer or not.

Partly addresses: valkey-io#668

---------

Signed-off-by: Sarthak Aggarwal <[email protected]>
@sarthakaggarwal97
Copy link
Contributor

sarthakaggarwal97 commented Jan 27, 2025

In my opinion, new filter sounds better for ip. I have updated the PR with rest of the discussed filters. I can update with ip filter as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
major-decision-pending Major decision pending by TSC team
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants