Skip to content

Commit

Permalink
allow anything inside label
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolaydubina committed Dec 18, 2024
1 parent 839e47a commit 0de1b79
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func ParseMetric(s string) (name string, labels map[string]string, err error) {
}

i := strings.IndexByte(s, '{')
j := strings.IndexByte(s, '}')
j := strings.LastIndexByte(s, '}')

if (i == -1) != (j == -1) {
return "", nil, ErrInvalidLabel
Expand Down
11 changes: 10 additions & 1 deletion metric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@ func TestParseMetric(t *testing.T) {
"b": "b",
},
},
{
s: `http_request_count{code="200",method="GET",path="/api/v1/something/{id}"}`,
name: "http_request_count",
labels: map[string]string{
"code": "200",
"method": "GET",
"path": "/api/v1/something/{id}",
},
},
}
for _, tt := range tests {
t.Run(tt.s, func(t *testing.T) {
Expand Down Expand Up @@ -127,13 +136,13 @@ func TestParseMetric_Error(t *testing.T) {
"{}",
"asdf{",
"asdf}",
"asdf{a=\"1}\"}",
"asdf}a=\"1}\"{",
"asd}f",
"asdf{,}",
"asdf{=}",
"asdf{=a}",
"asdf{a=}",
"asdf{a=\"b\"}a",
"asdf{a=a",
"asdf{a=a,",
"asdf{a=a,}",
Expand Down

0 comments on commit 0de1b79

Please sign in to comment.