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

JSON parser fails on empty arrays #6125

Closed
andreykaipov opened this issue Jul 16, 2019 · 1 comment · Fixed by #6130
Closed

JSON parser fails on empty arrays #6125

andreykaipov opened this issue Jul 16, 2019 · 1 comment · Fixed by #6130
Assignees
Labels
bug unexpected problem or unintended behavior
Milestone

Comments

@andreykaipov
Copy link

I was using the http input plugin to parse out metrics out of one of our services but found Telegraf failing on an empty array (on service startup, our endpoint responds with an empty array until it receives a request).

I took a look and found the isarray function doesn't consider this edge-case. The condition for an array is ia > -1 && ia < ib, where ia is the index of [, and ib is the index of {. If { never occurs though (e.g. in an empty array), then ia is actually greater than ib. Changing the condition to ia > -1 && (ib == -1 || ia < ib) makes it work.

The errors aren't that big of a deal because Telegraf will just retry, but it'd be nice to not have any spurious errors in the logs. Lemme know if you guys would like a PR. 😄

@danielnelson danielnelson added this to the 1.11.3 milestone Jul 16, 2019
@danielnelson danielnelson self-assigned this Jul 16, 2019
@danielnelson danielnelson added the bug unexpected problem or unintended behavior label Jul 16, 2019
@andreykaipov
Copy link
Author

Thank you @danielnelson for pushing a fix out so quickly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants