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 {
99
99
// Summaries and histograms are rather special beasts. You would probably not
100
100
// use them in the simple text format anyway. This method can deal with
101
101
// summaries and histograms if they are presented in exactly the way the
102
- // text.Create function creates them.
102
+ // text. Create function creates them.
103
103
//
104
104
// This method must not be called concurrently. If you want to parse different
105
105
// input concurrently, instantiate a separate Parser for each goroutine.
@@ -142,6 +142,7 @@ func (p *TextParser) reset(in io.Reader) {
142
142
p .currentQuantile = math .NaN ()
143
143
p .currentBucket = math .NaN ()
144
144
p .currentMF = nil
145
+ p .currentMetric = nil
145
146
}
146
147
147
148
// startOfLine represents the state where the next byte read from p.buf is the
@@ -417,7 +418,7 @@ func (p *TextParser) startLabelValue() stateFn {
417
418
return p .startLabelName
418
419
419
420
case '}' :
420
- if p .currentMF == nil {
421
+ if p .currentMF == nil || p . currentMetric == nil {
421
422
p .parseError ("invalid metric name" )
422
423
return nil
423
424
}
Original file line number Diff line number Diff line change @@ -934,6 +934,16 @@ line"="bla"} 3.14
934
934
` ,
935
935
err : `text format parsing error in line 2: label name "new" contains unescaped new-line` ,
936
936
},
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
+ },
937
947
}
938
948
for i , scenario := range scenarios {
939
949
_ , err := parser .TextToMetricFamilies (strings .NewReader (scenario .in ))
You can’t perform that action at this time.
0 commit comments