Skip to content

Commit

Permalink
fix: incorrect handling of json_v2 timestamp_path (#10618)
Browse files Browse the repository at this point in the history
(cherry picked from commit 25e8b45)
  • Loading branch information
mark-rushakoff authored and powersj committed Feb 16, 2022
1 parent 84d0161 commit 94543b3
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions plugins/parsers/json_v2/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
file f="value" 1644434944000000000
4 changes: 4 additions & 0 deletions plugins/parsers/json_v2/testdata/timestamp_rfc3339/input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"when": "2022-02-09T19:29:04Z",
"f": "value"
}
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 94543b3

Please sign in to comment.