Skip to content

Commit 2e984ce

Browse files
committed
Change currentLabelPairs field name and add descriptive comment
Signed-off-by: Federico Torres <[email protected]>
1 parent ad09b93 commit 2e984ce

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

expfmt/text_parse.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ type TextParser struct {
6060
currentMF *dto.MetricFamily
6161
currentMetric *dto.Metric
6262
currentLabelPair *dto.LabelPair
63-
currentLabel []*dto.LabelPair
63+
currentLabelPairs []*dto.LabelPair // Temporarily stores label pairs while parsing a metric line.
6464

6565
// The remaining member variables are only used for summaries/histograms.
6666
currentLabels map[string]string // All labels including '__name__' but excluding 'quantile'/'le'
@@ -282,8 +282,8 @@ func (p *TextParser) startLabelName() stateFn {
282282
return nil // Unexpected end of input.
283283
}
284284
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
287287
if p.skipBlankTab(); p.err != nil {
288288
return nil // Unexpected end of input.
289289
}
@@ -309,8 +309,8 @@ func (p *TextParser) startLabelName() stateFn {
309309
case '}':
310310
p.setOrCreateCurrentMF()
311311
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
314314
if p.skipBlankTab(); p.err != nil {
315315
return nil // Unexpected end of input.
316316
}
@@ -321,7 +321,7 @@ func (p *TextParser) startLabelName() stateFn {
321321
}
322322
}
323323
p.parseError(fmt.Sprintf("expected '=' after label name, found %q", p.currentByte))
324-
p.currentLabel = nil
324+
p.currentLabelPairs = nil
325325
return nil
326326
}
327327
p.currentLabelPair = &dto.LabelPair{Name: proto.String(p.currentToken.String())}
@@ -333,17 +333,17 @@ func (p *TextParser) startLabelName() stateFn {
333333
// labels to 'real' labels.
334334
if !(p.currentMF.GetType() == dto.MetricType_SUMMARY && p.currentLabelPair.GetName() == model.QuantileLabel) &&
335335
!(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)
337337
}
338338
// Check for duplicate label names.
339339
labels := make(map[string]struct{})
340-
for _, l := range p.currentLabel {
340+
for _, l := range p.currentLabelPairs {
341341
lName := l.GetName()
342342
if _, exists := labels[lName]; !exists {
343343
labels[lName] = struct{}{}
344344
} else {
345345
p.parseError(fmt.Sprintf("duplicate label names for metric %q", p.currentMF.GetName()))
346-
p.currentLabel = nil
346+
p.currentLabelPairs = nil
347347
return nil
348348
}
349349
}
@@ -376,7 +376,7 @@ func (p *TextParser) startLabelValue() stateFn {
376376
if p.currentQuantile, p.err = parseFloat(p.currentLabelPair.GetValue()); p.err != nil {
377377
// Create a more helpful error message.
378378
p.parseError(fmt.Sprintf("expected float as value for 'quantile' label, got %q", p.currentLabelPair.GetValue()))
379-
p.currentLabel = nil
379+
p.currentLabelPairs = nil
380380
return nil
381381
}
382382
} else {
@@ -407,15 +407,15 @@ func (p *TextParser) startLabelValue() stateFn {
407407
p.parseError("invalid metric name")
408408
return nil
409409
}
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
412412
if p.skipBlankTab(); p.err != nil {
413413
return nil // Unexpected end of input.
414414
}
415415
return p.readingValue
416416
default:
417417
p.parseError(fmt.Sprintf("unexpected end of label value %q", p.currentLabelPair.GetValue()))
418-
p.currentLabel = nil
418+
p.currentLabelPairs = nil
419419
return nil
420420
}
421421
}
@@ -767,7 +767,7 @@ func (p *TextParser) readTokenAsLabelValue() {
767767
p.currentToken.WriteByte('\n')
768768
default:
769769
p.parseError(fmt.Sprintf("invalid escape sequence '\\%c'", p.currentByte))
770-
p.currentLabel = nil
770+
p.currentLabelPairs = nil
771771
return
772772
}
773773
escaped = false

0 commit comments

Comments
 (0)