Skip to content

Commit

Permalink
fix: json_v2 parser timestamp setting (#10221)
Browse files Browse the repository at this point in the history
  • Loading branch information
powersj authored Dec 6, 2021
1 parent 7049967 commit f9d719d
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 9 deletions.
2 changes: 1 addition & 1 deletion plugins/parsers/json_v2/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ func (p *Parser) combineObject(result MetricNode) ([]telegraf.Metric, error) {
if err != nil {
return false
}
results = cartesianProduct(results, r)
results = cartesianProduct(r, results)
}

return true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
file,title=The\ Lord\ Of\ The\ Rings author="Tolkien",chapters="A Long-expected Party",name="Bilbo",species="hobbit",random=1
file,title=The\ Lord\ Of\ The\ Rings author="Tolkien",chapters="A Long-expected Party",name="Bilbo",species="hobbit",random=2
file,title=The\ Lord\ Of\ The\ Rings author="Tolkien",chapters="A Long-expected Party",name="Frodo",species="hobbit",random=1
file,title=The\ Lord\ Of\ The\ Rings author="Tolkien",chapters="A Long-expected Party",name="Frodo",species="hobbit",random=2
file,title=The\ Lord\ Of\ The\ Rings author="Tolkien",chapters="The Shadow of the Past",name="Bilbo",species="hobbit",random=1
file,title=The\ Lord\ Of\ The\ Rings author="Tolkien",chapters="The Shadow of the Past",name="Bilbo",species="hobbit",random=2
file,title=The\ Lord\ Of\ The\ Rings author="Tolkien",chapters="The Shadow of the Past",name="Frodo",species="hobbit",random=1
file,title=The\ Lord\ Of\ The\ Rings author="Tolkien",chapters="The Shadow of the Past",name="Frodo",species="hobbit",random=2
file,title=The\ Lord\ Of\ The\ Rings author="Tolkien",chapters="A Long-expected Party",name="Bilbo",random=1,species="hobbit"
file,title=The\ Lord\ Of\ The\ Rings author="Tolkien",chapters="The Shadow of the Past",name="Bilbo",random=1,species="hobbit"
file,title=The\ Lord\ Of\ The\ Rings author="Tolkien",chapters="A Long-expected Party",name="Frodo",random=1,species="hobbit"
file,title=The\ Lord\ Of\ The\ Rings author="Tolkien",chapters="The Shadow of the Past",name="Frodo",random=1,species="hobbit"
file,title=The\ Lord\ Of\ The\ Rings author="Tolkien",chapters="A Long-expected Party",name="Bilbo",random=2,species="hobbit"
file,title=The\ Lord\ Of\ The\ Rings author="Tolkien",chapters="The Shadow of the Past",name="Bilbo",random=2,species="hobbit"
file,title=The\ Lord\ Of\ The\ Rings author="Tolkien",chapters="A Long-expected Party",name="Frodo",random=2,species="hobbit"
file,title=The\ Lord\ Of\ The\ Rings author="Tolkien",chapters="The Shadow of the Past",name="Frodo",random=2,species="hobbit"
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
metric,id=100 value=100.123 1609459199000000000
metric,id=101 value=200.001 1276605000000000000
metric,id=102 value=999.999 946684800000000000
19 changes: 19 additions & 0 deletions plugins/parsers/json_v2/testdata/object_timestamp/input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"events": [
{
"id": 100,
"value": 100.123,
"time": "2020-12-31T23:59:59Z"
},
{
"id": 101,
"value": 200.001,
"time": "2010-06-15T12:30:00Z"
},
{
"id": 102,
"value": 999.999,
"time": "2000-01-01T00:00:00Z"
}
]
}
12 changes: 12 additions & 0 deletions plugins/parsers/json_v2/testdata/object_timestamp/telegraf.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[[inputs.file]]
files = ["./testdata/object_timestamp/input.json"]
data_format = "json_v2"

[[inputs.file.json_v2]]
measurement_name = "metric"

[[inputs.file.json_v2.object]]
path = "events"
tags = ["id"]
timestamp_key = "time"
timestamp_format = "2006-01-02T15:04:05Z"

0 comments on commit f9d719d

Please sign in to comment.