@@ -60,7 +60,7 @@ type TextParser struct {
60
60
currentMF * dto.MetricFamily
61
61
currentMetric * dto.Metric
62
62
currentLabelPair * dto.LabelPair
63
- currentLabel []* dto.LabelPair
63
+ currentLabelPairs []* dto.LabelPair // Temporarily stores label pairs while parsing a metric line.
64
64
65
65
// The remaining member variables are only used for summaries/histograms.
66
66
currentLabels map [string ]string // All labels including '__name__' but excluding 'quantile'/'le'
@@ -282,8 +282,8 @@ func (p *TextParser) startLabelName() stateFn {
282
282
return nil // Unexpected end of input.
283
283
}
284
284
if p .currentByte == '}' {
285
- p .currentMetric .Label = append (p .currentMetric .Label , p .currentLabel ... )
286
- p .currentLabel = nil
285
+ p .currentMetric .Label = append (p .currentMetric .Label , p .currentLabelPairs ... )
286
+ p .currentLabelPairs = nil
287
287
if p .skipBlankTab (); p .err != nil {
288
288
return nil // Unexpected end of input.
289
289
}
@@ -309,8 +309,8 @@ func (p *TextParser) startLabelName() stateFn {
309
309
case '}' :
310
310
p .setOrCreateCurrentMF ()
311
311
p .currentMetric = & dto.Metric {}
312
- p .currentMetric .Label = append (p .currentMetric .Label , p .currentLabel ... )
313
- p .currentLabel = nil
312
+ p .currentMetric .Label = append (p .currentMetric .Label , p .currentLabelPairs ... )
313
+ p .currentLabelPairs = nil
314
314
if p .skipBlankTab (); p .err != nil {
315
315
return nil // Unexpected end of input.
316
316
}
@@ -321,7 +321,7 @@ func (p *TextParser) startLabelName() stateFn {
321
321
}
322
322
}
323
323
p .parseError (fmt .Sprintf ("expected '=' after label name, found %q" , p .currentByte ))
324
- p .currentLabel = nil
324
+ p .currentLabelPairs = nil
325
325
return nil
326
326
}
327
327
p .currentLabelPair = & dto.LabelPair {Name : proto .String (p .currentToken .String ())}
@@ -333,17 +333,17 @@ func (p *TextParser) startLabelName() stateFn {
333
333
// labels to 'real' labels.
334
334
if ! (p .currentMF .GetType () == dto .MetricType_SUMMARY && p .currentLabelPair .GetName () == model .QuantileLabel ) &&
335
335
! (p .currentMF .GetType () == dto .MetricType_HISTOGRAM && p .currentLabelPair .GetName () == model .BucketLabel ) {
336
- p .currentLabel = append (p .currentLabel , p .currentLabelPair )
336
+ p .currentLabelPairs = append (p .currentLabelPairs , p .currentLabelPair )
337
337
}
338
338
// Check for duplicate label names.
339
339
labels := make (map [string ]struct {})
340
- for _ , l := range p .currentLabel {
340
+ for _ , l := range p .currentLabelPairs {
341
341
lName := l .GetName ()
342
342
if _ , exists := labels [lName ]; ! exists {
343
343
labels [lName ] = struct {}{}
344
344
} else {
345
345
p .parseError (fmt .Sprintf ("duplicate label names for metric %q" , p .currentMF .GetName ()))
346
- p .currentLabel = nil
346
+ p .currentLabelPairs = nil
347
347
return nil
348
348
}
349
349
}
@@ -376,7 +376,7 @@ func (p *TextParser) startLabelValue() stateFn {
376
376
if p .currentQuantile , p .err = parseFloat (p .currentLabelPair .GetValue ()); p .err != nil {
377
377
// Create a more helpful error message.
378
378
p .parseError (fmt .Sprintf ("expected float as value for 'quantile' label, got %q" , p .currentLabelPair .GetValue ()))
379
- p .currentLabel = nil
379
+ p .currentLabelPairs = nil
380
380
return nil
381
381
}
382
382
} else {
@@ -407,15 +407,15 @@ func (p *TextParser) startLabelValue() stateFn {
407
407
p .parseError ("invalid metric name" )
408
408
return nil
409
409
}
410
- p .currentMetric .Label = append (p .currentMetric .Label , p .currentLabel ... )
411
- p .currentLabel = nil
410
+ p .currentMetric .Label = append (p .currentMetric .Label , p .currentLabelPairs ... )
411
+ p .currentLabelPairs = nil
412
412
if p .skipBlankTab (); p .err != nil {
413
413
return nil // Unexpected end of input.
414
414
}
415
415
return p .readingValue
416
416
default :
417
417
p .parseError (fmt .Sprintf ("unexpected end of label value %q" , p .currentLabelPair .GetValue ()))
418
- p .currentLabel = nil
418
+ p .currentLabelPairs = nil
419
419
return nil
420
420
}
421
421
}
@@ -767,7 +767,7 @@ func (p *TextParser) readTokenAsLabelValue() {
767
767
p .currentToken .WriteByte ('\n' )
768
768
default :
769
769
p .parseError (fmt .Sprintf ("invalid escape sequence '\\ %c'" , p .currentByte ))
770
- p .currentLabel = nil
770
+ p .currentLabelPairs = nil
771
771
return
772
772
}
773
773
escaped = false
0 commit comments