From 71a52f5f9062a1538f4146d72be98b3b4f79d35d Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Sun, 16 Feb 2020 19:06:02 +0200 Subject: [PATCH] lib/protoparser/prometheus: skip leading whitespace from tag names --- lib/protoparser/prometheus/parser.go | 2 +- lib/protoparser/prometheus/parser_test.go | 27 ++++++++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/lib/protoparser/prometheus/parser.go b/lib/protoparser/prometheus/parser.go index e76a3026c..bacccffa0 100644 --- a/lib/protoparser/prometheus/parser.go +++ b/lib/protoparser/prometheus/parser.go @@ -236,7 +236,7 @@ func unmarshalTags(dst []Tag, s string, noEscapes bool) (string, []Tag, error) { if len(s) == 0 || s[0] != ',' { return s, dst, fmt.Errorf("missing comma after tag %s=%q", key, value) } - s = s[1:] + s = skipLeadingWhitespace(s[1:]) } } diff --git a/lib/protoparser/prometheus/parser_test.go b/lib/protoparser/prometheus/parser_test.go index b1517da6d..3a5628c72 100644 --- a/lib/protoparser/prometheus/parser_test.go +++ b/lib/protoparser/prometheus/parser_test.go @@ -253,7 +253,7 @@ func TestRowsUnmarshalSuccess(t *testing.T) { }) // Multi lines with invalid line - f("\t foo\t {} 0.3\t 2\naaa\n bar.baz 0.34 43\n", &Rows{ + f("\t foo\t { } 0.3\t 2\naaa\n bar.baz 0.34 43\n", &Rows{ Rows: []Row{ { Metric: "foo", @@ -267,4 +267,29 @@ func TestRowsUnmarshalSuccess(t *testing.T) { }, }, }) + + // Spaces around tags + f(`vm_accounting { name="vminsertRows", accountID = "1" , projectID= "1" } 277779100`, &Rows{ + Rows: []Row{ + { + Metric: "vm_accounting", + Tags: []Tag{ + { + Key: "name", + Value: "vminsertRows", + }, + { + Key: "accountID", + Value: "1", + }, + { + Key: "projectID", + Value: "1", + }, + }, + Value: 277779100, + Timestamp: 0, + }, + }, + }) }