feat(log-query): add 'jmespath:' filter syntax as alternative to jq for JSON log processing #852
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds JMESPath filter syntax (
jmespath:
) to the log query feature as an alternative to thejq:
filter. JMESPath provides a different JSON query language that some users may find more intuitive for certain use cases.Motivation
Changes
New Query Syntax
jmespath:<expression>
- Filter JSON logs using JMESPath expressionsjmes:
,jm:
pod:api log:error jmespath:message
orpod:api jm:data.userId
Implementation Details
JsonFilter
enum withJMESPath
variant alongsideJq
JMESPathProgram
struct to hold compiled expressions with'static
lifetimejmespath_expression
parser to handle the new syntax with three aliasesjmespath
crate (v0.4.0 with sync feature)jq:
filter (last one specified wins, consistent with other single-value filters)FilterError::JMESPathCompile
for compilation errors (holdsJmespathError
directly)Error Handling
Query Compatibility
log:
/!log:
,pod:
,container:
, label selectors, etc.Testing
Added 22 comprehensive tests covering:
Parser tests (9 tests):
jmespath:
,jmes:
, andjm:
syntax variants (5 test cases)attribute
parser (3 test cases)parse_attributes
(1 test case)Filter tests (8 tests):
LogCollector tests (6 tests):
All 491 tests passing (469 existing + 22 new)
Documentation
jmespath:<expr>
with aliases in the query referenceCommits
Related: #809
Follows: #841 (jq filter implementation)