diff --git a/.chloggen/cumulativetodelta-drop-first-datapoint-after-restart.yaml b/.chloggen/cumulativetodelta-drop-first-datapoint-after-restart.yaml new file mode 100755 index 0000000000000..a171aa72d1ba5 --- /dev/null +++ b/.chloggen/cumulativetodelta-drop-first-datapoint-after-restart.yaml @@ -0,0 +1,16 @@ +# 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: cumulativetodeltaprocessor + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: exclude the first point after a restart in monotonic sums + +# One or more tracking issues related to the change +issues: [17190, 18053] + +# (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: diff --git a/processor/cumulativetodeltaprocessor/internal/tracking/tracker.go b/processor/cumulativetodeltaprocessor/internal/tracking/tracker.go index 3a868ddd71fc5..54a41516b4832 100644 --- a/processor/cumulativetodeltaprocessor/internal/tracking/tracker.go +++ b/processor/cumulativetodeltaprocessor/internal/tracking/tracker.go @@ -127,7 +127,7 @@ func (t *MetricTracker) Convert(in MetricPoint) (out DeltaValue, valid bool) { // Detect reset (non-monotonic sums are not converted) if value < prevValue { - delta = value + valid = false } out.FloatValue = delta @@ -138,7 +138,7 @@ func (t *MetricTracker) Convert(in MetricPoint) (out DeltaValue, valid bool) { // Detect reset (non-monotonic sums are not converted) if value < prevValue { - delta = value + valid = false } out.IntValue = delta diff --git a/processor/cumulativetodeltaprocessor/internal/tracking/tracker_test.go b/processor/cumulativetodeltaprocessor/internal/tracking/tracker_test.go index c3fbae26869e4..2e4e1240c6f63 100644 --- a/processor/cumulativetodeltaprocessor/internal/tracking/tracker_test.go +++ b/processor/cumulativetodeltaprocessor/internal/tracking/tracker_test.go @@ -50,7 +50,7 @@ func TestMetricTracker_Convert(t *testing.T) { noOut bool }{ { - name: "Initial Value not recorded", + name: "Initial Value Omitted", value: ValuePoint{ ObservedTimestamp: 10, FloatValue: 100.0, @@ -59,7 +59,7 @@ func TestMetricTracker_Convert(t *testing.T) { noOut: true, }, { - name: "Higher Value Recorded", + name: "Higher Value Converted", value: ValuePoint{ ObservedTimestamp: 50, FloatValue: 225.0, @@ -72,20 +72,16 @@ func TestMetricTracker_Convert(t *testing.T) { }, }, { - name: "Lower Value Recorded - No Previous Offset", + name: "Lower Value not Converted - Restart", value: ValuePoint{ ObservedTimestamp: 100, FloatValue: 75.0, IntValue: 75, }, - wantOut: DeltaValue{ - StartTimestamp: 50, - FloatValue: 75.0, - IntValue: 75, - }, + noOut: true, }, { - name: "Record delta above first recorded value", + name: "Convert delta above previous not Converted Value", value: ValuePoint{ ObservedTimestamp: 150, FloatValue: 300.0, @@ -98,11 +94,11 @@ func TestMetricTracker_Convert(t *testing.T) { }, }, { - name: "Lower Value Recorded - Previous Offset Recorded", + name: "Higher Value Converted - Previous Offset Recorded", value: ValuePoint{ ObservedTimestamp: 200, - FloatValue: 25.0, - IntValue: 25, + FloatValue: 325.0, + IntValue: 325, }, wantOut: DeltaValue{ StartTimestamp: 150, diff --git a/processor/cumulativetodeltaprocessor/processor_test.go b/processor/cumulativetodeltaprocessor/processor_test.go index cb134cc33a05d..74da743c01439 100644 --- a/processor/cumulativetodeltaprocessor/processor_test.go +++ b/processor/cumulativetodeltaprocessor/processor_test.go @@ -425,6 +425,28 @@ func TestCumulativeToDeltaProcessor(t *testing.T) { isMonotonic: []bool{true, true}, }), }, + { + name: "cumulative_to_delta_restart_detected", + include: MatchMetrics{ + Metrics: []string{".*"}, + Config: filterset.Config{ + MatchType: "regexp", + RegexpConfig: nil, + }, + }, + inMetrics: generateTestSumMetrics(testSumMetric{ + metricNames: []string{"metric_1"}, + metricValues: [][]float64{{100, 105, 120, 100, 110}}, + isCumulative: []bool{true}, + isMonotonic: []bool{true}, + }), + outMetrics: generateTestSumMetrics(testSumMetric{ + metricNames: []string{"metric_1"}, + metricValues: [][]float64{{5, 15, 10}}, + isCumulative: []bool{false}, + isMonotonic: []bool{true}, + }), + }, } for _, test := range testCases {