From e31591e6fe62a7a95f479b015c0b13c1ae4d98d9 Mon Sep 17 00:00:00 2001 From: Julius Volz Date: Thu, 28 Mar 2013 18:14:41 +0100 Subject: [PATCH] Allow single-letter identifiers (metric and label names). --- rules/lexer.l | 2 +- rules/lexer.l.go | 2 +- rules/rules_test.go | 7 +++++++ rules/testdata.go | 8 ++++++++ 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/rules/lexer.l b/rules/lexer.l index 643f52fc6d..1edfcc6b09 100644 --- a/rules/lexer.l +++ b/rules/lexer.l @@ -45,7 +45,7 @@ AVG|SUM|MAX|MIN { yylval.str = yytext; return AGGR_OP } [*/%] { yylval.str = yytext; return MULT_OP } {D}+{U} { yylval.str = yytext; return DURATION } -{L}({L}|{D})+ { yylval.str = yytext; return IDENTIFIER } +{L}({L}|{D})* { yylval.str = yytext; return IDENTIFIER } \-?{D}+(\.{D}*)? { num, err := strconv.ParseFloat(yytext, 32); if (err != nil && err.(*strconv.NumError).Err == strconv.ErrSyntax) { diff --git a/rules/lexer.l.go b/rules/lexer.l.go index 7ec712fd63..0671c45afb 100644 --- a/rules/lexer.l.go +++ b/rules/lexer.l.go @@ -411,7 +411,7 @@ var yyrules []yyrule = []yyrule{{regexp.MustCompile("[^\\n]"), nil, []yystartcon return yyactionreturn{DURATION, yyRT_USER_RETURN} } return yyactionreturn{0, yyRT_FALLTHROUGH} -}}, {regexp.MustCompile("([a-zA-Z_:])(([a-zA-Z_:])|([0-9]))+"), nil, []yystartcondition{}, false, func() (yyar yyactionreturn) { +}}, {regexp.MustCompile("([a-zA-Z_:])(([a-zA-Z_:])|([0-9]))*"), nil, []yystartcondition{}, false, func() (yyar yyactionreturn) { defer func() { if r := recover(); r != nil { if r != "yyREJECT" { diff --git a/rules/rules_test.go b/rules/rules_test.go index bda1cb1963..1b928ffd92 100644 --- a/rules/rules_test.go +++ b/rules/rules_test.go @@ -179,6 +179,13 @@ var expressionTests = []struct { }, fullRanges: 8, intervalRanges: 0, + }, { + expr: "x{y='testvalue'}", + output: []string{ + "x{y='testvalue'} => 100 @[%v]", + }, + fullRanges: 0, + intervalRanges: 1, // Invalid expressions that should fail to parse. }, { expr: "", diff --git a/rules/testdata.go b/rules/testdata.go index deeb0a54dc..7a900bab05 100644 --- a/rules/testdata.go +++ b/rules/testdata.go @@ -140,6 +140,14 @@ var testMatrix = ast.Matrix{ }, Values: getTestValueStream(0, 800, 80), }, + // Single-letter metric and label names. + { + Metric: model.Metric{ + model.MetricNameLabel: "x", + "y": "testvalue", + }, + Values: getTestValueStream(0, 100, 10), + }, } var testVector = getTestVectorFromTestMatrix(testMatrix)