From 8638a417246b0ae34f84ad5ae714ccb813a3a691 Mon Sep 17 00:00:00 2001 From: Mya Date: Tue, 22 Jun 2021 10:48:29 -0600 Subject: [PATCH] tags no longer required in included_keys (#9406) --- plugins/parsers/json_v2/parser.go | 2 ++ .../json_v2/testdata/nested_and_nonnested_tags/telegraf.conf | 2 -- plugins/parsers/json_v2/testdata/object/telegraf.conf | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/parsers/json_v2/parser.go b/plugins/parsers/json_v2/parser.go index e586b35eb..d013f6b35 100644 --- a/plugins/parsers/json_v2/parser.go +++ b/plugins/parsers/json_v2/parser.go @@ -484,6 +484,8 @@ func (p *Parser) isIncluded(key string, val gjson.Result) bool { if len(p.currentSettings.IncludedKeys) == 0 { return true } + // automatically adds tags to included_keys so it does NOT have to be repeated in the config + p.currentSettings.IncludedKeys = append(p.currentSettings.IncludedKeys, p.currentSettings.Tags...) for _, i := range p.currentSettings.IncludedKeys { if i == key { return true diff --git a/plugins/parsers/json_v2/testdata/nested_and_nonnested_tags/telegraf.conf b/plugins/parsers/json_v2/testdata/nested_and_nonnested_tags/telegraf.conf index 45692dc5d..e1748b463 100644 --- a/plugins/parsers/json_v2/testdata/nested_and_nonnested_tags/telegraf.conf +++ b/plugins/parsers/json_v2/testdata/nested_and_nonnested_tags/telegraf.conf @@ -9,10 +9,8 @@ data_format = "json_v2" disable_prepend_keys = true path = "@this" included_keys = [ - "hostname", "systemVoltage", "systemCurrent", "tables", - "tables_outputname", ] tags = ["hostname", "tables_outputname"] diff --git a/plugins/parsers/json_v2/testdata/object/telegraf.conf b/plugins/parsers/json_v2/testdata/object/telegraf.conf index 6ad244fd7..50ed245a3 100644 --- a/plugins/parsers/json_v2/testdata/object/telegraf.conf +++ b/plugins/parsers/json_v2/testdata/object/telegraf.conf @@ -6,7 +6,7 @@ [[inputs.file.json_v2.object]] path = "root.station" disable_prepend_keys = true - included_keys = ["name", "etd_destination", "etd_estimate_minutes"] + included_keys = ["etd_estimate_minutes"] tags = ["name", "etd_destination"] [inputs.file.json_v2.object.fields] etd_estimate_minutes = "int"