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

Feature: Filter shortcuts in logs #2874

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

Conversation

hami-sh
Copy link

@hami-sh hami-sh commented Sep 5, 2024

This PR enables a set of shortcuts to be used when filtering through logs in k9s.

A new config file filters.yaml is defined, an example of which is shown below:

 filters:
   http_errors: '"status_code":[4-5]\d{2}'
   http_success: '"status_code":[2]\d{2}'
   info: 'info'

When using the / keybind in the logs view for a pod, a user can type the @ key followed by the name of the filter to access the pre-written regex or string they wish to match on. An example from the above would be @http_errors -- note how the title automatically resolves to the regex that was applied by the filter:

image

This is especially helpful when using complex regexes that a user might want to have close at hand when searching through logs.

@hami-sh hami-sh changed the title init commit Feature: Filter shortcuts in logs Sep 5, 2024
Copy link
Owner

@derailed derailed left a comment

Choose a reason for hiding this comment

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

@hami-sh Thank you for this PR!
I like the idea but I am not sure how useable this would be in several respects:

  1. The naming is generic and does not reflect this customization only applied to logs
  2. How does on fine tunes the filters ie if the log filters config file is changed how does one validate the exps?
  3. No auto completion how can one recall what filters are available and what do they do? (especially in light of future self and/or an org sharing common regex based on their log layouts)

Also no docs or tests are present to ensure the behavior is properly advertised and correct.

@@ -36,6 +36,7 @@ func printInfo(cmd *cobra.Command, args []string) error {
printTuple(fmat, "Plugins", config.AppPluginsFile, color.Cyan)
printTuple(fmat, "Hotkeys", config.AppHotKeysFile, color.Cyan)
printTuple(fmat, "Aliases", config.AppAliasesFile, color.Cyan)
printTuple(fmat, "Filters", config.AppFilterFile, color.Cyan)
Copy link
Owner

Choose a reason for hiding this comment

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

Given these are only available in the logs we should name this accordingly aka LogFilters or something like that.

} else {
customFilter, ok := l.filterConfig.Filters[q[1:]]
if !ok {
log.Debug().Msgf("Failed to find custom filter for: %s", q)
Copy link
Owner

Choose a reason for hiding this comment

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

Not really useful best to fire off an error so the view can display a flash to the user.

@derailed derailed added enhancement New feature or request needs-tlc Pr needs additional updates labels Sep 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request needs-tlc Pr needs additional updates
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants