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

Add CLIENT INFO filter #1776

Open
wants to merge 1 commit into
base: unstable
Choose a base branch
from

Conversation

sungming2
Copy link
Contributor

@sungming2 sungming2 commented Feb 25, 2025

Issue: #1699

Problem

The CLIENT INFO command currently returns all client details, which can be excessive. This proposal suggests adding an optional parameter to request specific fields, reducing unnecessary output and improving usability.

CLIENT INFO output:

id=5 addr=127.0.0.1:33448 laddr=127.0.0.1:6379 fd=11 name= age=118 idle=0 flags=N db=8 sub=0 psub=0 ssub=0 multi=-1 watch=0 qbuf=0 qbuf-free=0 argv-mem=10 multi-mem=0 rbs=1024 rbp=0 obl=0 oll=0 omem=0 tot-mem=1562 events=r cmd=client|info user=default redir=-1 resp=2 lib-name= lib-ver= tot-net-in=131 tot-net-out=214470 tot-cmds=4

Proposal

Enhance CLIENT INFO command by adding an optional parameter to specify the fields users want to retrieve.

CLIENT INFO [field1] [field2] [...]

Example

1. Default behavior (no parameters) remains unchanged:

client info

Output:

id=2 addr=127.0.0.1:12345 laddr=127.0.0.1:6379 fd=8 name= age=3000 idle=10 ...

2. Retrieve specific fields:

client info id addr

Output:

id=2 addr=127.0.0.1:12345

3. Retrieve a single field (No parsing required):

client info id

Output:

2

@@ -3340,98 +3340,120 @@ int isClientConnIpV6(client *c) {
return getClientPeerId(c)[0] == '[';
}

sds getClientInfoAttribute(client *client, const char *attr, int hide_user_data) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted to avoid these repetitive conditions but it seems C doesn't have a graceful way to handle it such as

attribute_map attribute_handlers[] = {
    {"id", () => { return client->id }},
    {"addr", () => { return getClientPeerId() }},
    {"laddr", () => { return getClientSockname() }},
    // Add other attributes...
};

I am open to getting any other suggestions if it doesn't look good

Copy link

codecov bot commented Feb 25, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 71.14%. Comparing base (bd951e6) to head (4f9a180).
Report is 1 commits behind head on unstable.

Additional details and impacted files
@@             Coverage Diff              @@
##           unstable    #1776      +/-   ##
============================================
+ Coverage     71.10%   71.14%   +0.04%     
============================================
  Files           123      123              
  Lines         65552    65615      +63     
============================================
+ Hits          46610    46684      +74     
+ Misses        18942    18931      -11     
Files with missing lines Coverage Δ
src/commands.def 100.00% <ø> (ø)
src/networking.c 89.00% <100.00%> (+0.15%) ⬆️

... and 12 files with indirect coverage changes

Signed-off-by: Seungmin Lee <[email protected]>
@sungming2 sungming2 marked this pull request as ready for review February 25, 2025 19:55
Copy link
Collaborator

@hpatro hpatro left a comment

Choose a reason for hiding this comment

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

Just discussed about this in our standup.

Some thought on this.

  • Do we really need it?
  • I found the regex in the tcl helper to do the job just fine.
  • I think @madolson mentioned this, it might be more beneficial for CLIENT LIST rather than CLIENT INFO. CLIENT INFO isn't that heavily used.

Would be good to hear others perspective as well.

@sungming2 sungming2 requested a review from xbasel February 26, 2025 00:02
@sungming2
Copy link
Contributor Author

sungming2 commented Feb 26, 2025

If users don’t actively use CLIENT INFO and if this filter is primarily for testing purposes, I’m fine with closing it.
What do you think? @xbasel

@xbasel
Copy link
Member

xbasel commented Feb 26, 2025

If users don’t actively use CLIENT INFO and if this filter is primarily for testing purposes, I’m fine with closing it. What do you think? @xbasel

sungming2
I'm not sure how many users actively use this command. I sometimes use CLIENT INFO (and CLIENT LIST) via valkey-cli and find it tedious to visually search for fields. I assume clients especially administrators who run commands interactively, might have the same experience.
No strong opinions either way.

Worth checking whether this is beneficial for CLIENT LIST.

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.

3 participants