From 4cfa1d331eb87e07a9964ff65c25aeab50402980 Mon Sep 17 00:00:00 2001 From: Bogdan Drutu Date: Mon, 1 Aug 2022 12:25:11 -0700 Subject: [PATCH] Fix usage of deprecated func, fix logic in merging exponential histogram (#12865) Signed-off-by: Bogdan Drutu --- .../operation_aggregate_labels.go | 24 ++++++++++++------- ...form-fix-merge-exponential-histograms.yaml | 11 +++++++++ 2 files changed, 26 insertions(+), 9 deletions(-) create mode 100755 unreleased/metricstransform-fix-merge-exponential-histograms.yaml diff --git a/processor/metricstransformprocessor/operation_aggregate_labels.go b/processor/metricstransformprocessor/operation_aggregate_labels.go index 66aa89fd37eb..eda0a3525574 100644 --- a/processor/metricstransformprocessor/operation_aggregate_labels.go +++ b/processor/metricstransformprocessor/operation_aggregate_labels.go @@ -164,9 +164,9 @@ func groupHistogramDataPoints(dps pmetric.HistogramDataPointSlice, dpsByAttrsAndTs map[string]pmetric.HistogramDataPointSlice) { for i := 0; i < dps.Len(); i++ { dp := dps.At(i) - keyHashParts := make([]interface{}, 0, len(dp.MExplicitBounds())+3) - for _, b := range dp.MExplicitBounds() { - keyHashParts = append(keyHashParts, b) + keyHashParts := make([]interface{}, 0, dp.ExplicitBounds().Len()+3) + for b := 0; b < dp.ExplicitBounds().Len(); b++ { + keyHashParts = append(keyHashParts, dp.ExplicitBounds().At(b)) } keyHashParts = append(keyHashParts, dp.HasMin(), dp.HasMax(), dp.Flags()) key := dataPointHashKey(dps.At(i).Attributes(), dp.StartTimestamp(), dp.Timestamp(), keyHashParts...) @@ -275,6 +275,7 @@ func mergeHistogramDataPoints(dpsMap map[string]pmetric.HistogramDataPointSlice, for _, dps := range dpsMap { dp := to.AppendEmpty() dps.At(0).MoveTo(dp) + counts := dp.BucketCounts().AsRaw() for i := 1; i < dps.Len(); i++ { if dps.At(i).Count() == 0 { continue @@ -288,11 +289,12 @@ func mergeHistogramDataPoints(dpsMap map[string]pmetric.HistogramDataPointSlice, dp.SetMax(dps.At(i).Max()) } dps.At(i).Exemplars().MoveAndAppendTo(dp.Exemplars()) - for b, bc := range dps.At(i).MBucketCounts() { - dp.MBucketCounts()[b] = dp.MBucketCounts()[b] + bc + for b := 0; b < dps.At(i).BucketCounts().Len(); b++ { + counts[b] += dps.At(i).BucketCounts().At(b) } dps.At(i).Exemplars().MoveAndAppendTo(dp.Exemplars()) } + dp.SetBucketCounts(pcommon.NewImmutableUInt64Slice(counts)) } } @@ -301,6 +303,8 @@ func mergeExponentialHistogramDataPoints(dpsMap map[string]pmetric.ExponentialHi for _, dps := range dpsMap { dp := to.AppendEmpty() dps.At(0).MoveTo(dp) + negatives := dp.Negative().BucketCounts().AsRaw() + positives := dp.Positive().BucketCounts().AsRaw() for i := 1; i < dps.Len(); i++ { if dps.At(i).Count() == 0 { continue @@ -313,13 +317,15 @@ func mergeExponentialHistogramDataPoints(dpsMap map[string]pmetric.ExponentialHi if dp.HasMax() && dp.Max() < dps.At(i).Max() { dp.SetMax(dps.At(i).Max()) } - for b, bc := range dps.At(i).Negative().MBucketCounts() { - dps.At(i).Negative().MBucketCounts()[b] = dps.At(i).Negative().MBucketCounts()[b] + bc + for b := 0; b < dps.At(i).Negative().BucketCounts().Len(); b++ { + negatives[b] += dps.At(i).Negative().BucketCounts().At(b) } - for b, bc := range dps.At(i).Positive().MBucketCounts() { - dps.At(i).Positive().MBucketCounts()[b] = dps.At(i).Positive().MBucketCounts()[b] + bc + for b := 0; b < dps.At(i).Positive().BucketCounts().Len(); b++ { + positives[b] += dps.At(i).Positive().BucketCounts().At(b) } dps.At(i).Exemplars().MoveAndAppendTo(dp.Exemplars()) } + dp.Negative().SetBucketCounts(pcommon.NewImmutableUInt64Slice(negatives)) + dp.Positive().SetBucketCounts(pcommon.NewImmutableUInt64Slice(positives)) } } diff --git a/unreleased/metricstransform-fix-merge-exponential-histograms.yaml b/unreleased/metricstransform-fix-merge-exponential-histograms.yaml new file mode 100755 index 000000000000..082bcaad08c2 --- /dev/null +++ b/unreleased/metricstransform-fix-merge-exponential-histograms.yaml @@ -0,0 +1,11 @@ +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: bug_fix + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: "metricstransformprocessor" + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Fix logic in merging exponential histogram. + +# One or more tracking issues related to the change +issues: [12865]