Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like an accident?

//
// 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
Comment on lines +1338 to +1341
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# HELP backupmonitor_size The size of the given backup.
# TYPE backupmonitor_size counter
{host="local", dir="alpha"} 1834194837
{host="remote", dir="beta"} 133638016
# HELP metric a metric.
# TYPE metric counter
{label="bla"} 3.14

Just to be consistent with previous test cases.

Copy link
Copy Markdown
Author

@Alhanaqtah Alhanaqtah Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I came across the fact that the error is not displayed at the values as in the previous metrics, so I decided to use these values:

# HELP backupmonitor_size The size of the given backup.
# TYPE backupmonitor_size counter
{host="local", dir="alpha"} 1834194837
{host="remote", dir="beta"} 133638016

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I follow. The request is make the test case consistent with what we use in the other test cases. The naming itself should have no effect on the case being tested.

`,
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