From f797684ec165eb619d194097e48d177388258fd0 Mon Sep 17 00:00:00 2001 From: Loc Mai Date: Mon, 18 Jul 2022 14:26:32 +0700 Subject: [PATCH] [exporter/prometheus] fix: cumulative condition based on the starttimestamp (#12340) * fix: fix the cumulative condition based on the starttimestamp Signed-off-by: Loc Mai * update changelog Signed-off-by: Loc Mai * Revert "update changelog" This reverts commit 6717c52771cb62e7a7dc414d94d282d6b7765a8c. Signed-off-by: Loc Mai * update changelog Signed-off-by: Loc Mai * fix value assertion instead of the last value Signed-off-by: Loc Mai * add more assertions Signed-off-by: Loc Mai --- exporter/prometheusexporter/accumulator.go | 2 +- exporter/prometheusexporter/accumulator_test.go | 12 ++++++++---- unreleased/fix_cumulative-condition.yaml | 11 +++++++++++ 3 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 unreleased/fix_cumulative-condition.yaml diff --git a/exporter/prometheusexporter/accumulator.go b/exporter/prometheusexporter/accumulator.go index d13aa34aed40..d49e32546f1f 100644 --- a/exporter/prometheusexporter/accumulator.go +++ b/exporter/prometheusexporter/accumulator.go @@ -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: diff --git a/exporter/prometheusexporter/accumulator_test.go b/exporter/prometheusexporter/accumulator_test.go index 7c6643443d75..f420695603b3 100644 --- a/exporter/prometheusexporter/accumulator_test.go +++ b/exporter/prometheusexporter/accumulator_test.go @@ -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) @@ -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()) }) diff --git a/unreleased/fix_cumulative-condition.yaml b/unreleased/fix_cumulative-condition.yaml new file mode 100644 index 000000000000..e983f0e07740 --- /dev/null +++ b/unreleased/fix_cumulative-condition.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: 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]