Skip to content

Commit

Permalink
[chore] Remove unnecessary data copies in ottl (#35429)
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
  • Loading branch information
bogdandrutu committed Sep 26, 2024
1 parent 488a79b commit 14ea885
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pkg/ottl/ottlfuncs/func_flatten.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func flatten[K any](target ottl.PMapGetter[K], p ottl.Optional[string], d ottl.O

result := pcommon.NewMap()
flattenHelper(m, result, prefix, 0, depth)
result.CopyTo(m)
result.MoveTo(m)

return nil, nil
}, nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/ottl/ottlfuncs/func_replace_all_patterns.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func replaceAllPatterns[K any](target ottl.PMapGetter[K], mode string, regexPatt
}
return true
})
updated.CopyTo(val)
updated.MoveTo(val)
return nil, nil
}, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,13 @@ func convertExponentialHistToExplicitHist(distributionFn string, explicitBounds
return nil, nil
}

explicitHist := pmetric.NewHistogram()
// create new metric and override metric
newMetric := pmetric.NewMetric()
newMetric.SetName(metric.Name())
newMetric.SetDescription(metric.Description())
newMetric.SetUnit(metric.Unit())
explicitHist := newMetric.SetEmptyHistogram()

dps := metric.ExponentialHistogram().DataPoints()
explicitHist.SetAggregationTemporality(metric.ExponentialHistogram().AggregationTemporality())

Expand All @@ -87,19 +93,13 @@ func convertExponentialHistToExplicitHist(distributionFn string, explicitBounds
explicitHistDp.SetSum(expDataPoint.Sum())
explicitHistDp.SetMin(expDataPoint.Min())
explicitHistDp.SetMax(expDataPoint.Max())
expDataPoint.Exemplars().CopyTo(explicitHistDp.Exemplars())
expDataPoint.Exemplars().MoveAndAppendTo(explicitHistDp.Exemplars())
explicitHistDp.ExplicitBounds().FromRaw(explicitBounds)
explicitHistDp.BucketCounts().FromRaw(bucketCounts)
expDataPoint.Attributes().CopyTo(explicitHistDp.Attributes())
expDataPoint.Attributes().MoveTo(explicitHistDp.Attributes())
}

// create new metric and override metric
newMetric := pmetric.NewMetric()
newMetric.SetName(metric.Name())
newMetric.SetDescription(metric.Description())
newMetric.SetUnit(metric.Unit())
explicitHist.CopyTo(newMetric.SetEmptyHistogram())
newMetric.CopyTo(metric)
newMetric.MoveTo(metric)

return nil, nil
}, nil
Expand Down

0 comments on commit 14ea885

Please sign in to comment.