From 25e8b45284e0abad5e5f33074aae4cff64440848 Mon Sep 17 00:00:00 2001 From: Mark Rushakoff Date: Tue, 15 Feb 2022 10:08:53 -0500 Subject: [PATCH] fix: incorrect handling of json_v2 timestamp_path (#10618) --- plugins/parsers/json_v2/parser.go | 4 ++-- .../json_v2/testdata/timestamp_rfc3339/expected.out | 1 + .../parsers/json_v2/testdata/timestamp_rfc3339/input.json | 4 ++++ .../json_v2/testdata/timestamp_rfc3339/telegraf.conf | 8 ++++++++ 4 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 plugins/parsers/json_v2/testdata/timestamp_rfc3339/expected.out create mode 100644 plugins/parsers/json_v2/testdata/timestamp_rfc3339/input.json create mode 100644 plugins/parsers/json_v2/testdata/timestamp_rfc3339/telegraf.conf diff --git a/plugins/parsers/json_v2/parser.go b/plugins/parsers/json_v2/parser.go index 43ea43d65c6f5..64153f1cfcbb7 100644 --- a/plugins/parsers/json_v2/parser.go +++ b/plugins/parsers/json_v2/parser.go @@ -125,7 +125,7 @@ func (p *Parser) Parse(input []byte) ([]telegraf.Metric, error) { } var err error - p.timestamp, err = internal.ParseTimestamp(c.TimestampFormat, result.Raw, c.TimestampTimezone) + p.timestamp, err = internal.ParseTimestamp(c.TimestampFormat, result.String(), c.TimestampTimezone) if err != nil { return nil, err } @@ -327,7 +327,7 @@ func (p *Parser) expandArray(result MetricNode) ([]telegraf.Metric, error) { err := fmt.Errorf("use of 'timestamp_query' requires 'timestamp_format'") return nil, err } - timestamp, err := internal.ParseTimestamp(p.objectConfig.TimestampFormat, result.Raw, p.objectConfig.TimestampTimezone) + timestamp, err := internal.ParseTimestamp(p.objectConfig.TimestampFormat, result.String(), p.objectConfig.TimestampTimezone) if err != nil { return nil, err } diff --git a/plugins/parsers/json_v2/testdata/timestamp_rfc3339/expected.out b/plugins/parsers/json_v2/testdata/timestamp_rfc3339/expected.out new file mode 100644 index 0000000000000..8d1e1285501f8 --- /dev/null +++ b/plugins/parsers/json_v2/testdata/timestamp_rfc3339/expected.out @@ -0,0 +1 @@ +file f="value" 1644434944000000000 diff --git a/plugins/parsers/json_v2/testdata/timestamp_rfc3339/input.json b/plugins/parsers/json_v2/testdata/timestamp_rfc3339/input.json new file mode 100644 index 0000000000000..9e02e0149ef14 --- /dev/null +++ b/plugins/parsers/json_v2/testdata/timestamp_rfc3339/input.json @@ -0,0 +1,4 @@ +{ + "when": "2022-02-09T19:29:04Z", + "f": "value" +} diff --git a/plugins/parsers/json_v2/testdata/timestamp_rfc3339/telegraf.conf b/plugins/parsers/json_v2/testdata/timestamp_rfc3339/telegraf.conf new file mode 100644 index 0000000000000..6329c6046c7f6 --- /dev/null +++ b/plugins/parsers/json_v2/testdata/timestamp_rfc3339/telegraf.conf @@ -0,0 +1,8 @@ +[[inputs.file]] + files = ["./testdata/timestamp_rfc3339/input.json"] + data_format = "json_v2" + [[inputs.file.json_v2]] + timestamp_path = "when" + timestamp_format = "rfc3339" + [[inputs.file.json_v2.field]] + path = "f"