fix(parsers.json_v2): Handle measurements with multiple objects correctly (#16878)
This commit is contained in:
parent
f5404aee67
commit
c31d402b72
|
|
@ -151,6 +151,8 @@ func (p *Parser) parseCriticalPath(input []byte) ([]telegraf.Metric, error) {
|
|||
}
|
||||
|
||||
var metrics []telegraf.Metric
|
||||
// timestamp defaults to current time
|
||||
now := time.Now()
|
||||
|
||||
for _, c := range p.Configs {
|
||||
// Measurement name can either be hardcoded, or parsed from the JSON using a GJSON path expression
|
||||
|
|
@ -162,8 +164,8 @@ func (p *Parser) parseCriticalPath(input []byte) ([]telegraf.Metric, error) {
|
|||
}
|
||||
}
|
||||
|
||||
// timestamp defaults to current time, or can be parsed from the JSON using a GJSON path expression
|
||||
timestamp := time.Now()
|
||||
// timestamp can be parsed from the JSON using a GJSON path expression
|
||||
timestamp := now
|
||||
if c.TimestampPath != "" {
|
||||
result := gjson.GetBytes(input, c.TimestampPath)
|
||||
|
||||
|
|
@ -200,13 +202,15 @@ func (p *Parser) parseCriticalPath(input []byte) ([]telegraf.Metric, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
metrics = append(metrics, cartesianProduct(tags, fields)...)
|
||||
cmetrics := cartesianProduct(tags, fields)
|
||||
|
||||
if len(objects) != 0 && len(metrics) != 0 {
|
||||
metrics = cartesianProduct(objects, metrics)
|
||||
if len(objects) != 0 && len(cmetrics) != 0 {
|
||||
cmetrics = cartesianProduct(objects, cmetrics)
|
||||
} else {
|
||||
metrics = append(metrics, objects...)
|
||||
cmetrics = append(cmetrics, objects...)
|
||||
}
|
||||
|
||||
metrics = append(metrics, cmetrics...)
|
||||
}
|
||||
|
||||
for k, v := range p.DefaultTags {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
api_http_status_codes 200=11586,201=16,202=14,204=8,404=43,500=0,503=0 1741532840501119000
|
||||
api_requests requests=11668 1741532840501225000
|
||||
api_responses responses=11667 1741532840501263000
|
||||
api_av sessions_added=0,sessions_removed=0 1741544068286646000
|
||||
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
{
|
||||
"api": {
|
||||
"http_status_codes": {
|
||||
"200": 11586,
|
||||
"201": 16,
|
||||
"202": 14,
|
||||
"204": 8,
|
||||
"404": 43,
|
||||
"500": 0,
|
||||
"503": 0
|
||||
},
|
||||
"requests": 11668,
|
||||
"responses": 11667,
|
||||
"av": {
|
||||
"sessions": {
|
||||
"added": 0,
|
||||
"removed": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
[[inputs.file]]
|
||||
files = ["./testdata/object_multiple/input.json"]
|
||||
data_format = "json_v2"
|
||||
|
||||
[[inputs.file.json_v2]]
|
||||
measurement_name = "api_http_status_codes"
|
||||
[[inputs.file.json_v2.object]]
|
||||
path = "api.http_status_codes"
|
||||
|
||||
[[inputs.file.json_v2]]
|
||||
measurement_name = "api_requests"
|
||||
[[inputs.file.json_v2.field]]
|
||||
path = "api.requests"
|
||||
|
||||
[[inputs.file.json_v2]]
|
||||
measurement_name = "api_responses"
|
||||
[[inputs.file.json_v2.field]]
|
||||
path = "api.responses"
|
||||
|
||||
[[inputs.file.json_v2]]
|
||||
measurement_name = "api_av"
|
||||
[[inputs.file.json_v2.object]]
|
||||
path = "api.av"
|
||||
Loading…
Reference in New Issue