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

promtail: fix handling of JMESPath expression returning nil while parsing JSON #1179

Merged
merged 1 commit into from
Oct 21, 2019

Conversation

pracucci
Copy link
Contributor

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, thus nil gets encoded into the string null.

Further stages working on the extracted data (ie. labels) will read that value as a string containing null, causing some weird side effects.

In this PR I propose to keep the nil value in the extracted map: the getString(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 a json stage expression returning nil 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:

pipeline_stages:
- json:
    expressions:
      app:
      message:
- labels:
    app:

And this input log:
{"message":"hello"}

At the end of the pipeline there's a label app whose value is the string null.

Checklist

  • Documentation added
  • Tests updated

Copy link
Contributor

@cyriltovena cyriltovena left a comment

Choose a reason for hiding this comment

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

LGTM

@cyriltovena cyriltovena merged commit 04a93b7 into grafana:master Oct 21, 2019
@pracucci pracucci deleted the fix-promtail-null-label-value branch October 22, 2019 06:37
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.

None yet

2 participants