Skip to content

Commit

Permalink
[chore] metricstransformprocessor: avoid unnecessary new metrics slic…
Browse files Browse the repository at this point in the history
…e when possible

Signed-off-by: Bogdan Drutu <[email protected]>
  • Loading branch information
bogdandrutu committed Sep 30, 2022
1 parent 1303178 commit 61fdd0d
Showing 1 changed file with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,9 @@ func (mtp *metricsTransformProcessor) processMetrics(_ context.Context, md pmetr
combinedMetric.MoveTo(metrics.AppendEmpty())
}
case Insert:
newMetrics := pmetric.NewMetricSlice()
newMetrics.EnsureCapacity(metrics.Len())
for i := 0; i < metrics.Len(); i++ {
// Save len, so we don't iterate over the newly generated metrics that are appended at the end.
mLen := metrics.Len()
for i := 0; i < mLen; i++ {
metric := metrics.At(i)
newMetric := transform.MetricIncludeFilter.extractMatchedMetric(metric)
if newMetric == (pmetric.Metric{}) {
Expand All @@ -281,10 +281,9 @@ func (mtp *metricsTransformProcessor) processMetrics(_ context.Context, md pmetr
metric.CopyTo(newMetric)
}
if transformMetric(newMetric, transform) {
newMetric.MoveTo(newMetrics.AppendEmpty())
newMetric.MoveTo(metrics.AppendEmpty())
}
}
newMetrics.MoveAndAppendTo(metrics)
case Update:
metrics.RemoveIf(func(metric pmetric.Metric) bool {
if !transform.MetricIncludeFilter.matchMetric(metric) {
Expand Down

0 comments on commit 61fdd0d

Please sign in to comment.