nats-io / nats.rs

Rust client for NATS, the cloud native messaging system.
Apache License 2.0
980 stars 159 forks source link

Add kv::keys with filters #1280

Open Jarema opened 1 week ago

Jarema commented 1 week ago

Proposed change

Add two new methods:

pub async fn keys_with_filters(&self, F) -> Result<Keys, HistoryError>

keys_with_fitlters require a feature flag server_2_10. That is also the reason why they are separated, instead of one method taking interator of sorts.

https://github.com/nats-io/nats-architecture-and-design/blob/main/adr/ADR-8.md?plain=1#L139 Reference ADR issue: https://github.com/nats-io/nats-architecture-and-design/issues/289

Use case

https://github.com/nats-io/nats-architecture-and-design/issues/289

Contribution

No response

TheGhoul21 commented 1 week ago

Can I try to work on this? I'm a noobie on rust though!

Jarema commented 1 week ago

Sure, go ahead! It should be pretty simple, like normal keys, just with filter(s) passed to the underlying ordered consumer.

TheGhoul21 commented 1 week ago

are unit test working? I tried to run cargo test (both on the whole project and only on keys() and get errors.

running 1 test
test kv::keys ... FAILED

failures:

---- kv::keys stdout ----
thread 'kv::keys' panicked at nats-server/src/lib.rs:268:29:
called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

failures:
    kv::keys

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 19 filtered out; finished in 0.01s

error: test failed, to rerun pass `-p async-nats --test kv_tests`

EDIT: Sorry, I got where the error comes from.

Jarema commented 1 week ago

As we updated the ADR to have just one method, please re-check the description.