From 94ae231180b0eeac1671967670a431bdb1e82799 Mon Sep 17 00:00:00 2001 From: Kuisong Tong Date: Thu, 27 Oct 2022 14:29:01 -0700 Subject: [PATCH] Set IsMonotonic to true for opencensus sum (#3389) * Set IsMonotonic to true for opencensus sum fix #3388 * Update metric_test.go * fix test * add changelog * Update CHANGELOG.md Co-authored-by: Tyler Yahn Co-authored-by: Tyler Yahn --- CHANGELOG.md | 1 + bridge/opencensus/internal/ocmetric/metric.go | 2 +- bridge/opencensus/internal/ocmetric/metric_test.go | 3 +++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a47d2b6451..da030b9193f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ### Fixed - The `go.opentelemetry.io/otel/exporters/prometheus` exporter fixes duplicated `_total` suffixes. (#3369) +- Cumulative metrics from the OpenCensus bridge (`go.opentelemetry.io/otel/bridge/opencensus`) are defined as monotonic sums, instead of non-monotonic. (#3389) - Asynchronous counters (`Counter` and `UpDownCounter`) from the metric SDK now produce delta sums when configured with delta temporality. (#3398) ## [1.11.1/0.33.0] 2022-10-19 diff --git a/bridge/opencensus/internal/ocmetric/metric.go b/bridge/opencensus/internal/ocmetric/metric.go index 575e99abe75..54b6619a1f6 100644 --- a/bridge/opencensus/internal/ocmetric/metric.go +++ b/bridge/opencensus/internal/ocmetric/metric.go @@ -92,7 +92,7 @@ func convertGauge[N int64 | float64](labelKeys []ocmetricdata.LabelKey, ts []*oc func convertSum[N int64 | float64](labelKeys []ocmetricdata.LabelKey, ts []*ocmetricdata.TimeSeries) (metricdata.Sum[N], error) { points, err := convertNumberDataPoints[N](labelKeys, ts) // OpenCensus sums are always Cumulative - return metricdata.Sum[N]{DataPoints: points, Temporality: metricdata.CumulativeTemporality}, err + return metricdata.Sum[N]{DataPoints: points, Temporality: metricdata.CumulativeTemporality, IsMonotonic: true}, err } // convertNumberDataPoints converts OpenCensus TimeSeries to OpenTelemetry DataPoints. diff --git a/bridge/opencensus/internal/ocmetric/metric_test.go b/bridge/opencensus/internal/ocmetric/metric_test.go index b93bc413088..19f74a6a887 100644 --- a/bridge/opencensus/internal/ocmetric/metric_test.go +++ b/bridge/opencensus/internal/ocmetric/metric_test.go @@ -312,6 +312,7 @@ func TestConvertMetrics(t *testing.T) { Description: "an int testing sum", Unit: unit.Milliseconds, Data: metricdata.Sum[int64]{ + IsMonotonic: true, Temporality: metricdata.CumulativeTemporality, DataPoints: []metricdata.DataPoint[int64]{ { @@ -342,6 +343,7 @@ func TestConvertMetrics(t *testing.T) { Description: "a float testing sum", Unit: unit.Milliseconds, Data: metricdata.Sum[float64]{ + IsMonotonic: true, Temporality: metricdata.CumulativeTemporality, DataPoints: []metricdata.DataPoint[float64]{ { @@ -410,6 +412,7 @@ func TestConvertMetrics(t *testing.T) { Description: "a testing sum", Unit: unit.Dimensionless, Data: metricdata.Sum[float64]{ + IsMonotonic: true, Temporality: metricdata.CumulativeTemporality, DataPoints: []metricdata.DataPoint[float64]{}, },