@@ -207,21 +207,6 @@ func isValidAggregationTemporality(metric pmetric.Metric) bool {
207
207
208
208
func (c * PrometheusConverter ) addHistogramDataPoints (dataPoints pmetric.HistogramDataPointSlice ,
209
209
resource pcommon.Resource , settings Settings , baseName string ) {
210
- createLabels := func (nameSuffix string , baseLabels []prompb.Label , extras ... string ) []prompb.Label {
211
- extraLabelCount := len (extras ) / 2
212
- labels := make ([]prompb.Label , len (baseLabels ), len (baseLabels )+ extraLabelCount + 1 ) // +1 for name
213
- copy (labels , baseLabels )
214
-
215
- for extrasIdx := 0 ; extrasIdx < extraLabelCount ; extrasIdx ++ {
216
- labels = append (labels , prompb.Label {Name : extras [extrasIdx ], Value : extras [extrasIdx + 1 ]})
217
- }
218
-
219
- // sum, count, and buckets of the histogram should append suffix to baseName
220
- labels = append (labels , prompb.Label {Name : model .MetricNameLabel , Value : baseName + nameSuffix })
221
-
222
- return labels
223
- }
224
-
225
210
for x := 0 ; x < dataPoints .Len (); x ++ {
226
211
pt := dataPoints .At (x )
227
212
timestamp := convertTimeStamp (pt .Timestamp ())
@@ -239,7 +224,7 @@ func (c *PrometheusConverter) addHistogramDataPoints(dataPoints pmetric.Histogra
239
224
sum .Value = math .Float64frombits (value .StaleNaN )
240
225
}
241
226
242
- sumlabels := createLabels (sumStr , baseLabels )
227
+ sumlabels := createLabels (baseName + sumStr , baseLabels )
243
228
c .addSample (sum , sumlabels )
244
229
245
230
}
@@ -253,7 +238,7 @@ func (c *PrometheusConverter) addHistogramDataPoints(dataPoints pmetric.Histogra
253
238
count .Value = math .Float64frombits (value .StaleNaN )
254
239
}
255
240
256
- countlabels := createLabels (countStr , baseLabels )
241
+ countlabels := createLabels (baseName + countStr , baseLabels )
257
242
c .addSample (count , countlabels )
258
243
259
244
// cumulative count for conversion to cumulative histogram
@@ -273,7 +258,7 @@ func (c *PrometheusConverter) addHistogramDataPoints(dataPoints pmetric.Histogra
273
258
bucket .Value = math .Float64frombits (value .StaleNaN )
274
259
}
275
260
boundStr := strconv .FormatFloat (bound , 'f' , - 1 , 64 )
276
- labels := createLabels (bucketStr , baseLabels , leStr , boundStr )
261
+ labels := createLabels (baseName + bucketStr , baseLabels , leStr , boundStr )
277
262
ts := c .addSample (bucket , labels )
278
263
279
264
bucketBounds = append (bucketBounds , bucketBoundsData {ts : ts , bound : bound })
@@ -287,15 +272,15 @@ func (c *PrometheusConverter) addHistogramDataPoints(dataPoints pmetric.Histogra
287
272
} else {
288
273
infBucket .Value = float64 (pt .Count ())
289
274
}
290
- infLabels := createLabels (bucketStr , baseLabels , leStr , pInfStr )
275
+ infLabels := createLabels (baseName + bucketStr , baseLabels , leStr , pInfStr )
291
276
ts := c .addSample (infBucket , infLabels )
292
277
293
278
bucketBounds = append (bucketBounds , bucketBoundsData {ts : ts , bound : math .Inf (1 )})
294
279
c .addExemplars (pt , bucketBounds )
295
280
296
281
startTimestamp := pt .StartTimestamp ()
297
282
if settings .ExportCreatedMetric && startTimestamp != 0 {
298
- labels := createLabels (createdSuffix , baseLabels )
283
+ labels := createLabels (baseName + createdSuffix , baseLabels )
299
284
c .addTimeSeriesIfNeeded (labels , startTimestamp , pt .Timestamp ())
300
285
}
301
286
}
@@ -405,20 +390,6 @@ func maxTimestamp(a, b pcommon.Timestamp) pcommon.Timestamp {
405
390
406
391
func (c * PrometheusConverter ) addSummaryDataPoints (dataPoints pmetric.SummaryDataPointSlice , resource pcommon.Resource ,
407
392
settings Settings , baseName string ) {
408
- createLabels := func (name string , baseLabels []prompb.Label , extras ... string ) []prompb.Label {
409
- extraLabelCount := len (extras ) / 2
410
- labels := make ([]prompb.Label , len (baseLabels ), len (baseLabels )+ extraLabelCount + 1 ) // +1 for name
411
- copy (labels , baseLabels )
412
-
413
- for extrasIdx := 0 ; extrasIdx < extraLabelCount ; extrasIdx ++ {
414
- labels = append (labels , prompb.Label {Name : extras [extrasIdx ], Value : extras [extrasIdx + 1 ]})
415
- }
416
-
417
- labels = append (labels , prompb.Label {Name : model .MetricNameLabel , Value : name })
418
-
419
- return labels
420
- }
421
-
422
393
for x := 0 ; x < dataPoints .Len (); x ++ {
423
394
pt := dataPoints .At (x )
424
395
timestamp := convertTimeStamp (pt .Timestamp ())
@@ -470,6 +441,24 @@ func (c *PrometheusConverter) addSummaryDataPoints(dataPoints pmetric.SummaryDat
470
441
}
471
442
}
472
443
444
+ // createLabels returns a copy of baseLabels, adding to it the pair model.MetricNameLabel=name.
445
+ // If extras are provided, corresponding label pairs are also added to the returned slice.
446
+ // If extras is uneven length, the last (unpaired) extra will be ignored.
447
+ func createLabels (name string , baseLabels []prompb.Label , extras ... string ) []prompb.Label {
448
+ extraLabelCount := len (extras ) / 2
449
+ labels := make ([]prompb.Label , len (baseLabels ), len (baseLabels )+ extraLabelCount + 1 ) // +1 for name
450
+ copy (labels , baseLabels )
451
+
452
+ n := len (extras )
453
+ n -= n % 2
454
+ for extrasIdx := 0 ; extrasIdx < n ; extrasIdx += 2 {
455
+ labels = append (labels , prompb.Label {Name : extras [extrasIdx ], Value : extras [extrasIdx + 1 ]})
456
+ }
457
+
458
+ labels = append (labels , prompb.Label {Name : model .MetricNameLabel , Value : name })
459
+ return labels
460
+ }
461
+
473
462
// getOrCreateTimeSeries returns the time series corresponding to the label set if existent, and false.
474
463
// Otherwise it creates a new one and returns that, and true.
475
464
func (c * PrometheusConverter ) getOrCreateTimeSeries (lbls []prompb.Label ) (* prompb.TimeSeries , bool ) {
0 commit comments