Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chore] metricstransformprocessor: avoid unnecessary new metrics slice when possible #14628

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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