Merge pull request #11681 from dgrisonnet/fix-tokens

Fix error output of the Prometheus parser to display the right tokens
This commit is contained in:
Levi Harrison 2023-01-02 16:04:20 -05:00 committed by GitHub
commit 15492d7100
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 6 deletions

View file

@ -340,7 +340,7 @@ func (p *PromParser) Next() (Entry, error) {
t2 = p.nextToken() t2 = p.nextToken()
} }
if t2 != tValue { if t2 != tValue {
return EntryInvalid, parseError("expected value after metric", t) return EntryInvalid, parseError("expected value after metric", t2)
} }
if p.val, err = parseFloat(yoloString(p.l.buf())); err != nil { if p.val, err = parseFloat(yoloString(p.l.buf())); err != nil {
return EntryInvalid, err return EntryInvalid, err
@ -350,7 +350,7 @@ func (p *PromParser) Next() (Entry, error) {
p.val = math.Float64frombits(value.NormalNaN) p.val = math.Float64frombits(value.NormalNaN)
} }
p.hasTS = false p.hasTS = false
switch p.nextToken() { switch t := p.nextToken(); t {
case tLinebreak: case tLinebreak:
break break
case tTimestamp: case tTimestamp:
@ -359,7 +359,7 @@ func (p *PromParser) Next() (Entry, error) {
return EntryInvalid, err return EntryInvalid, err
} }
if t2 := p.nextToken(); t2 != tLinebreak { if t2 := p.nextToken(); t2 != tLinebreak {
return EntryInvalid, parseError("expected next entry after timestamp", t) return EntryInvalid, parseError("expected next entry after timestamp", t2)
} }
default: default:
return EntryInvalid, parseError("expected timestamp or new record", t) return EntryInvalid, parseError("expected timestamp or new record", t)

View file

@ -219,7 +219,7 @@ func TestPromParseErrors(t *testing.T) {
}{ }{
{ {
input: "a", input: "a",
err: "expected value after metric, got \"MNAME\"", err: "expected value after metric, got \"INVALID\"",
}, },
{ {
input: "a{b='c'} 1\n", input: "a{b='c'} 1\n",
@ -263,7 +263,7 @@ func TestPromParseErrors(t *testing.T) {
}, },
{ {
input: "foo 0 1_2\n", input: "foo 0 1_2\n",
err: "expected next entry after timestamp, got \"MNAME\"", err: "expected next entry after timestamp, got \"INVALID\"",
}, },
{ {
input: `{a="ok"} 1`, input: `{a="ok"} 1`,
@ -325,7 +325,11 @@ func TestPromNullByteHandling(t *testing.T) {
}, },
{ {
input: "a\x00{b=\"ddd\"} 1", input: "a\x00{b=\"ddd\"} 1",
err: "expected value after metric, got \"MNAME\"", err: "expected value after metric, got \"INVALID\"",
},
{
input: "a 0 1\x00",
err: "expected next entry after timestamp, got \"INVALID\"",
}, },
} }