Skip to content

Commit 32e8acc

Browse files
danielegozzijackzampolin
authored andcommitted
Allow numeric and non-string values for tag_keys. (#1782)
* 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. * 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... * Updated changelog entries with PR and issue links.
1 parent 4d37d81 commit 32e8acc

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Features
66

7+
- [#1782](https://github.com/influxdata/telegraf/pull/1782): Allow numeric and non-string values for tag_keys.
78
- [#1694](https://github.com/influxdata/telegraf/pull/1694): Adding Gauge and Counter metric types.
89
- [#1606](https://github.com/influxdata/telegraf/pull/1606): Remove carraige returns from exec plugin output on Windows
910
- [#1674](https://github.com/influxdata/telegraf/issues/1674): elasticsearch input: configurable timeout.
@@ -23,6 +24,7 @@
2324

2425
### Bugfixes
2526

27+
- [#1746](https://github.com/influxdata/telegraf/issues/1746): Fix handling of non-string values for JSON keys listed in tag_keys.
2628
- [#1628](https://github.com/influxdata/telegraf/issues/1628): Fix mongodb input panic on version 2.2.
2729
- [#1733](https://github.com/influxdata/telegraf/issues/1733): Fix statsd scientific notation parsing
2830
- [#1716](https://github.com/influxdata/telegraf/issues/1716): Sensors plugin strconv.ParseFloat: parsing "": invalid syntax

plugins/parsers/json/parser.go

+4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ func (p *JSONParser) Parse(buf []byte) ([]telegraf.Metric, error) {
3535
switch v := jsonOut[tag].(type) {
3636
case string:
3737
tags[tag] = v
38+
case bool:
39+
tags[tag] = strconv.FormatBool(v)
40+
case float64:
41+
tags[tag] = strconv.FormatFloat(v, 'f', -1, 64)
3842
}
3943
delete(jsonOut, tag)
4044
}

0 commit comments

Comments
 (0)