Skip to content

Commit 6aefb2d

Browse files
committed
mark tagged terms with empty values with HasWildcard when using useCarbonBehavior feature flag
1 parent 0228a8d commit 6aefb2d

File tree

2 files changed

+33
-16
lines changed

2 files changed

+33
-16
lines changed

finder/tagged.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,8 @@ func ParseTaggedConditions(conditions []string, config *config.Config, autocompl
303303
terms[i].HasWildcard = where.HasWildcard(terms[i].Value)
304304
// special case when using useCarbonBehaviour = true
305305
// which matches everything that does not have that tag
306-
emptyValue := config.FeatureFlags.UseCarbonBehavior && terms[i].Value == ""
307-
if !terms[i].HasWildcard && !emptyValue {
306+
terms[i].HasWildcard = terms[i].HasWildcard || config.FeatureFlags.UseCarbonBehavior && terms[i].Value == ""
307+
if !terms[i].HasWildcard {
308308
nonWildcards++
309309
}
310310
case "!=":

finder/tagged_test.go

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -930,14 +930,16 @@ func TestParseSeriesByTagWithCostsFromCountTable(t *testing.T) {
930930

931931
func TestTaggedFinder_whereFilter(t *testing.T) {
932932
tests := []struct {
933-
name string
934-
query string
935-
from int64
936-
until int64
937-
dailyEnabled bool
938-
taggedCosts map[string]*config.Costs
939-
want string
940-
wantPre string
933+
name string
934+
query string
935+
from int64
936+
until int64
937+
dailyEnabled bool
938+
useCarbonBehavior bool
939+
dontMatchMissingTags bool
940+
taggedCosts map[string]*config.Costs
941+
want string
942+
wantPre string
941943
}{
942944
{
943945
name: "nodaily",
@@ -959,26 +961,41 @@ func TestTaggedFinder_whereFilter(t *testing.T) {
959961
date.FromTimestampToDaysFormat(1668124800) + "' AND Date <= '" + date.UntilTimestampToDaysFormat(1668124810) + "')",
960962
wantPre: "",
961963
},
964+
{
965+
name: "",
966+
query: "seriesByTag('emptyval=', 'what=value')",
967+
from: 1668124800, // 2022-11-11 00:00:00 UTC
968+
until: 1668124810, // 2022-11-11 00:00:10 UTC
969+
dailyEnabled: true,
970+
useCarbonBehavior: true,
971+
want: "((Tag1='what=value') AND (NOT arrayExists((x) -> x LIKE 'emptyval=%', Tags))) AND (Date >='" +
972+
date.FromTimestampToDaysFormat(1668124800) + "' AND Date <= '" + date.UntilTimestampToDaysFormat(1668124810) + "')",
973+
wantPre: "",
974+
},
962975
}
963976
for _, tt := range tests {
964977
t.Run(tt.name+" "+time.Unix(tt.from, 0).Format(time.RFC3339), func(t *testing.T) {
965978
config := config.New()
966979
config.ClickHouse.TaggedCosts = tt.taggedCosts
967-
terms, err := ParseSeriesByTag(tt.query, config)
968-
if err != nil {
969-
t.Fatal(err)
970-
}
980+
config.FeatureFlags.UseCarbonBehavior = tt.useCarbonBehavior
981+
config.FeatureFlags.DontMatchMissingTags = tt.dontMatchMissingTags
982+
971983
f := NewTagged(
972984
"http://localhost:8123/",
973985
"graphite_tags",
974986
"",
975987
tt.dailyEnabled,
976-
false,
977-
false,
988+
tt.useCarbonBehavior,
989+
tt.dontMatchMissingTags,
978990
false,
979991
clickhouse.Options{},
980992
tt.taggedCosts,
981993
)
994+
stat := &FinderStat{}
995+
terms, err := f.PrepareTaggedTerms(context.Background(), config, tt.query, tt.from, tt.until, stat)
996+
if err != nil {
997+
t.Fatal(err)
998+
}
982999
got, gotDate, err := f.whereFilter(terms, tt.from, tt.until)
9831000
if err != nil {
9841001
t.Fatal(err)

0 commit comments

Comments
 (0)