fix: duplicate line_protocol when using object and fields (#9872)
This commit is contained in:
parent
9de8c987f2
commit
da5727e34c
|
|
@ -137,7 +137,7 @@ func (p *Parser) Parse(input []byte) ([]telegraf.Metric, error) {
|
|||
metrics = append(metrics, cartesianProduct(tags, fields)...)
|
||||
|
||||
if len(objects) != 0 && len(metrics) != 0 {
|
||||
metrics = append(metrics, cartesianProduct(objects, metrics)...)
|
||||
metrics = cartesianProduct(objects, metrics)
|
||||
} else {
|
||||
metrics = append(metrics, objects...)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,10 @@ func TestData(t *testing.T) {
|
|||
name string
|
||||
test string
|
||||
}{
|
||||
{
|
||||
name: "Test when using field and object together",
|
||||
test: "mix_field_and_object",
|
||||
},
|
||||
{
|
||||
name: "Test complex nesting",
|
||||
test: "complex_nesting",
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
openweather,id=2.643743e+06,name=London coord_lat=51.5085,coord_lon=-0.1257,description="few clouds",main_temp=12.54,summary="Clouds",wind_speed=2.11 1628186541000000000
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
{
|
||||
"coord": {
|
||||
"lon": -0.1257,
|
||||
"lat": 51.5085
|
||||
},
|
||||
"weather": [
|
||||
{
|
||||
"id": 801,
|
||||
"main": "Clouds",
|
||||
"description": "few clouds",
|
||||
"icon": "02n"
|
||||
}
|
||||
],
|
||||
"base": "stations",
|
||||
"main": {
|
||||
"temp": 12.54,
|
||||
"feels_like": 11.86,
|
||||
"temp_min": 10.49,
|
||||
"temp_max": 14.27,
|
||||
"pressure": 1024,
|
||||
"humidity": 77
|
||||
},
|
||||
"visibility": 10000,
|
||||
"wind": {
|
||||
"speed": 2.11,
|
||||
"deg": 254,
|
||||
"gust": 4.63
|
||||
},
|
||||
"clouds": {
|
||||
"all": 21
|
||||
},
|
||||
"dt": 1633545358,
|
||||
"sys": {
|
||||
"type": 2,
|
||||
"id": 2019646,
|
||||
"country": "GB",
|
||||
"sunrise": 1633500560,
|
||||
"sunset": 1633541256
|
||||
},
|
||||
"timezone": 3600,
|
||||
"id": 2643743,
|
||||
"name": "London",
|
||||
"cod": 200
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
[[inputs.file]]
|
||||
files = ["./testdata/mix_field_and_object/input.json"]
|
||||
data_format = "json_v2"
|
||||
[[inputs.file.json_v2]]
|
||||
measurement_name = "openweather"
|
||||
[[inputs.file.json_v2.field]]
|
||||
path = "weather.#.main"
|
||||
rename = "summary"
|
||||
[[inputs.file.json_v2.field]]
|
||||
path = "weather.#.description"
|
||||
[[inputs.file.json_v2.object]]
|
||||
path = "@this"
|
||||
included_keys = ["coord_lat", "coord_lon", "main_temp", "wind_speed"] # List of JSON keys (for a nested key, prepend the parent keys with underscores) that should be only included in result
|
||||
tags = ["id", "name"] # List of JSON keys (for a nested key, prepend the parent keys with underscores) to be a tag instead of a field
|
||||
|
||||
Loading…
Reference in New Issue