@@ -75,7 +75,9 @@ type TextParser struct {
7575 // count and sum of that summary/histogram.
7676 currentIsSummaryCount , currentIsSummarySum bool
7777 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
7981}
8082
8183// TextToMetricFamilies reads 'in' as the simple and flat text-based exchange
@@ -147,6 +149,7 @@ func (p *TextParser) reset(in io.Reader) {
147149func (p * TextParser ) startOfLine () stateFn {
148150 p .lineCount ++
149151 p .currentMetricIsInsideBraces = false
152+ p .currentMetricInsideBracesIsPresent = false
150153 if p .skipBlankTab (); p .err != nil {
151154 // This is the only place that we expect to see io.EOF,
152155 // which is not an error but the signal that we are done.
@@ -301,17 +304,24 @@ func (p *TextParser) startLabelName() stateFn {
301304 }
302305 if p .currentByte != '=' {
303306 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 ()))
306309 return nil
307310 }
308311 switch p .currentByte {
309312 case ',' :
310313 p .setOrCreateCurrentMF ()
314+ if p .currentMF .Type == nil {
315+ p .currentMF .Type = dto .MetricType_UNTYPED .Enum ()
316+ }
311317 p .currentMetric = & dto.Metric {}
318+ p .currentMetricInsideBracesIsPresent = true
312319 return p .startLabelName
313320 case '}' :
314321 p .setOrCreateCurrentMF ()
322+ if p .currentMF .Type == nil {
323+ p .currentMF .Type = dto .MetricType_UNTYPED .Enum ()
324+ }
315325 p .currentMetric = & dto.Metric {}
316326 p .currentMetric .Label = append (p .currentMetric .Label , p .currentLabelPairs ... )
317327 p .currentLabelPairs = nil
0 commit comments