feat(cli): add scrolling, sorting and filtering to `vector top`
Summary
This adds new features requested in #24337:
- scrolling with arrow keys (by line or by page, or top/bottom)
- sorting by any of the columns
- filtering by id, kind or type
- help menu for new keybinds
The default keybinds were partly inspired by htop, the usual keybinds (arrows) and the usual vim keybinds.
Filtering input is very basic - it doesn't support moving cursor around, only writing / deleting one character at a time. I couldn't justify adding a whole new complex component or a crate for a single input field.
Vector configuration
This is just a basic configuration, with many repeated components, to test scrolling, sorting and filtering:
api:
enabled: true
sources:
demo_logs_test:
type: "demo_logs"
format: "json"
demo_logs_test2:
type: "demo_logs"
format: "json"
demo_logs_test3:
type: "demo_logs"
format: "json"
# ... repeat many times
transforms:
demo_logs_processor:
type: "remap"
inputs: ["demo_logs_test"]
source: |
. = parse_json!(.message)
demo_logs_processor2:
type: "remap"
inputs: ["demo_logs_test2"]
source: |
. = parse_json!(.message)
# ... repeat many times
sinks:
console:
inputs: ["demo_logs_processor"]
target: "stdout"
type: "console"
encoding:
codec: "json"
console2:
inputs: ["demo_logs_processor2"]
target: "stdout"
type: "console"
encoding:
codec: "json"
# ... repeat many times
How did you test this PR?
Ran Vector with the above configuration and ran vector top separately. ? can be used to show the help window with all the keybinds for scrolling, sorting and filtering. vector top --help can be used to show the newly added CLI arguments, to start up with sort/filter options.
Change Type
- [ ] Bug fix
- [x] New feature
- [ ] Non-functional (chore, refactoring, docs)
- [ ] Performance
Is this a breaking change?
- [ ] Yes
- [x] No
Does this PR include user facing changes?
- [x] Yes. Please add a changelog fragment based on our guidelines.
- [ ] No. A maintainer will apply the
no-changeloglabel to this PR.
References
- Closes: #24337
Notes
- Please read our Vector contributor resources.
- Do not hesitate to use
@vectordotdev/vectorto reach out to us regarding this PR. - Some CI checks run only after we manually approve them.
- We recommend adding a
pre-pushhook, please see this template. - Alternatively, we recommend running the following locally before pushing to the remote branch:
make fmtmake check-clippy(if there are failures it's possible some of them can be fixed withmake clippy-fix)make test
- We recommend adding a
- After a review is requested, please avoid force pushes to help us review incrementally.
- Feel free to push as many commits as you want. They will be squashed into one before merging.
- For example, you can run
git merge origin masterandgit push.
- If this PR introduces changes Vector dependencies (modifies
Cargo.lock), please runmake build-licensesto regenerate the license inventory and commit the changes (if any). More details here.
Sponsored by Quad9