Browse Source

pkg/textparse: parse metric names with ':'

pull/2694/head
Fabian Reinartz 8 years ago
parent
commit
f7c5d96e84
  1. 7
      pkg/textparse/lex.l
  2. 14
      pkg/textparse/lex.l.go
  3. 5
      pkg/textparse/parse_test.go

7
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_:]
<lstateLabels>,? s = lstateLName
l.offsets = append(l.offsets, l.i)
<lstateLName>{M}({M}|{D})*= s = lstateLValue
<lstateLName>{S}({L}|{D})*= s = lstateLValue
l.offsets = append(l.offsets, l.i-1)
<lstateLValue>\"(\\.|[^\\"])*\" s = lstateLabels

14
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)

5
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,

Loading…
Cancel
Save