From b3ea8398298fd55ba4ea03bdea8dd11b8af544b6 Mon Sep 17 00:00:00 2001 From: Trevor Foster Date: Tue, 23 Feb 2021 00:15:58 -0500 Subject: [PATCH 1/5] Pass metric labels when transforming to gaugeArray --- exporters/otlp/internal/transform/metric.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/exporters/otlp/internal/transform/metric.go b/exporters/otlp/internal/transform/metric.go index 123ef2e8fda..d27dd4c1f12 100644 --- a/exporters/otlp/internal/transform/metric.go +++ b/exporters/otlp/internal/transform/metric.go @@ -308,18 +308,21 @@ func Record(exportSelector export.ExportKindSelector, r export.Record) (*metricp func gaugeArray(record export.Record, points []aggregation.Point) (*metricpb.Metric, error) { desc := record.Descriptor() + labels := record.Labels() m := &metricpb.Metric{ Name: desc.Name(), Description: desc.Description(), Unit: string(desc.Unit()), } + pbLabels := stringKeyValues(labels.Iter()) + switch nk := desc.NumberKind(); nk { case number.Int64Kind: var pts []*metricpb.IntDataPoint for _, s := range points { pts = append(pts, &metricpb.IntDataPoint{ - Labels: nil, + Labels: pbLabels, StartTimeUnixNano: toNanos(record.StartTime()), TimeUnixNano: toNanos(record.EndTime()), Value: s.Number.CoerceToInt64(nk), @@ -335,7 +338,7 @@ func gaugeArray(record export.Record, points []aggregation.Point) (*metricpb.Met var pts []*metricpb.DoubleDataPoint for _, s := range points { pts = append(pts, &metricpb.DoubleDataPoint{ - Labels: nil, + Labels: pbLabels, StartTimeUnixNano: toNanos(record.StartTime()), TimeUnixNano: toNanos(record.EndTime()), Value: s.Number.CoerceToFloat64(nk), From ab2a9acf535a651f9d6d6042cdeaef3e1d0426b9 Mon Sep 17 00:00:00 2001 From: Trevor Foster Date: Tue, 23 Feb 2021 00:41:31 -0500 Subject: [PATCH 2/5] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a2df2c302c9..ff0e6f6faae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,9 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Removed attempt to resample spans upon changing the span name with `span.SetName()`. (#1545) +### Fixed +- Fixed otlpgrpc exporter passing labels when translating exact aggregation to pb + ## [0.17.0] - 2020-02-12 ### Changed From fe50b17d0fc210f3133ca97dabaa4327cf9bb62a Mon Sep 17 00:00:00 2001 From: Trevor Foster Date: Wed, 24 Feb 2021 16:05:18 -0500 Subject: [PATCH 3/5] Update CHANGELOG.md Co-authored-by: Tyler Yahn --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ff0e6f6faae..e8ab519a1b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,7 +32,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Removed attempt to resample spans upon changing the span name with `span.SetName()`. (#1545) ### Fixed -- Fixed otlpgrpc exporter passing labels when translating exact aggregation to pb + +- The OTLP exporter includes related labels for translations of a GaugeArray (#1563). (#1570) ## [0.17.0] - 2020-02-12 From d2341fd742fafd5e73bfb5be01fb1136e8544654 Mon Sep 17 00:00:00 2001 From: Trevor Foster Date: Sat, 27 Feb 2021 10:15:28 -0500 Subject: [PATCH 4/5] Add label requirements to transformed metric assertions --- .../otlp/internal/transform/metric_test.go | 48 ++++++++++++++++--- 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/exporters/otlp/internal/transform/metric_test.go b/exporters/otlp/internal/transform/metric_test.go index b36eaccec8d..a1d087ab265 100644 --- a/exporters/otlp/internal/transform/metric_test.go +++ b/exporters/otlp/internal/transform/metric_test.go @@ -123,7 +123,7 @@ func TestMinMaxSumCountValue(t *testing.T) { func TestMinMaxSumCountDatapoints(t *testing.T) { desc := metric.NewDescriptor("", metric.ValueRecorderInstrumentKind, number.Int64Kind) - labels := attribute.NewSet() + labels := attribute.NewSet(attribute.String("one", "1")) mmsc, ckpt := metrictest.Unslice2(minmaxsumcount.New(2, &desc)) assert.NoError(t, mmsc.Update(context.Background(), 1, &desc)) @@ -137,6 +137,12 @@ func TestMinMaxSumCountDatapoints(t *testing.T) { BucketCounts: []uint64{1, 10}, StartTimeUnixNano: uint64(intervalStart.UnixNano()), TimeUnixNano: uint64(intervalEnd.UnixNano()), + Labels: []*commonpb.StringKeyValue{ + { + Key: "one", + Value: "1", + }, + }, }, } record := export.NewRecord(&desc, &labels, nil, ckpt.Aggregation(), intervalStart, intervalEnd) @@ -162,7 +168,7 @@ func TestMinMaxSumCountPropagatesErrors(t *testing.T) { func TestSumIntDataPoints(t *testing.T) { desc := metric.NewDescriptor("", metric.ValueRecorderInstrumentKind, number.Int64Kind) - labels := attribute.NewSet() + labels := attribute.NewSet(attribute.String("one", "1")) s, ckpt := metrictest.Unslice2(sumAgg.New(2)) assert.NoError(t, s.Update(context.Background(), number.Number(1), &desc)) require.NoError(t, s.SynchronizedMove(ckpt, &desc)) @@ -182,6 +188,12 @@ func TestSumIntDataPoints(t *testing.T) { Value: 1, StartTimeUnixNano: uint64(intervalStart.UnixNano()), TimeUnixNano: uint64(intervalEnd.UnixNano()), + Labels: []*commonpb.StringKeyValue{ + { + Key: "one", + Value: "1", + }, + }, }}}, m.GetIntSum()) assert.Nil(t, m.GetDoubleGauge()) assert.Nil(t, m.GetDoubleHistogram()) @@ -190,7 +202,7 @@ func TestSumIntDataPoints(t *testing.T) { func TestSumFloatDataPoints(t *testing.T) { desc := metric.NewDescriptor("", metric.ValueRecorderInstrumentKind, number.Float64Kind) - labels := attribute.NewSet() + labels := attribute.NewSet(attribute.String("one", "1")) s, ckpt := metrictest.Unslice2(sumAgg.New(2)) assert.NoError(t, s.Update(context.Background(), number.NewFloat64Number(1), &desc)) require.NoError(t, s.SynchronizedMove(ckpt, &desc)) @@ -213,13 +225,19 @@ func TestSumFloatDataPoints(t *testing.T) { Value: 1, StartTimeUnixNano: uint64(intervalStart.UnixNano()), TimeUnixNano: uint64(intervalEnd.UnixNano()), + Labels: []*commonpb.StringKeyValue{ + { + Key: "one", + Value: "1", + }, + }, }}}, m.GetDoubleSum()) } } func TestLastValueIntDataPoints(t *testing.T) { desc := metric.NewDescriptor("", metric.ValueRecorderInstrumentKind, number.Int64Kind) - labels := attribute.NewSet() + labels := attribute.NewSet(attribute.String("one", "1")) s, ckpt := metrictest.Unslice2(lvAgg.New(2)) assert.NoError(t, s.Update(context.Background(), number.Number(100), &desc)) require.NoError(t, s.SynchronizedMove(ckpt, &desc)) @@ -234,6 +252,12 @@ func TestLastValueIntDataPoints(t *testing.T) { Value: 100, StartTimeUnixNano: 0, TimeUnixNano: uint64(timestamp.UnixNano()), + Labels: []*commonpb.StringKeyValue{ + { + Key: "one", + Value: "1", + }, + }, }}, m.GetIntGauge().DataPoints) assert.Nil(t, m.GetIntHistogram()) assert.Nil(t, m.GetIntSum()) @@ -245,7 +269,7 @@ func TestLastValueIntDataPoints(t *testing.T) { func TestExactIntDataPoints(t *testing.T) { desc := metric.NewDescriptor("", metric.ValueRecorderInstrumentKind, number.Int64Kind) - labels := attribute.NewSet() + labels := attribute.NewSet(attribute.String("one", "1")) e, ckpt := metrictest.Unslice2(arrAgg.New(2)) assert.NoError(t, e.Update(context.Background(), number.Number(100), &desc)) require.NoError(t, e.SynchronizedMove(ckpt, &desc)) @@ -260,6 +284,12 @@ func TestExactIntDataPoints(t *testing.T) { Value: 100, StartTimeUnixNano: toNanos(intervalStart), TimeUnixNano: toNanos(intervalEnd), + Labels: []*commonpb.StringKeyValue{ + { + Key: "one", + Value: "1", + }, + }, }}, m.GetIntGauge().DataPoints) assert.Nil(t, m.GetIntHistogram()) assert.Nil(t, m.GetIntSum()) @@ -271,7 +301,7 @@ func TestExactIntDataPoints(t *testing.T) { func TestExactFloatDataPoints(t *testing.T) { desc := metric.NewDescriptor("", metric.ValueRecorderInstrumentKind, number.Float64Kind) - labels := attribute.NewSet() + labels := attribute.NewSet(attribute.String("one", "1")) e, ckpt := metrictest.Unslice2(arrAgg.New(2)) assert.NoError(t, e.Update(context.Background(), number.NewFloat64Number(100), &desc)) require.NoError(t, e.SynchronizedMove(ckpt, &desc)) @@ -286,6 +316,12 @@ func TestExactFloatDataPoints(t *testing.T) { Value: 100, StartTimeUnixNano: toNanos(intervalStart), TimeUnixNano: toNanos(intervalEnd), + Labels: []*commonpb.StringKeyValue{ + { + Key: "one", + Value: "1", + }, + }, }}, m.GetDoubleGauge().DataPoints) assert.Nil(t, m.GetIntHistogram()) assert.Nil(t, m.GetIntSum()) From d603a867f0db3c352a360a0ea4cbfbd624aabd92 Mon Sep 17 00:00:00 2001 From: Trevor Foster Date: Sat, 27 Feb 2021 10:58:00 -0500 Subject: [PATCH 5/5] Fix fmting --- exporters/otlp/internal/transform/metric_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exporters/otlp/internal/transform/metric_test.go b/exporters/otlp/internal/transform/metric_test.go index a1d087ab265..b80aaff5d50 100644 --- a/exporters/otlp/internal/transform/metric_test.go +++ b/exporters/otlp/internal/transform/metric_test.go @@ -137,7 +137,7 @@ func TestMinMaxSumCountDatapoints(t *testing.T) { BucketCounts: []uint64{1, 10}, StartTimeUnixNano: uint64(intervalStart.UnixNano()), TimeUnixNano: uint64(intervalEnd.UnixNano()), - Labels: []*commonpb.StringKeyValue{ + Labels: []*commonpb.StringKeyValue{ { Key: "one", Value: "1",