Skip to content
This repository has been archived by the owner on Aug 23, 2023. It is now read-only.

Commit

Permalink
add = to valid characters in metric names
Browse files Browse the repository at this point in the history
  • Loading branch information
replay committed Oct 31, 2017
1 parent f3bd367 commit df646b2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
14 changes: 7 additions & 7 deletions expr/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ type MetricRequest struct {
func ParseMany(targets []string) ([]*expr, error) {
var out []*expr
for _, target := range targets {
e, leftover, err := Parse(target)
e, leftover, err := Parse(target, false)
if err != nil {
return nil, err
}
Expand All @@ -95,7 +95,7 @@ func ParseMany(targets []string) ([]*expr, error) {

// Parses an expression string and turns it into an expression
// also returns any leftover data that could not be parsed
func Parse(e string) (*expr, string, error) {
func Parse(e string, keyvalue bool) (*expr, string, error) {
// skip whitespace
for len(e) > 1 && e[0] == ' ' {
e = e[1:]
Expand All @@ -122,7 +122,7 @@ func Parse(e string) (*expr, string, error) {
return &expr{str: val, etype: etString}, e, err
}

name, e := parseName(e)
name, e := parseName(e, keyvalue)

if name == "" {
return nil, e, ErrMissingArg
Expand Down Expand Up @@ -167,7 +167,7 @@ func parseArgList(e string) (string, []*expr, map[string]*expr, string, error) {
for {
var arg *expr
var err error
arg, e, err = Parse(e)
arg, e, err = Parse(e, true)
if err != nil {
return "", nil, nil, e, err
}
Expand All @@ -179,7 +179,7 @@ func parseArgList(e string) (string, []*expr, map[string]*expr, string, error) {
// we now know we're parsing a key-value pair
if arg.etype == etName && e[0] == '=' {
e = e[1:]
argCont, eCont, errCont := Parse(e)
argCont, eCont, errCont := Parse(e, true)
if errCont != nil {
return "", nil, nil, eCont, errCont
}
Expand Down Expand Up @@ -261,14 +261,14 @@ func parseConst(s string) (*expr, string, error) {
return &expr{int: v, str: s[:i], etype: etInt}, s[i:], err
}

func parseName(s string) (string, string) {
func parseName(s string, keyvalue bool) (string, string) {

var i int

FOR:
for braces := 0; i < len(s); i++ {

if isNameChar(s[i]) {
if isNameChar(s[i]) || (!keyvalue && s[i] == 61) {
continue
}

Expand Down
7 changes: 6 additions & 1 deletion expr/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ func TestParse(t *testing.T) {
&expr{str: "metric.*.foo"},
nil,
},
{
"a.b.c;tagkey1=tagvalue1;tagkey2=tagvalue2",
&expr{str: "a.b.c;tagkey1=tagvalue1;tagkey2=tagvalue2"},
nil,
},
{
"func(metric)",
&expr{
Expand Down Expand Up @@ -330,7 +335,7 @@ func TestParse(t *testing.T) {
}

for _, tt := range tests {
e, _, err := Parse(tt.s)
e, _, err := Parse(tt.s, false)
if err != tt.err {
t.Errorf("case %+v expected err %v, got %v", tt.s, tt.err, err)
continue
Expand Down

0 comments on commit df646b2

Please sign in to comment.