From ea09299ca59f0b48aa0b92bf4266de4f5eca5d5f Mon Sep 17 00:00:00 2001 From: Fabian Reinartz Date: Mon, 22 May 2017 11:15:40 +0200 Subject: [PATCH] pkg/textparse: handle trailing labels comma (#2752) --- pkg/textparse/lex.l | 2 +- pkg/textparse/lex.l.go | 9 +++++++-- pkg/textparse/parse_test.go | 4 ++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/pkg/textparse/lex.l b/pkg/textparse/lex.l index 8cd009ceab..50d5390a7c 100644 --- a/pkg/textparse/lex.l +++ b/pkg/textparse/lex.l @@ -73,7 +73,7 @@ M [a-zA-Z_:] l.offsets = append(l.offsets, l.i) [ \t]+ -\} s = lstateValue +,?\} s = lstateValue l.mend = l.i ,? s = lstateLName l.offsets = append(l.offsets, l.i) diff --git a/pkg/textparse/lex.l.go b/pkg/textparse/lex.l.go index 836b3bbdb5..d28a0248a6 100644 --- a/pkg/textparse/lex.l.go +++ b/pkg/textparse/lex.l.go @@ -264,7 +264,12 @@ yystate20: yystate21: c = l.next() - goto yyrule8 + switch { + default: + goto yyrule8 + case c == '}': + goto yystate22 + } yystate22: c = l.next() @@ -391,7 +396,7 @@ yyrule5: // {S}({M}|{D})* yyrule6: // [ \t]+ goto yystate0 -yyrule7: // \} +yyrule7: // ,?\} { s = lstateValue l.mend = l.i diff --git a/pkg/textparse/parse_test.go b/pkg/textparse/parse_test.go index d1afa8c50b..30464d5377 100644 --- a/pkg/textparse/parse_test.go +++ b/pkg/textparse/parse_test.go @@ -31,7 +31,7 @@ func TestParse(t *testing.T) { input := `# HELP go_gc_duration_seconds A summary of the GC invocation durations. # TYPE go_gc_duration_seconds summary go_gc_duration_seconds{quantile="0"} 4.9351e-05 -go_gc_duration_seconds{quantile="0.25"} 7.424100000000001e-05 +go_gc_duration_seconds{quantile="0.25",} 7.424100000000001e-05 go_gc_duration_seconds{quantile="0.5",a="b"} 8.3835e-05 go_gc_duration_seconds_count 99 some:aggregate:rate5m{a_b="c"} 1 @@ -52,7 +52,7 @@ go_goroutines 33 123123` v: 4.9351e-05, lset: labels.FromStrings("__name__", "go_gc_duration_seconds", "quantile", "0"), }, { - m: `go_gc_duration_seconds{quantile="0.25"}`, + m: `go_gc_duration_seconds{quantile="0.25",}`, v: 7.424100000000001e-05, lset: labels.FromStrings("__name__", "go_gc_duration_seconds", "quantile", "0.25"), }, {