diff --git a/translator/internaldata/metrics_to_oc.go b/translator/internaldata/metrics_to_oc.go index ed77e5b2348..e8fbbe4cdd9 100644 --- a/translator/internaldata/metrics_to_oc.go +++ b/translator/internaldata/metrics_to_oc.go @@ -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 diff --git a/translator/internaldata/metrics_to_oc_test.go b/translator/internaldata/metrics_to_oc_test.go index 9f981e2fc77..0fd5706a02e 100644 --- a/translator/internaldata/metrics_to_oc_test.go +++ b/translator/internaldata/metrics_to_oc_test.go @@ -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())) + }) + } +}