Skip to content

Commit

Permalink
Merge pull request #1 from locmai/fix/logic-in-dropping-metric
Browse files Browse the repository at this point in the history
fix: dropping non-cumulative logic
  • Loading branch information
vsabella authored Jan 13, 2022
2 parents 772f39c + 9bd73b5 commit b6f3693
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
4 changes: 2 additions & 2 deletions exporter/prometheusexporter/accumulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ func (a *lastValueAccumulator) accumulateGauge(metric pdata.Metric, il pdata.Ins
func (a *lastValueAccumulator) accumulateSum(metric pdata.Metric, il pdata.InstrumentationLibrary, now time.Time) (n int) {
doubleSum := metric.Sum()

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

Expand Down
16 changes: 16 additions & 0 deletions exporter/prometheusexporter/accumulator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,22 @@ func TestAccumulateMetrics(t *testing.T) {
dp.SetTimestamp(pdata.NewTimestampFromTime(ts))
},
},
{
name: "DeltaCumulativeMonotonicSum", // For testing the delta cumulative but monotonic metric #4153
metric: func(ts time.Time, v float64, metrics pdata.MetricSlice) {
metric := metrics.AppendEmpty()
metric.SetName("test_metric")
metric.SetDataType(pdata.MetricDataTypeSum)
metric.Sum().SetIsMonotonic(true)
metric.Sum().SetAggregationTemporality(pdata.MetricAggregationTemporalityDelta)
metric.SetDescription("test description")
dp := metric.Sum().DataPoints().AppendEmpty()
dp.SetDoubleVal(v)
dp.Attributes().InsertString("label_1", "1")
dp.Attributes().InsertString("label_2", "2")
dp.SetTimestamp(pdata.NewTimestampFromTime(ts))
},
},
{
name: "Histogram",
metric: func(ts time.Time, v float64, metrics pdata.MetricSlice) {
Expand Down
10 changes: 9 additions & 1 deletion go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b6f3693

Please sign in to comment.