From f28e76a812aff332cd15b82860b72e0472e6ea43 Mon Sep 17 00:00:00 2001 From: Daniele Gozzi Date: Fri, 16 Sep 2016 20:22:20 +0200 Subject: [PATCH 1/3] Allow numeric and non-string values for tag_keys. According to the go documentation the JSON deserializer only produces these base types in output: - string - bool - float64 - nil With this patch bool, float64 and nil values get converted to a string when their field key is specified in tag_keys. Previously the field was simply discarded. --- plugins/parsers/json/parser.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugins/parsers/json/parser.go b/plugins/parsers/json/parser.go index e5172ac97b116..7ebabe4075157 100644 --- a/plugins/parsers/json/parser.go +++ b/plugins/parsers/json/parser.go @@ -35,6 +35,12 @@ func (p *JSONParser) Parse(buf []byte) ([]telegraf.Metric, error) { switch v := jsonOut[tag].(type) { case string: tags[tag] = v + case bool: + tags[tag] = strconv.FormatBool(v) + case float64: + tags[tag] = strconv.FormatFloat(v, 'f', -1, 64) + case nil: + tags[tag] = "nil" } delete(jsonOut, tag) } From e3f29a0a743946fca9e53e2bcdfac5679b4c52c7 Mon Sep 17 00:00:00 2001 From: Daniele Gozzi Date: Sat, 17 Sep 2016 12:20:35 +0200 Subject: [PATCH 2/3] Updated handling of nil for passing tests. The automated tests are less than trivial to reproduece locally for me, so I hope CircleCI wonn't mind... --- plugins/parsers/json/parser.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/plugins/parsers/json/parser.go b/plugins/parsers/json/parser.go index 7ebabe4075157..180f2452aff15 100644 --- a/plugins/parsers/json/parser.go +++ b/plugins/parsers/json/parser.go @@ -39,8 +39,6 @@ func (p *JSONParser) Parse(buf []byte) ([]telegraf.Metric, error) { tags[tag] = strconv.FormatBool(v) case float64: tags[tag] = strconv.FormatFloat(v, 'f', -1, 64) - case nil: - tags[tag] = "nil" } delete(jsonOut, tag) } From e20d58353b248fb23a02aad1a439718e8946551a Mon Sep 17 00:00:00 2001 From: Daniele Gozzi Date: Wed, 21 Sep 2016 18:49:36 +0200 Subject: [PATCH 3/3] Updated changelog entries with PR and issue links. --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 994354d56a09b..0b81d4f1c5e6f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Features +- [#1782](https://github.com/influxdata/telegraf/pull/1782): Allow numeric and non-string values for tag_keys. - [#1694](https://github.com/influxdata/telegraf/pull/1694): Adding Gauge and Counter metric types. - [#1606](https://github.com/influxdata/telegraf/pull/1606): Remove carraige returns from exec plugin output on Windows - [#1674](https://github.com/influxdata/telegraf/issues/1674): elasticsearch input: configurable timeout. @@ -22,6 +23,7 @@ ### Bugfixes +- [#1746](https://github.com/influxdata/telegraf/issues/1746): Fix handling of non-string values for JSON keys listed in tag_keys. - [#1628](https://github.com/influxdata/telegraf/issues/1628): Fix mongodb input panic on version 2.2. - [#1733](https://github.com/influxdata/telegraf/issues/1733): Fix statsd scientific notation parsing - [#1716](https://github.com/influxdata/telegraf/issues/1716): Sensors plugin strconv.ParseFloat: parsing "": invalid syntax