@@ -75,7 +75,9 @@ type TextParser struct {
75
75
// count and sum of that summary/histogram.
76
76
currentIsSummaryCount , currentIsSummarySum bool
77
77
currentIsHistogramCount , currentIsHistogramSum bool
78
- currentMetricIsInsideBraces bool
78
+ // These indicate if the metric name from the current line being parsed is inside
79
+ // braces and if that metric name was found respectively.
80
+ currentMetricIsInsideBraces , currentMetricInsideBracesIsPresent bool
79
81
}
80
82
81
83
// TextToMetricFamilies reads 'in' as the simple and flat text-based exchange
@@ -147,6 +149,7 @@ func (p *TextParser) reset(in io.Reader) {
147
149
func (p * TextParser ) startOfLine () stateFn {
148
150
p .lineCount ++
149
151
p .currentMetricIsInsideBraces = false
152
+ p .currentMetricInsideBracesIsPresent = false
150
153
if p .skipBlankTab (); p .err != nil {
151
154
// This is the only place that we expect to see io.EOF,
152
155
// which is not an error but the signal that we are done.
@@ -301,17 +304,24 @@ func (p *TextParser) startLabelName() stateFn {
301
304
}
302
305
if p .currentByte != '=' {
303
306
if p .currentMetricIsInsideBraces {
304
- if p .currentMF != nil && p . currentMF . GetName () != p . currentToken . String () {
305
- p .parseError (fmt .Sprintf ("multiple metric names %s %s " , p .currentMF .GetName (), p . currentToken . String ()))
307
+ if p .currentMetricInsideBracesIsPresent {
308
+ p .parseError (fmt .Sprintf ("multiple metric names for metric %q " , p .currentMF .GetName ()))
306
309
return nil
307
310
}
308
311
switch p .currentByte {
309
312
case ',' :
310
313
p .setOrCreateCurrentMF ()
314
+ if p .currentMF .Type == nil {
315
+ p .currentMF .Type = dto .MetricType_UNTYPED .Enum ()
316
+ }
311
317
p .currentMetric = & dto.Metric {}
318
+ p .currentMetricInsideBracesIsPresent = true
312
319
return p .startLabelName
313
320
case '}' :
314
321
p .setOrCreateCurrentMF ()
322
+ if p .currentMF .Type == nil {
323
+ p .currentMF .Type = dto .MetricType_UNTYPED .Enum ()
324
+ }
315
325
p .currentMetric = & dto.Metric {}
316
326
p .currentMetric .Label = append (p .currentMetric .Label , p .currentLabelPairs ... )
317
327
p .currentLabelPairs = nil
0 commit comments