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(kv): implement KeysWithFilters and ListKeysWithFilters with tests #1711

Merged
merged 4 commits into from
Dec 27, 2024

Conversation

somratdutta
Copy link
Contributor

@somratdutta somratdutta commented Sep 4, 2024

  • Added KeysWithFilters to filter and return a list of matching keys.
  • Added ListKeysWithFilters to filter keys and return them as an iterable lister.
  • Included test cases for both methods to validate filtering logic and key retrieval.

Resolves: #1655

- Added `KeysWithFilters` to filter and return a list of matching keys.
- Added `ListKeysWithFilters` to filter keys and return them as an iterable lister.
- Included test cases for both methods to validate filtering logic and key retrieval.
@Jarema Jarema requested a review from piotrpio November 13, 2024 12:27
Copy link
Collaborator

@piotrpio piotrpio left a comment

Choose a reason for hiding this comment

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

Hello @somratdutta, thank you for the contribution and sorry it took so long to review this. There are a few issues with this PR and it'll be easier to list them in a single comment rather than commenting on individual lines:

  1. The filtering should not be done client-side, for a few reasons. Firstly, it is not efficient as you're fetching all keys from the server, even if you're interested in 1% of them based on the provided filter. Secondly, the filter you apply will not work with wildcards, which users should be able to provide. For filtering, we should leverage the FilterSubjects field on ConsumerConfig and let the server do the work and simply return results to the user.
    That presents another issue unfortunately. While you can add a single filter to Watch() and use it to filter the keys (instead of WatchAll()), there currently is no version of Watch() which accepts multiple filters.

  2. We agreed internally that we don't really want to bloat the API with too many new methods, so we settled on adding a single one: ListKeysFiltered(ctx context.Context, filters ...string) (KeyLister, error). This will allow us to add 0 or more keys easily and iterate over results in efficient way (not having to allocate memory for all keys at once if there are many of them). Also in this new method WatchOpt can be dropped as it does not really contribute to the result.

I understand that this was not properly outlined in the related issue, apologies for that. Here's my proposal - I'll work on adding a watcher which can accept multiple filters (it should not take longer than 1-2 days I hope) and after it's done you'll be able to rework this PR to use this new API - obviously if you're still willing to.

@somratdutta
Copy link
Contributor Author

somratdutta commented Nov 14, 2024

Thanks, @piotrpio for the detailed feedback on the PR.
I now get the approach and it makes a lot of sense.
I would love to still work on it as I have previously worked on many NATS-related PRs.
FYI : I am currently working on adding Jetstream support to Nats-Flink connector 😄

@piotrpio
Copy link
Collaborator

Hello @somratdutta! We've merged the PR for WatchFiltered (#1739) so you can continue with this PR now :)

@piotrpio
Copy link
Collaborator

@somratdutta could you let us know if you'll be working on that? If you don't have time for that, I can continue your work :)

@somratdutta
Copy link
Contributor Author

somratdutta commented Dec 13, 2024

@piotrpio Thanks for the ping, I was busy with the connector work and the festive seasons shenanigans :)
I will work on it tomorrow.

- Replaced custom filtering logic with the new `WatchFiltered()` method.
- Updated associated tests in `kv_test.go` to validate the new implementation with various filter patterns.
@somratdutta
Copy link
Contributor Author

@piotrpio I have added the changes, let me know if this is fine.
Thanks.

Copy link
Collaborator

@piotrpio piotrpio left a comment

Choose a reason for hiding this comment

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

In general it looks fine, but I have a few comments.

jetstream/kv.go Outdated Show resolved Hide resolved
jetstream/kv.go Outdated Show resolved Hide resolved
jetstream/kv.go Outdated Show resolved Hide resolved
jetstream/kv.go Outdated Show resolved Hide resolved
jetstream/kv.go Outdated Show resolved Hide resolved
jetstream/kv.go Outdated Show resolved Hide resolved
…ed test (#2)

* refactor(kv): utilize WatchFiltered() for key filtering logic

- Replaced custom filtering logic with the new `WatchFiltered()` method.
- Updated associated tests in `kv_test.go` to validate the new implementation with various filter patterns.

* work on comments
@somratdutta somratdutta requested a review from piotrpio December 18, 2024 04:34
@somratdutta
Copy link
Contributor Author

Hi @piotrpio.
Have worked on your feedback while back, can you verify once. 😄

@Jarema
Copy link
Member

Jarema commented Dec 27, 2024

@somratdutta we will get back to this with @piotrpio next week.

@coveralls
Copy link

Coverage Status

coverage: 84.935% (+0.08%) from 84.853%
when pulling 4354df8 on somratdutta:add-kv-filter
into 01fafde on nats-io:main.

Copy link
Collaborator

@piotrpio piotrpio left a comment

Choose a reason for hiding this comment

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

LGTM!

@piotrpio piotrpio merged commit ecb328a into nats-io:main Dec 27, 2024
4 checks passed
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.

Add KeysWithFilter methods to KV interface
4 participants