Skip to content

Commit 4960cc2

Browse files
authored
fix(tagged): mark tagged terms with empty values with HasWildcard when using useCarbonBehavior feature flag (#314)
1 parent 0d1c986 commit 4960cc2

File tree

2 files changed

+34
-17
lines changed

2 files changed

+34
-17
lines changed

finder/tagged.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,8 @@ func ParseTaggedConditions(conditions []string, config *config.Config, autocompl
326326
terms[i].HasWildcard = where.HasWildcard(terms[i].Value)
327327
// special case when using useCarbonBehaviour = true
328328
// which matches everything that does not have that tag
329-
emptyValue := config.FeatureFlags.UseCarbonBehavior && terms[i].Value == ""
330-
if !terms[i].HasWildcard && !emptyValue {
329+
terms[i].HasWildcard = terms[i].HasWildcard || config.FeatureFlags.UseCarbonBehavior && terms[i].Value == ""
330+
if !terms[i].HasWildcard {
331331
nonWildcards++
332332
}
333333
case "!=":

finder/tagged_test.go

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -943,14 +943,16 @@ func TestParseSeriesByTagWithCostsFromCountTable(t *testing.T) {
943943

944944
func TestTaggedFinder_whereFilter(t *testing.T) {
945945
tests := []struct {
946-
name string
947-
query string
948-
from int64
949-
until int64
950-
dailyEnabled bool
951-
taggedCosts map[string]*config.Costs
952-
want string
953-
wantPre string
946+
name string
947+
query string
948+
from int64
949+
until int64
950+
dailyEnabled bool
951+
useCarbonBehavior bool
952+
dontMatchMissingTags bool
953+
taggedCosts map[string]*config.Costs
954+
want string
955+
wantPre string
954956
}{
955957
{
956958
name: "nodaily",
@@ -972,29 +974,44 @@ func TestTaggedFinder_whereFilter(t *testing.T) {
972974
date.FromTimestampToDaysFormat(1668124800) + "' AND Date <= '" + date.UntilTimestampToDaysFormat(1668124810) + "')",
973975
wantPre: "",
974976
},
977+
{
978+
name: "",
979+
query: "seriesByTag('emptyval=', 'what=value')",
980+
from: 1668124800, // 2022-11-11 00:00:00 UTC
981+
until: 1668124810, // 2022-11-11 00:00:10 UTC
982+
dailyEnabled: true,
983+
useCarbonBehavior: true,
984+
want: "((Tag1='what=value') AND (NOT arrayExists((x) -> x LIKE 'emptyval=%', Tags))) AND (Date >='" +
985+
date.FromTimestampToDaysFormat(1668124800) + "' AND Date <= '" + date.UntilTimestampToDaysFormat(1668124810) + "')",
986+
wantPre: "",
987+
},
975988
}
976989
for _, tt := range tests {
977990
t.Run(tt.name+" "+time.Unix(tt.from, 0).Format(time.RFC3339), func(t *testing.T) {
978991
config := config.New()
979992
config.ClickHouse.TaggedCosts = tt.taggedCosts
980-
981-
terms, err := ParseSeriesByTag(tt.query, config)
982-
if err != nil {
983-
t.Fatal(err)
984-
}
993+
config.FeatureFlags.UseCarbonBehavior = tt.useCarbonBehavior
994+
config.FeatureFlags.DontMatchMissingTags = tt.dontMatchMissingTags
985995

986996
f := NewTagged(
987997
"http://localhost:8123/",
988998
"graphite_tags",
989999
"",
9901000
tt.dailyEnabled,
991-
false,
992-
false,
1001+
tt.useCarbonBehavior,
1002+
tt.dontMatchMissingTags,
9931003
false,
9941004
clickhouse.Options{},
9951005
tt.taggedCosts,
9961006
)
9971007

1008+
stat := &FinderStat{}
1009+
1010+
terms, err := f.PrepareTaggedTerms(context.Background(), config, tt.query, tt.from, tt.until, stat)
1011+
if err != nil {
1012+
t.Fatal(err)
1013+
}
1014+
9981015
got, gotDate, err := f.whereFilter(terms, tt.from, tt.until)
9991016
if err != nil {
10001017
t.Fatal(err)

0 commit comments

Comments
 (0)