fix(collector): correct jsonpath alias parsing for rows missing path - #4265
Open
orangeCatDeveloper wants to merge 4 commits into
Open
fix(collector): correct jsonpath alias parsing for rows missing path#4265orangeCatDeveloper wants to merge 4 commits into
orangeCatDeveloper wants to merge 4 commits into
Conversation
Http jsonPath collection resolved alias paths with a global "parseScript + alias" query indexed by row number, so rows missing the path (e.g. pending pods without containerStatuses) misaligned every following row. Calculates like rc=$.status.containerStatuses[0].restartCount also compiled as JEXL array access and silently evaluated to null. Alias paths are now evaluated per row, and calculates equal to an aliasField skip JEXL entirely. Fixes apache#3307.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What's changed?
Fixes #3307.
A custom alias field
$.status.containerStatuses[0].restartCount(monitor pod restart count, jsonPath parsing) returns an empty or wrong column. Example response,parseScript: $.items.*:{"items": [ {"metadata": {"name": "pod-a"}, "status": {"containerStatuses": [{"restartCount": 5}]}}, {"metadata": {"name": "pod-b"}, "status": {"phase": "Pending"}}, {"metadata": {"name": "pod-c"}, "status": {"containerStatuses": [{"restartCount": 2}]}} ]}Two independent bugs. Both hit this user.
Bug 1: rows receive each other's values (
HttpCollectImpl)Problem. The alias column was filled by one global query, then distributed by row index:
pod-b has no
containerStatuses, and jayway skips it without a placeholder. Distributing[5, 2]by row index:Fix. Ask each row's own object instead of the whole response: new
JsonPathParser.parseRowWithJsonPath(rowObject, alias). A row that lacks the path returns an empty list → NULL cell. No cross-row indexing, nothing to misalign.Bug 2: the calculates step silently eats the value (
MetricsCollect)Problem.
calculates: rc=$.status.containerStatuses[0].restartCountmust be classified: is the right side a column reference or a formula? The old rule was "if it compiles as JEXL, it's a formula". This path does compile — JEXL reads[0]as array access on a variable named$.status.containerStatuses. That variable doesn't exist, so it evaluates to null with no log. The column stays empty even when Bug 1 is fixed.Fix. Before compiling, check: right side exactly equals one of the metric's
aliasFields? Then it is by definition a column reference → map it directly, skip JEXL. Real formulas keep working — docker'scpu_delta=$.cpu_stats... - $.precpu_stats...doesn't equal any single aliasField.Test plan
HttpCollectImplTest,MetricsCollectTest,JsonPathParserTest. Full collector suites pass.rcall null; after →5 / null / 2.spring_gateway(profile=$.activeProfiles[0]) anddocker(name=$.Names[0]) monitors return identical values before and after.Checklist
Add or update API