File tree Expand file tree Collapse file tree 2 files changed +13
-2
lines changed
Expand file tree Collapse file tree 2 files changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -99,7 +99,7 @@ type TextParser struct {
9999// Summaries and histograms are rather special beasts. You would probably not
100100// use them in the simple text format anyway. This method can deal with
101101// summaries and histograms if they are presented in exactly the way the
102- // text.Create function creates them.
102+ // text. Create function creates them.
103103//
104104// This method must not be called concurrently. If you want to parse different
105105// input concurrently, instantiate a separate Parser for each goroutine.
@@ -142,6 +142,7 @@ func (p *TextParser) reset(in io.Reader) {
142142 p .currentQuantile = math .NaN ()
143143 p .currentBucket = math .NaN ()
144144 p .currentMF = nil
145+ p .currentMetric = nil
145146}
146147
147148// startOfLine represents the state where the next byte read from p.buf is the
@@ -417,7 +418,7 @@ func (p *TextParser) startLabelValue() stateFn {
417418 return p .startLabelName
418419
419420 case '}' :
420- if p .currentMF == nil {
421+ if p .currentMF == nil || p . currentMetric == nil {
421422 p .parseError ("invalid metric name" )
422423 return nil
423424 }
Original file line number Diff line number Diff line change @@ -934,6 +934,16 @@ line"="bla"} 3.14
934934` ,
935935 err : `text format parsing error in line 2: label name "new" contains unescaped new-line` ,
936936 },
937+ // 40: Metric's name missing.
938+ {
939+ in : `
940+ # HELP backupmonitor_size The size of the given backup.
941+ # TYPE backupmonitor_size counter
942+ {host="local", dir="alpha"} 1834194837
943+ {host="remote", dir="beta"} 133638016
944+ ` ,
945+ err : `text format parsing error in line 4: invalid metric name` ,
946+ },
937947 }
938948 for i , scenario := range scenarios {
939949 _ , err := parser .TextToMetricFamilies (strings .NewReader (scenario .in ))
You can’t perform that action at this time.
0 commit comments