From f7c5d96e84baa388c85ac181c2b7c9a44974afcf Mon Sep 17 00:00:00 2001 From: Fabian Reinartz Date: Tue, 9 May 2017 12:21:19 +0200 Subject: [PATCH] pkg/textparse: parse metric names with ':' --- pkg/textparse/lex.l | 7 ++++--- pkg/textparse/lex.l.go | 14 +++++++------- pkg/textparse/parse_test.go | 5 +++++ 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/pkg/textparse/lex.l b/pkg/textparse/lex.l index 3decbb1ca..4a0b45e10 100644 --- a/pkg/textparse/lex.l +++ b/pkg/textparse/lex.l @@ -46,6 +46,7 @@ func (l *lexer) Lex() int { %} D [0-9] +S [a-zA-Z] L [a-zA-Z_] M [a-zA-Z_:] @@ -63,9 +64,9 @@ M [a-zA-Z_:] #[^\r\n]*\n l.mstart = l.i [\r\n \t]+ l.mstart = l.i -{L}({L}|{D})*\{ s = lstateLabels +{S}({M}|{D})*\{ s = lstateLabels l.offsets = append(l.offsets, l.i-1) -{L}({L}|{D})* s = lstateValue +{S}({M}|{D})* s = lstateValue l.mend = l.i l.offsets = append(l.offsets, l.i) @@ -75,7 +76,7 @@ M [a-zA-Z_:] ,? s = lstateLName l.offsets = append(l.offsets, l.i) -{M}({M}|{D})*= s = lstateLValue +{S}({L}|{D})*= s = lstateLValue l.offsets = append(l.offsets, l.i-1) \"(\\.|[^\\"])*\" s = lstateLabels diff --git a/pkg/textparse/lex.l.go b/pkg/textparse/lex.l.go index 11ebde484..9b9e731b0 100644 --- a/pkg/textparse/lex.l.go +++ b/pkg/textparse/lex.l.go @@ -77,7 +77,7 @@ yystart1: goto yystate3 case c == '\x00': goto yystate2 - case c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z': + case c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z': goto yystate6 } @@ -116,7 +116,7 @@ yystate6: goto yyrule5 case c == '{': goto yystate7 - case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z': + case c >= '0' && c <= ':' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z': goto yystate6 } @@ -275,7 +275,7 @@ yystart23: switch { default: goto yyabort - case c == ':' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z': + case c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z': goto yystate24 } @@ -286,7 +286,7 @@ yystate24: goto yyabort case c == '=': goto yystate25 - case c >= '0' && c <= ':' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z': + case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z': goto yystate24 } @@ -373,13 +373,13 @@ yyrule3: // [\r\n \t]+ l.mstart = l.i goto yystate0 } -yyrule4: // {L}({L}|{D})*\{ +yyrule4: // {S}({M}|{D})*\{ { s = lstateLabels l.offsets = append(l.offsets, l.i-1) goto yystate0 } -yyrule5: // {L}({L}|{D})* +yyrule5: // {S}({M}|{D})* { s = lstateValue l.mend = l.i @@ -401,7 +401,7 @@ yyrule8: // ,? l.offsets = append(l.offsets, l.i) goto yystate0 } -yyrule9: // {M}({M}|{D})*= +yyrule9: // {S}({L}|{D})*= { s = lstateLValue l.offsets = append(l.offsets, l.i-1) diff --git a/pkg/textparse/parse_test.go b/pkg/textparse/parse_test.go index bfb91aa30..d1afa8c50 100644 --- a/pkg/textparse/parse_test.go +++ b/pkg/textparse/parse_test.go @@ -34,6 +34,7 @@ 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.5",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. # TYPE go_goroutines gauge go_goroutines 33 123123` @@ -62,6 +63,10 @@ go_goroutines 33 123123` m: `go_gc_duration_seconds_count`, v: 99, lset: labels.FromStrings("__name__", "go_gc_duration_seconds_count"), + }, { + m: `some:aggregate:rate5m{a_b="c"}`, + v: 1, + lset: labels.FromStrings("__name__", "some:aggregate:rate5m", "a_b", "c"), }, { m: `go_goroutines`, v: 33,