Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions expfmt/text_parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ type TextParser struct {
// Summaries and histograms are rather special beasts. You would probably not
// use them in the simple text format anyway. This method can deal with
// summaries and histograms if they are presented in exactly the way the
// text.Create function creates them.
// text. Create function creates them.
//
// This method must not be called concurrently. If you want to parse different
// input concurrently, instantiate a separate Parser for each goroutine.
Expand Down Expand Up @@ -142,6 +142,7 @@ func (p *TextParser) reset(in io.Reader) {
p.currentQuantile = math.NaN()
p.currentBucket = math.NaN()
p.currentMF = nil
p.currentMetric = nil
}

// startOfLine represents the state where the next byte read from p.buf is the
Expand Down Expand Up @@ -417,7 +418,7 @@ func (p *TextParser) startLabelValue() stateFn {
return p.startLabelName

case '}':
if p.currentMF == nil {
if p.currentMF == nil || p.currentMetric == nil {
p.parseError("invalid metric name")
return nil
}
Expand Down
10 changes: 10 additions & 0 deletions expfmt/text_parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,16 @@ line"="bla"} 3.14
`,
err: `text format parsing error in line 2: label name "new" contains unescaped new-line`,
},
// 40: Metric's name missing.
{
in: `
# HELP backupmonitor_size The size of the given backup.
# TYPE backupmonitor_size counter
{host="local", dir="alpha"} 1834194837
{host="remote", dir="beta"} 133638016
`,
err: `text format parsing error in line 4: invalid metric name`,
},
}
for i, scenario := range scenarios {
_, err := parser.TextToMetricFamilies(strings.NewReader(scenario.in))
Expand Down
Loading