Skip to content

Commit

Permalink
properly pushdown label filters for label_match() and label_mismatch(…
Browse files Browse the repository at this point in the history
…) functions
  • Loading branch information
valyala committed Feb 18, 2024
1 parent cbc428c commit dbff62c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions optimizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func getCommonLabelFilters(e Expr) []LabelFilter {
switch strings.ToLower(t.Name) {
case "label_set":
return getCommonLabelFiltersForLabelSet(t.Args)
case "label_replace", "label_join", "label_map":
case "label_replace", "label_join", "label_map", "label_match", "label_mismatch":
return getCommonLabelFiltersForLabelReplace(t.Args)
case "label_copy", "label_move":
return getCommonLabelFiltersForLabelCopy(t.Args)
Expand Down Expand Up @@ -339,7 +339,7 @@ func pushdownBinaryOpFiltersInplace(e Expr, lfs []LabelFilter) {
switch strings.ToLower(t.Name) {
case "label_set":
pushdownLabelFiltersForLabelSet(t.Args, lfs)
case "label_replace", "label_join", "label_map":
case "label_replace", "label_join", "label_map", "label_match", "label_mismatch":
pushdownLabelFiltersForLabelReplace(t.Args, lfs)
case "label_copy", "label_move":
pushdownLabelFiltersForLabelCopy(t.Args, lfs)
Expand Down
8 changes: 8 additions & 0 deletions optimizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,14 @@ func TestOptimize(t *testing.T) {
f(`label_map(foo, "a", "x", "y") + bar{x="y"}`, `label_map(foo{x="y"}, "a", "x", "y") + bar{x="y"}`)
f(`label_map(foo{a="qwe",b="c"}, "a", "x", "y") + bar{a="rt",x="y"}`, `label_map(foo{a="qwe",b="c",x="y"}, "a", "x", "y") + bar{a="rt",b="c",x="y"}`)

// label_match
f(`label_match(foo, "a", "x", "y") + bar{x="y"}`, `label_match(foo{x="y"}, "a", "x", "y") + bar{x="y"}`)
f(`label_match(foo{a="qwe",b="c"}, "a", "x", "y") + bar{a="rt",x="y"}`, `label_match(foo{a="qwe",b="c",x="y"}, "a", "x", "y") + bar{a="rt",b="c",x="y"}`)

// label_mismatch
f(`label_mismatch(foo, "a", "x", "y") + bar{x="y"}`, `label_mismatch(foo{x="y"}, "a", "x", "y") + bar{x="y"}`)
f(`label_mismatch(foo{a="qwe",b="c"}, "a", "x", "y") + bar{a="rt",x="y"}`, `label_mismatch(foo{a="qwe",b="c",x="y"}, "a", "x", "y") + bar{a="rt",b="c",x="y"}`)

// label_copy
f(`label_copy(foo, "a", "b") + bar{x="y"}`, `label_copy(foo{x="y"}, "a", "b") + bar{x="y"}`)
f(`label_copy(foo, "a", "b", "c", "d") + bar{a="y",b="z"}`, `label_copy(foo{a="y"}, "a", "b", "c", "d") + bar{a="y",b="z"}`)
Expand Down

0 comments on commit dbff62c

Please sign in to comment.