diff --git a/rules/lexer.l b/rules/lexer.l index 643f52fc6..1edfcc6b0 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 7ec712fd6..0671c45af 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 bda1cb196..1b928ffd9 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 deeb0a54d..7a900bab0 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)