Skip to content

Commit 7d4496e

Browse files
terevMrAlias
andauthored
Pass metric labels when transforming to gaugeArray (#1570)
* Pass metric labels when transforming to gaugeArray * Update CHANGELOG.md * Update CHANGELOG.md Co-authored-by: Tyler Yahn <[email protected]> * Add label requirements to transformed metric assertions * Fix fmting Co-authored-by: Tyler Yahn <[email protected]>
1 parent 6d4a5e0 commit 7d4496e

File tree

3 files changed

+48
-8
lines changed

3 files changed

+48
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
5050
- Windows build of Jaeger tests now compiles with OS specific functions (#1576). (#1577)
5151
- The sequential timing check of timestamps of go.opentelemetry.io/otel/sdk/metric/aggregator/lastvalue are now setup explicitly to be sequential (#1578). (#1579)
5252
- Validate tracestate header keys with vedors according to the W3C TraceContext specification (#1475). (#1581)
53+
- The OTLP exporter includes related labels for translations of a GaugeArray (#1563). (#1570)
5354

5455
## [0.17.0] - 2020-02-12
5556

exporters/otlp/internal/transform/metric.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,18 +308,21 @@ func Record(exportSelector export.ExportKindSelector, r export.Record) (*metricp
308308

309309
func gaugeArray(record export.Record, points []aggregation.Point) (*metricpb.Metric, error) {
310310
desc := record.Descriptor()
311+
labels := record.Labels()
311312
m := &metricpb.Metric{
312313
Name: desc.Name(),
313314
Description: desc.Description(),
314315
Unit: string(desc.Unit()),
315316
}
316317

318+
pbLabels := stringKeyValues(labels.Iter())
319+
317320
switch nk := desc.NumberKind(); nk {
318321
case number.Int64Kind:
319322
var pts []*metricpb.IntDataPoint
320323
for _, s := range points {
321324
pts = append(pts, &metricpb.IntDataPoint{
322-
Labels: nil,
325+
Labels: pbLabels,
323326
StartTimeUnixNano: toNanos(record.StartTime()),
324327
TimeUnixNano: toNanos(record.EndTime()),
325328
Value: s.Number.CoerceToInt64(nk),
@@ -335,7 +338,7 @@ func gaugeArray(record export.Record, points []aggregation.Point) (*metricpb.Met
335338
var pts []*metricpb.DoubleDataPoint
336339
for _, s := range points {
337340
pts = append(pts, &metricpb.DoubleDataPoint{
338-
Labels: nil,
341+
Labels: pbLabels,
339342
StartTimeUnixNano: toNanos(record.StartTime()),
340343
TimeUnixNano: toNanos(record.EndTime()),
341344
Value: s.Number.CoerceToFloat64(nk),

exporters/otlp/internal/transform/metric_test.go

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func TestMinMaxSumCountValue(t *testing.T) {
123123

124124
func TestMinMaxSumCountDatapoints(t *testing.T) {
125125
desc := metric.NewDescriptor("", metric.ValueRecorderInstrumentKind, number.Int64Kind)
126-
labels := attribute.NewSet()
126+
labels := attribute.NewSet(attribute.String("one", "1"))
127127
mmsc, ckpt := metrictest.Unslice2(minmaxsumcount.New(2, &desc))
128128

129129
assert.NoError(t, mmsc.Update(context.Background(), 1, &desc))
@@ -137,6 +137,12 @@ func TestMinMaxSumCountDatapoints(t *testing.T) {
137137
BucketCounts: []uint64{1, 10},
138138
StartTimeUnixNano: uint64(intervalStart.UnixNano()),
139139
TimeUnixNano: uint64(intervalEnd.UnixNano()),
140+
Labels: []*commonpb.StringKeyValue{
141+
{
142+
Key: "one",
143+
Value: "1",
144+
},
145+
},
140146
},
141147
}
142148
record := export.NewRecord(&desc, &labels, nil, ckpt.Aggregation(), intervalStart, intervalEnd)
@@ -162,7 +168,7 @@ func TestMinMaxSumCountPropagatesErrors(t *testing.T) {
162168

163169
func TestSumIntDataPoints(t *testing.T) {
164170
desc := metric.NewDescriptor("", metric.ValueRecorderInstrumentKind, number.Int64Kind)
165-
labels := attribute.NewSet()
171+
labels := attribute.NewSet(attribute.String("one", "1"))
166172
s, ckpt := metrictest.Unslice2(sumAgg.New(2))
167173
assert.NoError(t, s.Update(context.Background(), number.Number(1), &desc))
168174
require.NoError(t, s.SynchronizedMove(ckpt, &desc))
@@ -182,6 +188,12 @@ func TestSumIntDataPoints(t *testing.T) {
182188
Value: 1,
183189
StartTimeUnixNano: uint64(intervalStart.UnixNano()),
184190
TimeUnixNano: uint64(intervalEnd.UnixNano()),
191+
Labels: []*commonpb.StringKeyValue{
192+
{
193+
Key: "one",
194+
Value: "1",
195+
},
196+
},
185197
}}}, m.GetIntSum())
186198
assert.Nil(t, m.GetDoubleGauge())
187199
assert.Nil(t, m.GetDoubleHistogram())
@@ -190,7 +202,7 @@ func TestSumIntDataPoints(t *testing.T) {
190202

191203
func TestSumFloatDataPoints(t *testing.T) {
192204
desc := metric.NewDescriptor("", metric.ValueRecorderInstrumentKind, number.Float64Kind)
193-
labels := attribute.NewSet()
205+
labels := attribute.NewSet(attribute.String("one", "1"))
194206
s, ckpt := metrictest.Unslice2(sumAgg.New(2))
195207
assert.NoError(t, s.Update(context.Background(), number.NewFloat64Number(1), &desc))
196208
require.NoError(t, s.SynchronizedMove(ckpt, &desc))
@@ -213,13 +225,19 @@ func TestSumFloatDataPoints(t *testing.T) {
213225
Value: 1,
214226
StartTimeUnixNano: uint64(intervalStart.UnixNano()),
215227
TimeUnixNano: uint64(intervalEnd.UnixNano()),
228+
Labels: []*commonpb.StringKeyValue{
229+
{
230+
Key: "one",
231+
Value: "1",
232+
},
233+
},
216234
}}}, m.GetDoubleSum())
217235
}
218236
}
219237

220238
func TestLastValueIntDataPoints(t *testing.T) {
221239
desc := metric.NewDescriptor("", metric.ValueRecorderInstrumentKind, number.Int64Kind)
222-
labels := attribute.NewSet()
240+
labels := attribute.NewSet(attribute.String("one", "1"))
223241
s, ckpt := metrictest.Unslice2(lvAgg.New(2))
224242
assert.NoError(t, s.Update(context.Background(), number.Number(100), &desc))
225243
require.NoError(t, s.SynchronizedMove(ckpt, &desc))
@@ -234,6 +252,12 @@ func TestLastValueIntDataPoints(t *testing.T) {
234252
Value: 100,
235253
StartTimeUnixNano: 0,
236254
TimeUnixNano: uint64(timestamp.UnixNano()),
255+
Labels: []*commonpb.StringKeyValue{
256+
{
257+
Key: "one",
258+
Value: "1",
259+
},
260+
},
237261
}}, m.GetIntGauge().DataPoints)
238262
assert.Nil(t, m.GetIntHistogram())
239263
assert.Nil(t, m.GetIntSum())
@@ -245,7 +269,7 @@ func TestLastValueIntDataPoints(t *testing.T) {
245269

246270
func TestExactIntDataPoints(t *testing.T) {
247271
desc := metric.NewDescriptor("", metric.ValueRecorderInstrumentKind, number.Int64Kind)
248-
labels := attribute.NewSet()
272+
labels := attribute.NewSet(attribute.String("one", "1"))
249273
e, ckpt := metrictest.Unslice2(arrAgg.New(2))
250274
assert.NoError(t, e.Update(context.Background(), number.Number(100), &desc))
251275
require.NoError(t, e.SynchronizedMove(ckpt, &desc))
@@ -260,6 +284,12 @@ func TestExactIntDataPoints(t *testing.T) {
260284
Value: 100,
261285
StartTimeUnixNano: toNanos(intervalStart),
262286
TimeUnixNano: toNanos(intervalEnd),
287+
Labels: []*commonpb.StringKeyValue{
288+
{
289+
Key: "one",
290+
Value: "1",
291+
},
292+
},
263293
}}, m.GetIntGauge().DataPoints)
264294
assert.Nil(t, m.GetIntHistogram())
265295
assert.Nil(t, m.GetIntSum())
@@ -271,7 +301,7 @@ func TestExactIntDataPoints(t *testing.T) {
271301

272302
func TestExactFloatDataPoints(t *testing.T) {
273303
desc := metric.NewDescriptor("", metric.ValueRecorderInstrumentKind, number.Float64Kind)
274-
labels := attribute.NewSet()
304+
labels := attribute.NewSet(attribute.String("one", "1"))
275305
e, ckpt := metrictest.Unslice2(arrAgg.New(2))
276306
assert.NoError(t, e.Update(context.Background(), number.NewFloat64Number(100), &desc))
277307
require.NoError(t, e.SynchronizedMove(ckpt, &desc))
@@ -286,6 +316,12 @@ func TestExactFloatDataPoints(t *testing.T) {
286316
Value: 100,
287317
StartTimeUnixNano: toNanos(intervalStart),
288318
TimeUnixNano: toNanos(intervalEnd),
319+
Labels: []*commonpb.StringKeyValue{
320+
{
321+
Key: "one",
322+
Value: "1",
323+
},
324+
},
289325
}}, m.GetDoubleGauge().DataPoints)
290326
assert.Nil(t, m.GetIntHistogram())
291327
assert.Nil(t, m.GetIntSum())

0 commit comments

Comments
 (0)