Skip to content

Commit

Permalink
[exporter/prometheus] fix: cumulative condition based on the starttim…
Browse files Browse the repository at this point in the history
…estamp (#12340)

* fix: fix the cumulative condition based on the starttimestamp

Signed-off-by: Loc Mai <[email protected]>

* update changelog

Signed-off-by: Loc Mai <[email protected]>

* Revert "update changelog"

This reverts commit 6717c52.

Signed-off-by: Loc Mai <[email protected]>

* update changelog

Signed-off-by: Loc Mai <[email protected]>

* fix value assertion instead of the last value

Signed-off-by: Loc Mai <[email protected]>

* add more assertions

Signed-off-by: Loc Mai <[email protected]>
  • Loading branch information
locmai authored Jul 18, 2022
1 parent 467c80a commit f797684
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion exporter/prometheusexporter/accumulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func (a *lastValueAccumulator) accumulateSum(metric pmetric.Metric, il pcommon.I
}

// Delta-to-Cumulative
if doubleSum.AggregationTemporality() == pmetric.MetricAggregationTemporalityDelta && ip.StartTimestamp() == mv.value.Sum().DataPoints().At(0).StartTimestamp() {
if doubleSum.AggregationTemporality() == pmetric.MetricAggregationTemporalityDelta && ip.StartTimestamp() == mv.value.Sum().DataPoints().At(0).Timestamp() {
ip.SetStartTimestamp(mv.value.Sum().DataPoints().At(0).StartTimestamp())
switch ip.ValueType() {
case pmetric.NumberDataPointValueTypeInt:
Expand Down
12 changes: 8 additions & 4 deletions exporter/prometheusexporter/accumulator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,19 +413,22 @@ func TestAccumulateDeltaToCumulative(t *testing.T) {
ilm.Scope().SetName("test")
a := newAccumulator(zap.NewNop(), 1*time.Hour).(*lastValueAccumulator)

dataPointValue1 := float64(11)
dataPointValue2 := float64(32)

// The first point arrived
tt.metric(ts1, ts2, 11, ilm.Metrics())
tt.metric(ts1, ts2, dataPointValue1, ilm.Metrics())
n := a.Accumulate(resourceMetrics)

require.Equal(t, 1, n)

// The next point arrived
tt.metric(ts2, ts3, 31, ilm.Metrics())
tt.metric(ts2, ts3, dataPointValue2, ilm.Metrics())
n = a.Accumulate(resourceMetrics)

require.Equal(t, 2, n)

mLabels, _, mValue, _, mIsMonotonic := getMetricProperties(ilm.Metrics().At(1))
mLabels, _, mValue, _, _ := getMetricProperties(ilm.Metrics().At(1))
signature := timeseriesSignature(ilm.Scope().Name(), ilm.Metrics().At(0), mLabels, pcommon.NewMap())
m, ok := a.registeredMetrics.Load(signature)
require.True(t, ok)
Expand All @@ -444,8 +447,9 @@ func TestAccumulateDeltaToCumulative(t *testing.T) {
})
require.Equal(t, mLabels.Len(), vLabels.Len())
require.Equal(t, mValue, vValue)
require.Equal(t, dataPointValue1+dataPointValue2, vValue)
require.Equal(t, pmetric.MetricAggregationTemporalityCumulative, vTemporality)
require.Equal(t, mIsMonotonic, vIsMonotonic)
require.Equal(t, true, vIsMonotonic)

require.Equal(t, ts3.Unix(), vTS.Unix())
})
Expand Down
11 changes: 11 additions & 0 deletions unreleased/fix_cumulative-condition.yaml
Original file line number Diff line number Diff line change
@@ -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: prometheusexporter

# A brief description of the change
note: Fix cumulative condition for the delta-to-cumulative

# One or more tracking issues related to the change
issues: [4153]

0 comments on commit f797684

Please sign in to comment.