Skip to content

Commit

Permalink
Fix oc to pdata translation for sum non-monotonic cumulative (#3272)
Browse files Browse the repository at this point in the history
Fixes #3266

Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
  • Loading branch information
bogdandrutu authored May 25, 2021
1 parent c8e28f2 commit 1a1bad8
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 2 deletions.
4 changes: 2 additions & 2 deletions translator/internaldata/metrics_to_oc.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,13 @@ func descriptorTypeToOC(metric pdata.Metric) ocmetrics.MetricDescriptor_Type {
return ocmetrics.MetricDescriptor_GAUGE_DOUBLE
case pdata.MetricDataTypeIntSum:
sd := metric.IntSum()
if sd.IsMonotonic() || sd.AggregationTemporality() == pdata.AggregationTemporalityCumulative {
if sd.IsMonotonic() && sd.AggregationTemporality() == pdata.AggregationTemporalityCumulative {
return ocmetrics.MetricDescriptor_CUMULATIVE_INT64
}
return ocmetrics.MetricDescriptor_GAUGE_INT64
case pdata.MetricDataTypeDoubleSum:
sd := metric.DoubleSum()
if sd.IsMonotonic() || sd.AggregationTemporality() == pdata.AggregationTemporalityCumulative {
if sd.IsMonotonic() && sd.AggregationTemporality() == pdata.AggregationTemporalityCumulative {
return ocmetrics.MetricDescriptor_CUMULATIVE_DOUBLE
}
return ocmetrics.MetricDescriptor_GAUGE_DOUBLE
Expand Down
121 changes: 121 additions & 0 deletions translator/internaldata/metrics_to_oc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,124 @@ func generateOCTestData() *agentmetricspb.ExportMetricsServiceRequest {
},
}
}

func TestMetricsType(t *testing.T) {
tests := []struct {
name string
internal func() pdata.Metric
descType ocmetrics.MetricDescriptor_Type
}{
{
name: "int-gauge",
internal: func() pdata.Metric {
m := pdata.NewMetric()
m.SetDataType(pdata.MetricDataTypeIntGauge)
return m
},
descType: ocmetrics.MetricDescriptor_GAUGE_INT64,
},
{
name: "double-gauge",
internal: func() pdata.Metric {
m := pdata.NewMetric()
m.SetDataType(pdata.MetricDataTypeDoubleGauge)
return m
},
descType: ocmetrics.MetricDescriptor_GAUGE_DOUBLE,
},
{
name: "int-non-monotonic-delta-sum",
internal: func() pdata.Metric {
m := pdata.NewMetric()
m.SetDataType(pdata.MetricDataTypeIntSum)
m.IntSum().SetIsMonotonic(false)
m.IntSum().SetAggregationTemporality(pdata.AggregationTemporalityDelta)
return m
},
descType: ocmetrics.MetricDescriptor_GAUGE_INT64,
},
{
name: "int-non-monotonic-cumulative-sum",
internal: func() pdata.Metric {
m := pdata.NewMetric()
m.SetDataType(pdata.MetricDataTypeIntSum)
m.IntSum().SetIsMonotonic(false)
m.IntSum().SetAggregationTemporality(pdata.AggregationTemporalityCumulative)
return m
},
descType: ocmetrics.MetricDescriptor_GAUGE_INT64,
},
{
name: "int-monotonic-delta-sum",
internal: func() pdata.Metric {
m := pdata.NewMetric()
m.SetDataType(pdata.MetricDataTypeIntSum)
m.IntSum().SetIsMonotonic(true)
m.IntSum().SetAggregationTemporality(pdata.AggregationTemporalityDelta)
return m
},
descType: ocmetrics.MetricDescriptor_GAUGE_INT64,
},
{
name: "int-monotonic-cumulative-sum",
internal: func() pdata.Metric {
m := pdata.NewMetric()
m.SetDataType(pdata.MetricDataTypeIntSum)
m.IntSum().SetIsMonotonic(true)
m.IntSum().SetAggregationTemporality(pdata.AggregationTemporalityCumulative)
return m
},
descType: ocmetrics.MetricDescriptor_CUMULATIVE_INT64,
},
{
name: "double-non-monotonic-delta-sum",
internal: func() pdata.Metric {
m := pdata.NewMetric()
m.SetDataType(pdata.MetricDataTypeDoubleSum)
m.DoubleSum().SetIsMonotonic(false)
m.DoubleSum().SetAggregationTemporality(pdata.AggregationTemporalityDelta)
return m
},
descType: ocmetrics.MetricDescriptor_GAUGE_DOUBLE,
},
{
name: "double-non-monotonic-cumulative-sum",
internal: func() pdata.Metric {
m := pdata.NewMetric()
m.SetDataType(pdata.MetricDataTypeDoubleSum)
m.DoubleSum().SetIsMonotonic(false)
m.DoubleSum().SetAggregationTemporality(pdata.AggregationTemporalityCumulative)
return m
},
descType: ocmetrics.MetricDescriptor_GAUGE_DOUBLE,
},
{
name: "double-monotonic-delta-sum",
internal: func() pdata.Metric {
m := pdata.NewMetric()
m.SetDataType(pdata.MetricDataTypeDoubleSum)
m.DoubleSum().SetIsMonotonic(true)
m.DoubleSum().SetAggregationTemporality(pdata.AggregationTemporalityDelta)
return m
},
descType: ocmetrics.MetricDescriptor_GAUGE_DOUBLE,
},
{
name: "double-monotonic-cumulative-sum",
internal: func() pdata.Metric {
m := pdata.NewMetric()
m.SetDataType(pdata.MetricDataTypeDoubleSum)
m.DoubleSum().SetIsMonotonic(true)
m.DoubleSum().SetAggregationTemporality(pdata.AggregationTemporalityCumulative)
return m
},
descType: ocmetrics.MetricDescriptor_CUMULATIVE_DOUBLE,
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
assert.Equal(t, test.descType, descriptorTypeToOC(test.internal()))
})
}
}

0 comments on commit 1a1bad8

Please sign in to comment.