diff --git a/plugins/parsers/json_v2/parser.go b/plugins/parsers/json_v2/parser.go index 46d089127ccdd..43f22668af89a 100644 --- a/plugins/parsers/json_v2/parser.go +++ b/plugins/parsers/json_v2/parser.go @@ -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 diff --git a/plugins/parsers/json_v2/testdata/multiple_arrays_in_object/expected.out b/plugins/parsers/json_v2/testdata/multiple_arrays_in_object/expected.out index 04cd0635a5497..8365b551cbe12 100644 --- a/plugins/parsers/json_v2/testdata/multiple_arrays_in_object/expected.out +++ b/plugins/parsers/json_v2/testdata/multiple_arrays_in_object/expected.out @@ -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" diff --git a/plugins/parsers/json_v2/testdata/object_timestamp/expected.out b/plugins/parsers/json_v2/testdata/object_timestamp/expected.out new file mode 100644 index 0000000000000..eb9fb2333e7b2 --- /dev/null +++ b/plugins/parsers/json_v2/testdata/object_timestamp/expected.out @@ -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 diff --git a/plugins/parsers/json_v2/testdata/object_timestamp/input.json b/plugins/parsers/json_v2/testdata/object_timestamp/input.json new file mode 100644 index 0000000000000..9f621a191da3d --- /dev/null +++ b/plugins/parsers/json_v2/testdata/object_timestamp/input.json @@ -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" + } + ] +} diff --git a/plugins/parsers/json_v2/testdata/object_timestamp/telegraf.conf b/plugins/parsers/json_v2/testdata/object_timestamp/telegraf.conf new file mode 100644 index 0000000000000..d9d86f622fa6b --- /dev/null +++ b/plugins/parsers/json_v2/testdata/object_timestamp/telegraf.conf @@ -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"