From cabfa6d27402913c6cc90da49eef51a9dfd3d193 Mon Sep 17 00:00:00 2001 From: Owen Williams Date: Fri, 8 Dec 2023 10:34:06 -0500 Subject: [PATCH] Restore previous behavior where spaces between label terms are acceptable in Promparse Signed-off-by: Owen Williams --- model/textparse/promparse.go | 9 ++++----- model/textparse/promparse_test.go | 6 ++++++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/model/textparse/promparse.go b/model/textparse/promparse.go index 5443225e74..0e9e2ee824 100644 --- a/model/textparse/promparse.go +++ b/model/textparse/promparse.go @@ -442,12 +442,11 @@ func (p *PromParser) parseLVals() error { // and last character. p.offsets = append(p.offsets, p.l.start+1, p.l.i-1) - // Free trailing commas are allowed. - t = p.nextToken() - if t == tComma { + // 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() - } else if t != tBraceClose { - return p.parseError("expected comma or brace close", t) } } } diff --git a/model/textparse/promparse_test.go b/model/textparse/promparse_test.go index 00f515f5ed..2a4921332f 100644 --- a/model/textparse/promparse_test.go +++ b/model/textparse/promparse_test.go @@ -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 = "2.0" a = "b" } 8.3835e-05 go_gc_duration_seconds_count 99 some:aggregate:rate5m{a_b="c"} 1 # 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" }`, v: 8.3835e-05, 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`, v: 99,