Skip to content

support negative filtering for client command filters #2378

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

Open
wants to merge 3 commits into
base: unstable
Choose a base branch
from

Conversation

soloestoy
Copy link
Member

@soloestoy soloestoy commented Jul 24, 2025

introduce negative filters for CLIENT LIST and CLIENT KILL commands:

  1. NOT-ID: Excludes clients in the IDs set
  2. NOT-TYPE: Excludes clients of the specified type
  3. NOT-ADDR: Excludes clients of the specified address and port
  4. NOT-LADDR: Excludes clients connected to the specified local address and port
  5. NOT-USER: Excludes clients of the specified user
  6. NOT-FLAGS: Excludes clients with the specified flag string
  7. NOT-NAME: Excludes clients with the specified name
  8. NOT-LIB-NAME: Excludes clients using the specified library name
  9. NOT-LIB-VER: Excludes clients with the specified library version
  10. NOT-DB: Excludes clients with the specified database ID
  11. NOT-CAPA: Excludes clients with the specified capabilities
  12. NOT-IP: Excludes clients with the specified IP address

close #1936

and fix the matching algorithm for flag 'N'.

@soloestoy soloestoy requested review from sarthakaggarwal97, hpatro and a team July 24, 2025 09:33
@soloestoy soloestoy moved this to In Progress in Valkey 9.0 Jul 24, 2025
Signed-off-by: zhaozhao.zz <[email protected]>
Copy link

codecov bot commented Jul 24, 2025

Codecov Report

❌ Patch coverage is 88.99083% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.53%. Comparing base (de76586) to head (41b1325).
⚠️ Report is 11 commits behind head on unstable.

Files with missing lines Patch % Lines
src/networking.c 88.99% 12 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           unstable    #2378      +/-   ##
============================================
+ Coverage     71.41%   71.53%   +0.11%     
============================================
  Files           123      123              
  Lines         67132    67282     +150     
============================================
+ Hits          47942    48129     +187     
+ Misses        19190    19153      -37     
Files with missing lines Coverage Δ
src/commands.def 100.00% <ø> (ø)
src/networking.c 88.24% <88.99%> (+0.08%) ⬆️

... and 24 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@PingXie PingXie requested a review from Copilot July 28, 2025 02:46
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces comprehensive negative filtering support for CLIENT LIST and CLIENT KILL commands, adding 14 new NOT-* filter types that exclude clients matching specified criteria instead of including them. The implementation allows combining positive and negative filters for more granular client management.

Key changes:

  • Added 14 new negative filter types (NOT-ID, NOT-MAXAGE, NOT-TYPE, etc.) for both CLIENT LIST and CLIENT KILL commands
  • Extended the clientFilter structure to support parallel negative filtering fields
  • Updated command documentation and argument definitions to reflect the new capabilities

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/networking.c Core implementation of negative filtering logic in clientFilter struct and parsing/matching functions
tests/unit/introspection.tcl Comprehensive test coverage for all new negative filter types and combinations
src/commands/client-list.json Command specification updates for CLIENT LIST negative filters
src/commands/client-kill.json Command specification updates for CLIENT KILL negative filters
src/commands.def Command definition updates including argument counts and structures

c->flag.unix_socket || c->flag.readonly ||
c->flag.no_evict || c->flag.no_touch ||
c->flag.import_source) {
return 0;
}
Copy link
Preview

Copilot AI Jul 28, 2025

Choose a reason for hiding this comment

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

The logic for the 'N' flag check is inverted. When any flag is present, it should return 0 (no match for 'N'), but when no flags are present, it should return 1 (match for 'N'). The current logic returns 0 when flags are present but doesn't return 1 when no flags are present.

Suggested change
}
}
return 1; /* Explicitly return 1 when no flags are present */

Copilot uses AI. Check for mistakes.

Copy link
Member

@madolson madolson left a comment

Choose a reason for hiding this comment

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

One high level comment, but the code looked mostly good. I liked some of the other improvements you made as well.

!c->flag.no_evict && !c->flag.no_touch &&
!c->flag.import_source) {
return 1; /* Matches 'N' */
if (c->flag.replica || c->flag.primary || c->flag.pubsub ||
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason you changed this

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, I'd also like to know this.

Copy link
Member Author

@soloestoy soloestoy Jul 29, 2025

Choose a reason for hiding this comment

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

it is a bugfix, witch the bug can lead to the test case fails:

    # Test CLIENT LIST with NOT-FLAGS filter
    test {CLIENT LIST with NOT-FLAGS filter} {
        set c1 [valkey_client]
        $c1 readonly
        set cl [r client list not-flags N]
        assert_match "*flags=r*" $cl
        assert_no_match "*flags=N*" $cl
        catch {$c1 close}
    }

with the old code, the READONLY client cannot match the condition:

        case 'N': /* Check for no flags */
            if (!c->flag.replica && !c->flag.primary && !c->flag.pubsub &&
                !c->flag.multi && !c->flag.blocked && !c->flag.tracking &&
                !c->flag.tracking_broken_redir && !c->flag.tracking_bcast &&
                !c->flag.dirty_cas && !c->flag.close_after_reply &&
                !c->flag.unblocked && !c->flag.close_asap &&
                !c->flag.unix_socket && !c->flag.readonly &&
                !c->flag.no_evict && !c->flag.no_touch &&
                !c->flag.import_source) {
                return 1; /* Matches 'N' */
            }
            break;
        default:
            /* Invalid flag, return false */
            return 0;
        }
    }
    /* If the loop completes, the client matches the flag filter */
    return 1;
}

but return the wrong "1" after the loop completes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

[NEW] Negative filtering for client command filters
4 participants