diff --git a/go.mod b/go.mod index 552ec08f7..9d796990d 100644 --- a/go.mod +++ b/go.mod @@ -130,7 +130,7 @@ require ( github.com/stretchr/testify v1.7.1 github.com/tbrandon/mbserver v0.0.0-20170611213546-993e1772cc62 github.com/testcontainers/testcontainers-go v0.12.0 - github.com/tidwall/gjson v1.10.2 + github.com/tidwall/gjson v1.14.1 github.com/tinylib/msgp v1.1.6 github.com/vapourismo/knx-go v0.0.0-20211128234507-8198fa17db36 github.com/vjeantet/grok v1.0.1 diff --git a/go.sum b/go.sum index 70f89ab2a..6349769a9 100644 --- a/go.sum +++ b/go.sum @@ -2176,8 +2176,8 @@ github.com/tedsuo/ifrit v0.0.0-20180802180643-bea94bb476cc/go.mod h1:eyZnKCc955u github.com/testcontainers/testcontainers-go v0.12.0 h1:SK0NryGHIx7aifF6YqReORL18aGAA4bsDPtikDVCEyg= github.com/testcontainers/testcontainers-go v0.12.0/go.mod h1:SIndOQXZng0IW8iWU1Js0ynrfZ8xcxrTtDfF6rD2pxs= github.com/tetafro/godot v1.4.4/go.mod h1:FVDd4JuKliW3UgjswZfJfHq4vAx0bD/Jd5brJjGeaz4= -github.com/tidwall/gjson v1.10.2 h1:APbLGOM0rrEkd8WBw9C24nllro4ajFuJu0Sc9hRz8Bo= -github.com/tidwall/gjson v1.10.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= +github.com/tidwall/gjson v1.14.1 h1:iymTbGkQBhveq21bEvAQ81I0LEBork8BFe1CUZXdyuo= +github.com/tidwall/gjson v1.14.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= diff --git a/plugins/parsers/json_v2/parser.go b/plugins/parsers/json_v2/parser.go index 20bf99fa9..52ba0156c 100644 --- a/plugins/parsers/json_v2/parser.go +++ b/plugins/parsers/json_v2/parser.go @@ -212,7 +212,8 @@ func (p *Parser) processMetric(input []byte, data []DataSet, tag bool, timestamp map[string]interface{}{}, timestamp, ), - Result: result, + Result: result, + ParentIndex: result.Index, } // Expand all array's and nested arrays into separate metrics @@ -296,9 +297,10 @@ func (p *Parser) expandArray(result MetricNode, timestamp time.Time) ([]telegraf ) if val.IsObject() { n := result - n.ParentIndex += val.Index n.Metric = m n.Result = val + n.Index = val.Index - result.Index + n.ParentIndex = n.Index + result.ParentIndex r, err := p.combineObject(n, timestamp) if err != nil { return false @@ -315,9 +317,10 @@ func (p *Parser) expandArray(result MetricNode, timestamp time.Time) ([]telegraf mergeMetric(result.Metric, m) n := result - n.ParentIndex += val.Index n.Metric = m n.Result = val + n.Index = val.Index - result.Index + n.ParentIndex = n.Index + result.ParentIndex r, err := p.expandArray(n, timestamp) if err != nil { return false @@ -454,15 +457,16 @@ func (p *Parser) processObjects(input []byte, objects []JSONObject, timestamp ti } rootObject := MetricNode{ - ParentIndex: 0, Metric: metric.New( p.measurementName, map[string]string{}, map[string]interface{}{}, timestamp, ), - Result: result, + Result: result, + ParentIndex: 0, } + metrics, err := p.expandArray(rootObject, timestamp) if err != nil { return nil, err @@ -534,6 +538,8 @@ func (p *Parser) combineObject(result MetricNode, timestamp time.Time) ([]telegr return false } } else { + arrayNode.Index -= result.Index + arrayNode.ParentIndex -= result.Index r, err := p.expandArray(arrayNode, timestamp) if err != nil { return false