Restore previous behavior where spaces between label terms are acceptable in Promparse

Signed-off-by: Owen Williams <owen.williams@grafana.com>
This commit is contained in:
Owen Williams 2023-12-08 10:34:06 -05:00
parent ac4e978816
commit cabfa6d274
2 changed files with 10 additions and 5 deletions

View file

@ -442,12 +442,11 @@ func (p *PromParser) parseLVals() error {
// and last character. // and last character.
p.offsets = append(p.offsets, p.l.start+1, p.l.i-1) p.offsets = append(p.offsets, p.l.start+1, p.l.i-1)
// Free trailing commas are allowed. // Free trailing commas are allowed. NOTE: this allows spaces between label
// names, unlike in OpenMetrics. It is not clear if this is intended or an
// accidental bug.
if t = p.nextToken(); t == tComma {
t = p.nextToken() t = p.nextToken()
if t == tComma {
t = p.nextToken()
} else if t != tBraceClose {
return p.parseError("expected comma or brace close", t)
} }
} }
} }

View file

@ -47,6 +47,7 @@ go_gc_duration_seconds{ quantile="1.0", a="b" } 8.3835e-05
go_gc_duration_seconds { quantile="1.0", a="b" } 8.3835e-05 go_gc_duration_seconds { quantile="1.0", a="b" } 8.3835e-05
go_gc_duration_seconds { quantile= "1.0", a= "b", } 8.3835e-05 go_gc_duration_seconds { quantile= "1.0", a= "b", } 8.3835e-05
go_gc_duration_seconds { quantile = "1.0", a = "b" } 8.3835e-05 go_gc_duration_seconds { quantile = "1.0", a = "b" } 8.3835e-05
go_gc_duration_seconds { quantile = "2.0" a = "b" } 8.3835e-05
go_gc_duration_seconds_count 99 go_gc_duration_seconds_count 99
some:aggregate:rate5m{a_b="c"} 1 some:aggregate:rate5m{a_b="c"} 1
# HELP go_goroutines Number of goroutines that currently exist. # HELP go_goroutines Number of goroutines that currently exist.
@ -129,6 +130,11 @@ testmetric{label="\"bar\""} 1`
m: `go_gc_duration_seconds { quantile = "1.0", a = "b" }`, m: `go_gc_duration_seconds { quantile = "1.0", a = "b" }`,
v: 8.3835e-05, v: 8.3835e-05,
lset: labels.FromStrings("__name__", "go_gc_duration_seconds", "quantile", "1.0", "a", "b"), lset: labels.FromStrings("__name__", "go_gc_duration_seconds", "quantile", "1.0", "a", "b"),
}, {
// NOTE: Unlike OpenMetrics, Promparse allows spaces between label terms. This appears to be unintended and should probably be fixed.
m: `go_gc_duration_seconds { quantile = "2.0" a = "b" }`,
v: 8.3835e-05,
lset: labels.FromStrings("__name__", "go_gc_duration_seconds", "quantile", "2.0", "a", "b"),
}, { }, {
m: `go_gc_duration_seconds_count`, m: `go_gc_duration_seconds_count`,
v: 99, v: 99,