From 65a745a0ed6347ade3302637a7b107b66ca0e732 Mon Sep 17 00:00:00 2001 From: msaf1980 Date: Thu, 22 Apr 2021 13:35:18 +0500 Subject: [PATCH 1/3] test: tagged find and masked All with asterisk (with regex) --- finder/tagged_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/finder/tagged_test.go b/finder/tagged_test.go index 2881cdd28..b78ad7772 100644 --- a/finder/tagged_test.go +++ b/finder/tagged_test.go @@ -38,6 +38,8 @@ func TestTaggedWhere(t *testing.T) { {"seriesByTag('name=m{in,ax')", "Tag1='__name__=m{in,ax'", "", true}, {"seriesByTag('name=value','what={avg,max}')", "(Tag1='__name__=value') AND (arrayExists((x) -> x IN ('what=avg','what=max'), Tags))", "", false}, {"seriesByTag('name=value','what!={avg,max}')", "(Tag1='__name__=value') AND (NOT arrayExists((x) -> x IN ('what=avg','what=max'), Tags))", "", false}, + // grafana workaround for multi-value variables default, masked with * + {"seriesByTag('name=value','what=~*')", "(Tag1='__name__=value') AND (arrayExists((x) -> x LIKE 'what=%', Tags))", "", false}, // If All masked to value with * } for _, test := range table { From a33c86828730a0b1d6ac6322e0efec1b19277654 Mon Sep 17 00:00:00 2001 From: msaf1980 Date: Thu, 22 Apr 2021 13:45:00 +0500 Subject: [PATCH 2/3] fix: tagged find and masked All with asterisk (with regex) --- pkg/where/match.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/where/match.go b/pkg/where/match.go index 4758b9464..896cabc7e 100644 --- a/pkg/where/match.go +++ b/pkg/where/match.go @@ -6,7 +6,7 @@ import ( ) var ( - opEq string = "=" + opEq string = "=" ) // clearGlob cleanup grafana globs like {name} @@ -153,6 +153,9 @@ func ConcatMatchKV(key, value string) string { } func Match(field string, key, value string) string { + if value == "*" { + return Like(field, key+"=%") + } expr := ConcatMatchKV(key, value) simplePrefix := NonRegexpPrefix(expr) if len(simplePrefix) == len(expr) { From acc123d6f93eefd63571733303a3ff43438b856d Mon Sep 17 00:00:00 2001 From: msaf1980 Date: Sat, 24 Apr 2021 07:49:11 +0500 Subject: [PATCH 3/3] fix for empty tag value during autocompletion --- finder/tagged_test.go | 2 ++ pkg/where/match.go | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/finder/tagged_test.go b/finder/tagged_test.go index b78ad7772..d88e307cd 100644 --- a/finder/tagged_test.go +++ b/finder/tagged_test.go @@ -40,6 +40,8 @@ func TestTaggedWhere(t *testing.T) { {"seriesByTag('name=value','what!={avg,max}')", "(Tag1='__name__=value') AND (NOT arrayExists((x) -> x IN ('what=avg','what=max'), Tags))", "", false}, // grafana workaround for multi-value variables default, masked with * {"seriesByTag('name=value','what=~*')", "(Tag1='__name__=value') AND (arrayExists((x) -> x LIKE 'what=%', Tags))", "", false}, // If All masked to value with * + // empty tag value during autocompletion + {"seriesByTag('name=value','what=~')", "(Tag1='__name__=value') AND (arrayExists((x) -> x LIKE 'what=%', Tags))", "", false}, // If All masked to value with * } for _, test := range table { diff --git a/pkg/where/match.go b/pkg/where/match.go index 896cabc7e..4f9e3c952 100644 --- a/pkg/where/match.go +++ b/pkg/where/match.go @@ -153,7 +153,7 @@ func ConcatMatchKV(key, value string) string { } func Match(field string, key, value string) string { - if value == "*" { + if len(value) == 0 || value == "*" { return Like(field, key+"=%") } expr := ConcatMatchKV(key, value)