Skip to content

Conversation

sarub0b0
Copy link
Owner

@sarub0b0 sarub0b0 commented Sep 28, 2025

Summary

To improve the readability of JSON logs, this PR adds a jq:<expr> filter syntax to the log query input form. This allows extracting specific fields and restructuring output inline in the query.
JMESPath will be added in a subsequent PR (jmespath:<expr>).

Background

As noted in the issue, raw JSON logs can be verbose and make it hard to quickly reach the needed information during operations. Allowing a filter expression directly in the query enables on-the-fly transformation into a more readable view.

Scope (this PR)

  • New syntax: jq:<expr>

    • If a log line is valid JSON, apply <expr> and render the result.
    • For non-JSON lines or evaluation failures, show the raw log with error context to aid debugging.
  • Works alongside existing query terms such as log: / !log:, pod:, container:.

  • Help: add jq: documentation and examples to the query help.

  • Documentation: update README with jq filter usage and examples.

Usage examples

# Example 1: show only the message
pod:api log:error jq:.message

# Example 2: restructure to {ts, level, msg}
pod:api jq:'{ts:.time, level:.level, msg:.msg}'

Compatibility

  • Default behavior is unchanged unless jq: is specified.
  • No breaking changes to existing text filters or resource selectors.

Tests

  • Parser: jq: tokenization, quoting/escaping, rule when multiple jq: are provided (last one wins).
  • Filter compilation: valid/invalid jq expressions, error handling, combination with other filters.
  • Runtime: extraction/restructuring, invalid expressions, non-JSON lines, jq evaluation errors, pretty print combinations, multi-value queries.
  • Help: jq: entry appears correctly in help dialog.

Added 16 comprehensive tests covering parser, compilation, and log rendering scenarios.

Future work (separate PRs)

  • jmespath:<expr> support.

@sarub0b0 sarub0b0 linked an issue Sep 28, 2025 that may be closed by this pull request
@sarub0b0 sarub0b0 closed this Sep 28, 2025
@sarub0b0 sarub0b0 force-pushed the 809-log-query-jq-filter branch from 53cfe2e to 7c98727 Compare September 28, 2025 18:07
@sarub0b0 sarub0b0 reopened this Sep 28, 2025
@sarub0b0 sarub0b0 force-pushed the 809-log-query-jq-filter branch 2 times, most recently from 2414676 to 14af0c7 Compare October 18, 2025 19:51
@sarub0b0 sarub0b0 marked this pull request as ready for review October 18, 2025 19:52
@sarub0b0 sarub0b0 force-pushed the 809-log-query-jq-filter branch 2 times, most recently from 363c543 to 23980b8 Compare October 18, 2025 19:59
sarub0b0 and others added 4 commits October 19, 2025 05:03
Add jaq-core, jaq-std, and jaq-json crates to enable jq-style
filtering of JSON logs in the log query feature.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Add jq filter support to the log query feature, allowing users to
extract fields and restructure JSON log output on-the-fly.

Key changes:
- Add jq:<expr> syntax to log query parser
- Implement JqProgram and JsonFilter types with compilation and error handling
- Apply jq filters in LogCollector with fallback to original logs on errors
- Add comprehensive tests for parser, compilation, and log rendering
- Improve error messages to show original logs when jq evaluation fails

Usage examples:
- jq:.message (extract message field)
- jq:{ts:.time,lvl:.level,msg:.msg} (restructure output)
- pod:api log:error jq:.message (combine with other filters)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Add jq:<expr> query syntax to the help dialog displayed when
users enter '?' or 'help' in the log query form.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Update README with jq filter feature documentation:
- Add jq:<expr> to supported queries table with description and examples
- Add usage example combining jq with other filters
- Update query syntax grammar to include JQ rule

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@sarub0b0 sarub0b0 force-pushed the 809-log-query-jq-filter branch from 23980b8 to 4447824 Compare October 18, 2025 20:03
@sarub0b0 sarub0b0 merged commit aa322df into main Oct 18, 2025
1 check passed
@sarub0b0 sarub0b0 deleted the 809-log-query-jq-filter branch October 18, 2025 20:11
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.

Enhance JSON logging

1 participant