Skip to content

Commit b6f3693

Browse files
authored
Merge pull request #1 from locmai/fix/logic-in-dropping-metric
fix: dropping non-cumulative logic
2 parents 772f39c + 9bd73b5 commit b6f3693

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

exporter/prometheusexporter/accumulator.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ func (a *lastValueAccumulator) accumulateGauge(metric pdata.Metric, il pdata.Ins
165165
func (a *lastValueAccumulator) accumulateSum(metric pdata.Metric, il pdata.InstrumentationLibrary, now time.Time) (n int) {
166166
doubleSum := metric.Sum()
167167

168-
// Drop metrics with non-cumulative aggregations
169-
if doubleSum.AggregationTemporality() != pdata.MetricAggregationTemporalityCumulative {
168+
// Drop metrics with non-cumulative aggregations and is not monotonic increasing
169+
if doubleSum.AggregationTemporality() != pdata.MetricAggregationTemporalityCumulative && !metric.Sum().IsMonotonic() {
170170
return
171171
}
172172

exporter/prometheusexporter/accumulator_test.go

+16
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,22 @@ func TestAccumulateMetrics(t *testing.T) {
199199
dp.SetTimestamp(pdata.NewTimestampFromTime(ts))
200200
},
201201
},
202+
{
203+
name: "DeltaCumulativeMonotonicSum", // For testing the delta cumulative but monotonic metric #4153
204+
metric: func(ts time.Time, v float64, metrics pdata.MetricSlice) {
205+
metric := metrics.AppendEmpty()
206+
metric.SetName("test_metric")
207+
metric.SetDataType(pdata.MetricDataTypeSum)
208+
metric.Sum().SetIsMonotonic(true)
209+
metric.Sum().SetAggregationTemporality(pdata.MetricAggregationTemporalityDelta)
210+
metric.SetDescription("test description")
211+
dp := metric.Sum().DataPoints().AppendEmpty()
212+
dp.SetDoubleVal(v)
213+
dp.Attributes().InsertString("label_1", "1")
214+
dp.Attributes().InsertString("label_2", "2")
215+
dp.SetTimestamp(pdata.NewTimestampFromTime(ts))
216+
},
217+
},
202218
{
203219
name: "Histogram",
204220
metric: func(ts time.Time, v float64, metrics pdata.MetricSlice) {

go.sum

+9-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)