-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Make JSON format compatible with nulls #9110
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤝 ✅ CLA has been signed. Thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like new artifacts were built from this PR. Get them here!
Artifact URLs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to make sense to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good, makes sense. I prefer []telegraf.Metric{}
to calling make
, but returning nil should be acceptable
Telegraf expects either an object or an array of objects but nulls are valid JSON values. This commit detects if query returns a null or the document is a null to return an empty metric instead of an error. Signed-off-by: Julien Riou <julien@riou.xyz>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like new artifacts were built from this PR. Get them here!
Artifact URLs
(cherry picked from commit 4336dae)
(cherry picked from commit 4336dae)
Telegraf expects either an object or an array of objects but nulls are valid JSON values. This commit detects if query returns a null or the document is a null to return an empty metric instead of an error.
For example, with this configuration:
test.json:
test.conf:
The query returns
null
:Latest version returns an error:
This commits skip the error:
In the end, in both cases, no metric is written to the outputs.
Same tests for a null document:
test.json:
null
Document is valid:
Unpatched:
Patched:
Required for all PRs:
Return an empty list of metrics when:
gjson.Null
if a query is detected