Skip to content

Commit

Permalink
fix(finder): fix seriesByTag arg t=~^q
Browse files Browse the repository at this point in the history
  • Loading branch information
msaf1980 committed Nov 3, 2023
1 parent d38ebe6 commit 3be28ba
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
4 changes: 4 additions & 0 deletions finder/tagged_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ func TestTaggedWhere(t *testing.T) {
{"seriesByTag('name=~^cpu|mem')", 0, "Tag1 LIKE '\\\\_\\\\_name\\\\_\\\\_=%' AND match(Tag1, '^__name__=cpu|mem')", "Tag1 LIKE '\\\\_\\\\_name\\\\_\\\\_=%' AND match(Tag1, '^__name__=cpu|mem')", false},
{"seriesByTag('name=~^cpu|mem$')", 0, "Tag1 LIKE '\\\\_\\\\_name\\\\_\\\\_=%' AND match(Tag1, '^__name__=cpu|mem$')", "Tag1 LIKE '\\\\_\\\\_name\\\\_\\\\_=%' AND match(Tag1, '^__name__=cpu|mem$')", false},
{"seriesByTag('name=rps', 'key=~value')", 0, "(Tag1='__name__=rps') AND (arrayExists((x) -> x LIKE 'key=%' AND match(x, '^key=.*value'), Tags))", "", false},
// test for issue #244
{"seriesByTag('name=rps', 'key=~^value')", 0, "(Tag1='__name__=rps') AND (arrayExists((x) -> x LIKE 'key=value%' AND match(x, '^key=value'), Tags))", "", false},
{"seriesByTag('name=rps', 'key=~^value.*')", 0, "(Tag1='__name__=rps') AND (arrayExists((x) -> x LIKE 'key=value%' AND match(x, '^key=value.*'), Tags))", "", false},
{"seriesByTag('name=rps', 'key=~^valu[a-e]')", 0, "(Tag1='__name__=rps') AND (arrayExists((x) -> x LIKE 'key=valu%' AND match(x, '^key=valu[a-e]'), Tags))", "", false},
{"seriesByTag('name=rps', 'key=~^value$')", 0, "(Tag1='__name__=rps') AND (arrayExists((x) -> x='key=value', Tags))", "", false},
{"seriesByTag('name=rps', 'key=~hello.world')", 0, "(Tag1='__name__=rps') AND (arrayExists((x) -> x LIKE 'key=%' AND match(x, '^key=.*hello.world'), Tags))", "", false},
{`seriesByTag('cpu=cpu-total','host=~Vladimirs-MacBook-Pro\.local')`, 0, `(Tag1='cpu=cpu-total') AND (arrayExists((x) -> x LIKE 'host=%' AND match(x, '^host=.*Vladimirs-MacBook-Pro\\.local'), Tags))`, "", false},
Expand Down
6 changes: 4 additions & 2 deletions pkg/where/match.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,12 @@ func TreeGlob(field string, query string) string {
func ConcatMatchKV(key, value string) string {
startLine := value[0] == '^'
endLine := value[len(value)-1] == '$'
if startLine {
if startLine && endLine {
return key + opEq + value[1:]
} else if endLine {
return key + opEq + value + "\\\\%"
return key + opEq + "\\\\%" + value
} else if startLine {
return key + opEq + value[1:] + "\\\\%"
}
return key + opEq + "\\\\%" + value
}
Expand Down
1 change: 1 addition & 0 deletions pkg/where/where_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func TestNonRegexpPrefix(t *testing.T) {
{`__name__=cpu.load`, `__name__=cpu`},
{`__name__=~(cpu|mem)`, `__name__=~`},
{`__name__=~cpu|mem`, `__name__=~`},
{`__name__=~^host`, `__name__=~`},
}

for _, test := range table {
Expand Down

0 comments on commit 3be28ba

Please sign in to comment.