@@ -253,21 +253,6 @@ func addSingleHistogramDataPoint(pt pmetric.HistogramDataPoint, resource pcommon
253
253
timestamp := convertTimeStamp (pt .Timestamp ())
254
254
baseLabels := createAttributes (resource , pt .Attributes (), settings .ExternalLabels )
255
255
256
- createLabels := func (nameSuffix string , extras ... string ) []prompb.Label {
257
- extraLabelCount := len (extras ) / 2
258
- labels := make ([]prompb.Label , len (baseLabels ), len (baseLabels )+ extraLabelCount + 1 ) // +1 for name
259
- copy (labels , baseLabels )
260
-
261
- for extrasIdx := 0 ; extrasIdx < extraLabelCount ; extrasIdx ++ {
262
- labels = append (labels , prompb.Label {Name : extras [extrasIdx ], Value : extras [extrasIdx + 1 ]})
263
- }
264
-
265
- // sum, count, and buckets of the histogram should append suffix to baseName
266
- labels = append (labels , prompb.Label {Name : model .MetricNameLabel , Value : baseName + nameSuffix })
267
-
268
- return labels
269
- }
270
-
271
256
// If the sum is unset, it indicates the _sum metric point should be
272
257
// omitted
273
258
if pt .HasSum () {
@@ -280,7 +265,7 @@ func addSingleHistogramDataPoint(pt pmetric.HistogramDataPoint, resource pcommon
280
265
sum .Value = math .Float64frombits (value .StaleNaN )
281
266
}
282
267
283
- sumlabels := createLabels (sumStr )
268
+ sumlabels := createLabels (baseName + sumStr , baseLabels )
284
269
addSample (tsMap , sum , sumlabels , metric .Type ().String ())
285
270
286
271
}
@@ -294,7 +279,7 @@ func addSingleHistogramDataPoint(pt pmetric.HistogramDataPoint, resource pcommon
294
279
count .Value = math .Float64frombits (value .StaleNaN )
295
280
}
296
281
297
- countlabels := createLabels (countStr )
282
+ countlabels := createLabels (baseName + countStr , baseLabels )
298
283
addSample (tsMap , count , countlabels , metric .Type ().String ())
299
284
300
285
// cumulative count for conversion to cumulative histogram
@@ -316,7 +301,7 @@ func addSingleHistogramDataPoint(pt pmetric.HistogramDataPoint, resource pcommon
316
301
bucket .Value = math .Float64frombits (value .StaleNaN )
317
302
}
318
303
boundStr := strconv .FormatFloat (bound , 'f' , - 1 , 64 )
319
- labels := createLabels (bucketStr , leStr , boundStr )
304
+ labels := createLabels (baseName + bucketStr , baseLabels , leStr , boundStr )
320
305
sig := addSample (tsMap , bucket , labels , metric .Type ().String ())
321
306
322
307
bucketBounds = append (bucketBounds , bucketBoundsData {sig : sig , bound : bound })
@@ -330,7 +315,7 @@ func addSingleHistogramDataPoint(pt pmetric.HistogramDataPoint, resource pcommon
330
315
} else {
331
316
infBucket .Value = float64 (pt .Count ())
332
317
}
333
- infLabels := createLabels (bucketStr , leStr , pInfStr )
318
+ infLabels := createLabels (baseName + bucketStr , baseLabels , leStr , pInfStr )
334
319
sig := addSample (tsMap , infBucket , infLabels , metric .Type ().String ())
335
320
336
321
bucketBounds = append (bucketBounds , bucketBoundsData {sig : sig , bound : math .Inf (1 )})
@@ -339,7 +324,7 @@ func addSingleHistogramDataPoint(pt pmetric.HistogramDataPoint, resource pcommon
339
324
// add _created time series if needed
340
325
startTimestamp := pt .StartTimestamp ()
341
326
if settings .ExportCreatedMetric && startTimestamp != 0 {
342
- labels := createLabels (createdSuffix )
327
+ labels := createLabels (baseName + createdSuffix , baseLabels )
343
328
addCreatedTimeSeriesIfNeeded (tsMap , labels , startTimestamp , pt .Timestamp (), metric .Type ().String ())
344
329
}
345
330
}
@@ -452,20 +437,6 @@ func addSingleSummaryDataPoint(pt pmetric.SummaryDataPoint, resource pcommon.Res
452
437
timestamp := convertTimeStamp (pt .Timestamp ())
453
438
baseLabels := createAttributes (resource , pt .Attributes (), settings .ExternalLabels )
454
439
455
- createLabels := func (name string , extras ... string ) []prompb.Label {
456
- extraLabelCount := len (extras ) / 2
457
- labels := make ([]prompb.Label , len (baseLabels ), len (baseLabels )+ extraLabelCount + 1 ) // +1 for name
458
- copy (labels , baseLabels )
459
-
460
- for extrasIdx := 0 ; extrasIdx < extraLabelCount ; extrasIdx ++ {
461
- labels = append (labels , prompb.Label {Name : extras [extrasIdx ], Value : extras [extrasIdx + 1 ]})
462
- }
463
-
464
- labels = append (labels , prompb.Label {Name : model .MetricNameLabel , Value : name })
465
-
466
- return labels
467
- }
468
-
469
440
// treat sum as a sample in an individual TimeSeries
470
441
sum := & prompb.Sample {
471
442
Value : pt .Sum (),
@@ -475,7 +446,7 @@ func addSingleSummaryDataPoint(pt pmetric.SummaryDataPoint, resource pcommon.Res
475
446
sum .Value = math .Float64frombits (value .StaleNaN )
476
447
}
477
448
// sum and count of the summary should append suffix to baseName
478
- sumlabels := createLabels (baseName + sumStr )
449
+ sumlabels := createLabels (baseName + sumStr , baseLabels )
479
450
addSample (tsMap , sum , sumlabels , metric .Type ().String ())
480
451
481
452
// treat count as a sample in an individual TimeSeries
@@ -486,7 +457,7 @@ func addSingleSummaryDataPoint(pt pmetric.SummaryDataPoint, resource pcommon.Res
486
457
if pt .Flags ().NoRecordedValue () {
487
458
count .Value = math .Float64frombits (value .StaleNaN )
488
459
}
489
- countlabels := createLabels (baseName + countStr )
460
+ countlabels := createLabels (baseName + countStr , baseLabels )
490
461
addSample (tsMap , count , countlabels , metric .Type ().String ())
491
462
492
463
// process each percentile/quantile
@@ -500,18 +471,36 @@ func addSingleSummaryDataPoint(pt pmetric.SummaryDataPoint, resource pcommon.Res
500
471
quantile .Value = math .Float64frombits (value .StaleNaN )
501
472
}
502
473
percentileStr := strconv .FormatFloat (qt .Quantile (), 'f' , - 1 , 64 )
503
- qtlabels := createLabels (baseName , quantileStr , percentileStr )
474
+ qtlabels := createLabels (baseName , baseLabels , quantileStr , percentileStr )
504
475
addSample (tsMap , quantile , qtlabels , metric .Type ().String ())
505
476
}
506
477
507
478
// add _created time series if needed
508
479
startTimestamp := pt .StartTimestamp ()
509
480
if settings .ExportCreatedMetric && startTimestamp != 0 {
510
- createdLabels := createLabels (baseName + createdSuffix )
481
+ createdLabels := createLabels (baseName + createdSuffix , baseLabels )
511
482
addCreatedTimeSeriesIfNeeded (tsMap , createdLabels , startTimestamp , pt .Timestamp (), metric .Type ().String ())
512
483
}
513
484
}
514
485
486
+ // createLabels returns a copy of baseLabels, adding to it the pair model.MetricNameLabel=name.
487
+ // If extras are provided, corresponding label pairs are also added to the returned slice.
488
+ // If extras is uneven length, the last (unpaired) extra will be ignored.
489
+ func createLabels (name string , baseLabels []prompb.Label , extras ... string ) []prompb.Label {
490
+ extraLabelCount := len (extras ) / 2
491
+ labels := make ([]prompb.Label , len (baseLabels ), len (baseLabels )+ extraLabelCount + 1 ) // +1 for name
492
+ copy (labels , baseLabels )
493
+
494
+ n := len (extras )
495
+ n -= n % 2
496
+ for extrasIdx := 0 ; extrasIdx < n ; extrasIdx += 2 {
497
+ labels = append (labels , prompb.Label {Name : extras [extrasIdx ], Value : extras [extrasIdx + 1 ]})
498
+ }
499
+
500
+ labels = append (labels , prompb.Label {Name : model .MetricNameLabel , Value : name })
501
+ return labels
502
+ }
503
+
515
504
// addCreatedTimeSeriesIfNeeded adds {name}_created time series with a single
516
505
// sample. If the series exists, then new samples won't be added.
517
506
func addCreatedTimeSeriesIfNeeded (
0 commit comments