-
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
Add support to parse JSON array (JSON Parser and HTTPJson) #1965
Add support to parse JSON array (JSON Parser and HTTPJson) #1965
Conversation
269d731
to
187973b
Compare
Our use case here is calling a web endpoint that already parses some data by "environment" which is tag we'd like to put on these metrics. This allows the JSON parser to parse the same metric with variable tags. |
187973b
to
8e1cefa
Compare
8e1cefa
to
e673dc5
Compare
|
||
## specifies if the incoming JSON data is an array of metric data (true) | ||
## to parse or a single object (false) | ||
array = false |
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.
couldn't the parser just figure this out without a configuration option?
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.
Yeah, probably. I'll give that a shot.
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.
@johnrengelman you can use the bytes
package to detect it with something like this:
func isarray(buf []byte) bool {
ia := bytes.IndexByte(buf, '[')
ib := bytes.IndexByte(buf, '{')
if ia > -1 && ia < ib {
return true
} else {
return false
}
}
f1325da
to
f585e60
Compare
@sparrc updated w/ your feedback. Good call on that. Must nicer. I guess I was initially thinking that explicit configuration would be appropriate, but I think just enforcing this convention works best since there's no other way to handle a root array. |
```toml | ||
[[inputs.exec]] | ||
## Commands array | ||
commands = ["/tmp/test.sh", "/usr/bin/mycollector --foo=bar"] |
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.
Can you remove test.sh
? I think the example will be a little clearer with just one command.
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.
Pushed an update for this.
f585e60
to
92459ee
Compare
```toml | ||
[[inputs.exec]] | ||
## Commands array | ||
commands = [/usr/bin/mycollector --foo=bar"] |
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.
Missing a quote.
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.
:sigh: and fixed.
92459ee
to
6b1ec87
Compare
Required for all PRs: