Skip to content

Commit

Permalink
[processor/cumulativetodelta]: exclude the first point after a restar…
Browse files Browse the repository at this point in the history
…t in monotonic sums (#18298)

fix: omit point after a restart in monotonic sums
  • Loading branch information
sigilioso committed Mar 1, 2023
1 parent 03b448d commit 459074e
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -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:
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
22 changes: 22 additions & 0 deletions processor/cumulativetodeltaprocessor/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 459074e

Please sign in to comment.