@@ -330,23 +330,25 @@ func (p *Plugin) Stop() {
330330
331331func (p * Plugin ) Do (event * pipeline.Event ) pipeline.ActionResult {
332332 p .mu .Lock ()
333- copyMetrics := make ([]Metric , 0 , len (p .Metrics ))
333+ metricIndices := make ([]int , 0 , len (p .Metrics ))
334334 for i := range p .Metrics {
335- if p .Metrics [i ].DoIfChecker == nil {
336- copyMetrics = append (copyMetrics , p .Metrics [i ])
337- } else {
338- if ! p .config .Metrics [i ].DoIfChecker .Check (event .Root ) {
339- continue
340- }
341- copyMetrics = append (copyMetrics , p .Metrics [i ])
342- }
343- if p .Metrics [i ].Labels != nil {
344- copyMetrics [len (copyMetrics )- 1 ].Labels = make (map [string ]string , len (p .Metrics [i ].Labels ))
345- maps .Copy (copyMetrics [len (copyMetrics )- 1 ].Labels , p .Metrics [i ].Labels )
335+ if p .Metrics [i ].DoIfChecker == nil || p .config .Metrics [i ].DoIfChecker .Check (event .Root ) {
336+ metricIndices = append (metricIndices , i )
346337 }
347338 }
348339 p .mu .Unlock ()
349340
341+ copyMetrics := make ([]Metric , 0 , len (metricIndices ))
342+ for _ , idx := range metricIndices {
343+ metric := p .Metrics [idx ]
344+ if metric .Labels != nil {
345+ labels := make (map [string ]string , len (metric .Labels ))
346+ maps .Copy (labels , metric .Labels )
347+ metric .Labels = labels
348+ }
349+ copyMetrics = append (copyMetrics , metric )
350+ }
351+
350352 var ts time.Time
351353
352354 if len (p .config .TimeField_ ) != 0 {
@@ -368,7 +370,8 @@ func (p *Plugin) Do(event *pipeline.Event) pipeline.ActionResult {
368370 }
369371
370372 children := make ([]* insaneJSON.Node , 0 , len (copyMetrics ))
371- for _ , metric := range copyMetrics {
373+ for i := range copyMetrics {
374+ metric := & copyMetrics [i ]
372375 elem := new (insaneJSON.Node )
373376 object := elem .MutateToObject ()
374377
0 commit comments