From aabc73123a4a06a5a52553e7799f0720c4485008 Mon Sep 17 00:00:00 2001 From: sh0rez Date: Tue, 20 Feb 2024 17:11:45 +0100 Subject: [PATCH 1/4] [processor/deltatocumulative]: process all samples Due to an oversight, the processor stopped after the first sample. It should process all available samples per stream. --- .../internal/streams/data.go | 2 +- .../internal/streams/data_test.go | 43 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/processor/deltatocumulativeprocessor/internal/streams/data.go b/processor/deltatocumulativeprocessor/internal/streams/data.go index f0f59356d56d..89073123eba3 100644 --- a/processor/deltatocumulativeprocessor/internal/streams/data.go +++ b/processor/deltatocumulativeprocessor/internal/streams/data.go @@ -43,7 +43,7 @@ func Aggregate[D data.Point[D]](m metrics.Data[D], aggr Aggregator[D]) error { return true } next.CopyTo(dp) - return false + return true }) return errs diff --git a/processor/deltatocumulativeprocessor/internal/streams/data_test.go b/processor/deltatocumulativeprocessor/internal/streams/data_test.go index 4ea5a80e1f7a..fe28ddab5318 100644 --- a/processor/deltatocumulativeprocessor/internal/streams/data_test.go +++ b/processor/deltatocumulativeprocessor/internal/streams/data_test.go @@ -10,6 +10,7 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/processor/deltatocumulativeprocessor/internal/metrics" "github.com/open-telemetry/opentelemetry-collector-contrib/processor/deltatocumulativeprocessor/internal/streams" "github.com/open-telemetry/opentelemetry-collector-contrib/processor/deltatocumulativeprocessor/internal/testdata/random" + "github.com/stretchr/testify/require" ) var rdp data.Number @@ -52,6 +53,42 @@ func BenchmarkSamples(b *testing.B) { }) } +func TestSample(t *testing.T) { + const total = 1000 + dps := generate(total) + + // check that all samples are visited + seen := 0 + streams.Samples[data.Number](dps)(func(id streams.Ident, dp data.Number) bool { + require.Equal(t, dps.id, id) + require.Equal(t, dps.dps[seen], dp) + seen++ + return true + }) + + require.Equal(t, total, seen) +} + +func TestAggregate(t *testing.T) { + const total = 1000 + dps := generate(total) + + // inv aggregator inverts each sample + inv := aggr(func(id streams.Ident, n data.Number) (data.Number, error) { + dp := n.Clone() + dp.SetIntValue(-dp.IntValue()) + return dp, nil + }) + + err := streams.Aggregate(dps, inv) + require.NoError(t, err) + + // check that all samples are inverted + for i := 0; i < total; i++ { + require.Equal(t, int64(-i), dps.dps[i].IntValue()) + } +} + func generate(n int) Data { id, ndp := random.Sum().Stream() dps := Data{id: id, dps: make([]data.Number, n)} @@ -79,3 +116,9 @@ func (l Data) Len() int { func (l Data) Ident() metrics.Ident { return l.id.Metric() } + +type aggr func(streams.Ident, data.Number) (data.Number, error) + +func (a aggr) Aggregate(id streams.Ident, dp data.Number) (data.Number, error) { + return a(id, dp) +} From fbf2f4bb43d65a264111d9324acada871f45c927 Mon Sep 17 00:00:00 2001 From: sh0rez Date: Tue, 20 Feb 2024 17:30:07 +0100 Subject: [PATCH 2/4] *: changelog --- .chloggen/deltatocumulative-all-samples.yaml | 27 ++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .chloggen/deltatocumulative-all-samples.yaml diff --git a/.chloggen/deltatocumulative-all-samples.yaml b/.chloggen/deltatocumulative-all-samples.yaml new file mode 100644 index 000000000000..6221b9d32b08 --- /dev/null +++ b/.chloggen/deltatocumulative-all-samples.yaml @@ -0,0 +1,27 @@ +# Use this changelog template to create an entry for release notes. + +# 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: "deltatocumulativeprocessor" + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: due to an oversight, only the first sample of each stream was processed. now all samples are. + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: + +# If your change doesn't affect end users or the exported elements of any package, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [] From c7bbe83348d97b22d043e5d18cf10af5a044e616 Mon Sep 17 00:00:00 2001 From: sh0rez Date: Tue, 20 Feb 2024 17:35:49 +0100 Subject: [PATCH 3/4] *: changelog issue nr --- .chloggen/deltatocumulative-all-samples.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.chloggen/deltatocumulative-all-samples.yaml b/.chloggen/deltatocumulative-all-samples.yaml index 6221b9d32b08..558f5d9e65cc 100644 --- a/.chloggen/deltatocumulative-all-samples.yaml +++ b/.chloggen/deltatocumulative-all-samples.yaml @@ -10,7 +10,7 @@ component: "deltatocumulativeprocessor" note: due to an oversight, only the first sample of each stream was processed. now all samples are. # Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. -issues: [] +issues: [31350] # (Optional) One or more lines of additional information to render under the primary note. # These lines will be padded with 2 spaces and then inserted directly into the document. From 65834c97c18e98191235c0664d85bfcdde69465c Mon Sep 17 00:00:00 2001 From: sh0rez Date: Wed, 21 Feb 2024 12:12:47 +0100 Subject: [PATCH 4/4] *: linter fixes --- .../deltatocumulativeprocessor/internal/streams/data_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/processor/deltatocumulativeprocessor/internal/streams/data_test.go b/processor/deltatocumulativeprocessor/internal/streams/data_test.go index fe28ddab5318..f7c4dc077781 100644 --- a/processor/deltatocumulativeprocessor/internal/streams/data_test.go +++ b/processor/deltatocumulativeprocessor/internal/streams/data_test.go @@ -6,11 +6,12 @@ package streams_test import ( "testing" + "github.com/stretchr/testify/require" + "github.com/open-telemetry/opentelemetry-collector-contrib/processor/deltatocumulativeprocessor/internal/data" "github.com/open-telemetry/opentelemetry-collector-contrib/processor/deltatocumulativeprocessor/internal/metrics" "github.com/open-telemetry/opentelemetry-collector-contrib/processor/deltatocumulativeprocessor/internal/streams" "github.com/open-telemetry/opentelemetry-collector-contrib/processor/deltatocumulativeprocessor/internal/testdata/random" - "github.com/stretchr/testify/require" ) var rdp data.Number