From 6aefb2d5a0ad75de92ff0f9c225d87c463e7d12e Mon Sep 17 00:00:00 2001 From: Artyom Antonov Date: Wed, 21 May 2025 16:43:59 +0500 Subject: [PATCH 1/2] mark tagged terms with empty values with HasWildcard when using useCarbonBehavior feature flag --- finder/tagged.go | 4 ++-- finder/tagged_test.go | 45 +++++++++++++++++++++++++++++-------------- 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/finder/tagged.go b/finder/tagged.go index 4e379c51..42154c2b 100644 --- a/finder/tagged.go +++ b/finder/tagged.go @@ -303,8 +303,8 @@ func ParseTaggedConditions(conditions []string, config *config.Config, autocompl terms[i].HasWildcard = where.HasWildcard(terms[i].Value) // special case when using useCarbonBehaviour = true // which matches everything that does not have that tag - emptyValue := config.FeatureFlags.UseCarbonBehavior && terms[i].Value == "" - if !terms[i].HasWildcard && !emptyValue { + terms[i].HasWildcard = terms[i].HasWildcard || config.FeatureFlags.UseCarbonBehavior && terms[i].Value == "" + if !terms[i].HasWildcard { nonWildcards++ } case "!=": diff --git a/finder/tagged_test.go b/finder/tagged_test.go index c6cb7cb0..3f3cc15f 100644 --- a/finder/tagged_test.go +++ b/finder/tagged_test.go @@ -930,14 +930,16 @@ func TestParseSeriesByTagWithCostsFromCountTable(t *testing.T) { func TestTaggedFinder_whereFilter(t *testing.T) { tests := []struct { - name string - query string - from int64 - until int64 - dailyEnabled bool - taggedCosts map[string]*config.Costs - want string - wantPre string + name string + query string + from int64 + until int64 + dailyEnabled bool + useCarbonBehavior bool + dontMatchMissingTags bool + taggedCosts map[string]*config.Costs + want string + wantPre string }{ { name: "nodaily", @@ -959,26 +961,41 @@ func TestTaggedFinder_whereFilter(t *testing.T) { date.FromTimestampToDaysFormat(1668124800) + "' AND Date <= '" + date.UntilTimestampToDaysFormat(1668124810) + "')", wantPre: "", }, + { + name: "", + query: "seriesByTag('emptyval=', 'what=value')", + from: 1668124800, // 2022-11-11 00:00:00 UTC + until: 1668124810, // 2022-11-11 00:00:10 UTC + dailyEnabled: true, + useCarbonBehavior: true, + want: "((Tag1='what=value') AND (NOT arrayExists((x) -> x LIKE 'emptyval=%', Tags))) AND (Date >='" + + date.FromTimestampToDaysFormat(1668124800) + "' AND Date <= '" + date.UntilTimestampToDaysFormat(1668124810) + "')", + wantPre: "", + }, } for _, tt := range tests { t.Run(tt.name+" "+time.Unix(tt.from, 0).Format(time.RFC3339), func(t *testing.T) { config := config.New() config.ClickHouse.TaggedCosts = tt.taggedCosts - terms, err := ParseSeriesByTag(tt.query, config) - if err != nil { - t.Fatal(err) - } + config.FeatureFlags.UseCarbonBehavior = tt.useCarbonBehavior + config.FeatureFlags.DontMatchMissingTags = tt.dontMatchMissingTags + f := NewTagged( "http://localhost:8123/", "graphite_tags", "", tt.dailyEnabled, - false, - false, + tt.useCarbonBehavior, + tt.dontMatchMissingTags, false, clickhouse.Options{}, tt.taggedCosts, ) + stat := &FinderStat{} + terms, err := f.PrepareTaggedTerms(context.Background(), config, tt.query, tt.from, tt.until, stat) + if err != nil { + t.Fatal(err) + } got, gotDate, err := f.whereFilter(terms, tt.from, tt.until) if err != nil { t.Fatal(err) From aa00237d01bccf49568a945d492c6321f0c22d95 Mon Sep 17 00:00:00 2001 From: Artyom Antonov Date: Fri, 23 May 2025 16:58:53 +0500 Subject: [PATCH 2/2] fix linter errors --- finder/tagged_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/finder/tagged_test.go b/finder/tagged_test.go index 7540c861..964aaefd 100644 --- a/finder/tagged_test.go +++ b/finder/tagged_test.go @@ -1004,7 +1004,9 @@ func TestTaggedFinder_whereFilter(t *testing.T) { clickhouse.Options{}, tt.taggedCosts, ) + stat := &FinderStat{} + terms, err := f.PrepareTaggedTerms(context.Background(), config, tt.query, tt.from, tt.until, stat) if err != nil { t.Fatal(err)