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

fix fluent-bit output plugin generating invalid JSON #3240

Merged
merged 2 commits into from
Feb 11, 2021
Merged

fix fluent-bit output plugin generating invalid JSON #3240

merged 2 commits into from
Feb 11, 2021

Conversation

sbaier1
Copy link
Contributor

@sbaier1 sbaier1 commented Jan 26, 2021

What this PR does / why we need it:

The fluent-bit output plugin incorrectly unescapes nested strings when generating JSON records. This leads to records with invalid JSON being sent to Loki, which are then no longer easily parsable with the json pipeline step as they lead to a JSON parser error in Loki's logql processor.

I added a unit-test for one of the, slightly modified, log lines that yielded the error on my fluent-bit/loki deployment, asserting a properly escaped JSON record.

An easy reproducer would be:

Which issue(s) this PR fixes:
None that i'm aware of

Special notes for your reviewer:
I'm honestly not sure whether the lineReplacer invocation has valid cases for JSON records. As of now, i can't think of a reason why it would be necessary/valid to un-escape any data in a JSON record, and the records generated with this fix are actually parse-able in Loki afterwards.

TBD: I'll verify whether this changes the records generated by the default values.yaml of the FLB chart in any way. (which only pass the log field to Loki)
-> From my tests with and without this change with the default config, the records remain the same, so it only has any effect when wrapping extra labels in a record. Therefore this change has no unwanted side-effects IMO.

Checklist

  • Documentation added <- unsure if there is any necessary here? changelog update?
  • Tests updated

closes #3245

@CLAassistant
Copy link

CLAassistant commented Jan 26, 2021

CLA assistant check
All committers have signed the CLA.

@sbaier1
Copy link
Contributor Author

sbaier1 commented Jan 27, 2021

created an issue that further explains this problem at #3245

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, I don't remember specifics, let's see.

@sbaier1
Copy link
Contributor Author

sbaier1 commented Feb 10, 2021

Do you need any input from me here?

@cyriltovena cyriltovena merged commit 9a58f83 into grafana:master Feb 11, 2021
cyriltovena pushed a commit to cyriltovena/loki that referenced this pull request Feb 15, 2021
* fix fluent-bit output plugin generating invalid JSON

* fix golint error
@sbaier1 sbaier1 deleted the fix-flb-json-escape branch December 1, 2021 19:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fluent-bit: JSON records are incorrectly un-escaped before writing to Loki
3 participants