fix fluent-bit output plugin generating invalid JSON #3240
Merged
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:
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:
kubernetes
key by removing it from this list: https://github.com/grafana/helm-charts/blob/main/charts/fluent-bit/values.yaml#L20json
stepWhich 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 thelog
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
closes #3245