promtail: fix handling of JMESPath expression returning nil while parsing JSON #1179
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 this PR does / why we need it:
Currently, when a JMESPath expression - executed by the json stage - returns
nil
, the value stored in the extracted data map is JSON encoded, thusnil
gets encoded into the stringnull
.Further stages working on the extracted data (ie.
labels
) will read that value as a string containingnull
, causing some weird side effects.In this PR I propose to keep the
nil
value in the extracted map: thegetString(nil)
returns error, so subsequent stages working with string will skip it.The reason why I didn't skip storing the
nil
in the extracted map (which is another option) is because then there would be any difference between ajson
stage expression returningnil
and not having that expression at all in the config. Right now there would be no difference, but in the future may be handy to be able to differentiate them (ie. think about a stage re-encoding into JSON).Example of the issue:
Currently, given this pipeline:
And this input log:
{"message":"hello"}
At the end of the pipeline there's a label
app
whose value is the stringnull
.Checklist