@@ -67,10 +67,6 @@ func TestQueryShardQuery(t *testing.T, instantQueryCodec Codec, shardedPrometheu
6767 name : "binary aggregation with different grouping labels" ,
6868 expression : `sum by (pod) (http_requests_total{code="400"}) / sum by (cluster) (http_requests_total)` ,
6969 },
70- {
71- name : "binary expression with vector matching and label_replace" ,
72- expression : `http_requests_total{code="400"} / on (pod) label_replace(metric, "dst_label", "$1", "src_label", "re")` ,
73- },
7470 {
7571 name : "multiple binary expressions" ,
7672 expression : `(http_requests_total{code="400"} + http_requests_total{code="500"}) / http_requests_total` ,
@@ -86,6 +82,14 @@ http_requests_total`,
8682 name : "problematic query" ,
8783 expression : `sum(a by(lanel)` ,
8884 },
85+ {
86+ name : "aggregate by expression with label_replace, sharding label is dynamic" ,
87+ expression : `sum by (dst_label) (label_replace(metric, "dst_label", "$1", "src_label", "re"))` ,
88+ },
89+ {
90+ name : "aggregate by expression with label_join, sharding label is dynamic" ,
91+ expression : `sum by (dst_label) (label_join(metric, "dst_label", ",", "src_label"))` ,
92+ },
8993 }
9094
9195 shardableByLabels := []queries {
@@ -147,6 +151,36 @@ sum by (container) (
147151 expression : "histogram_quantile(0.95, sum(rate(metric[1m])) by (le, cluster))" ,
148152 shardingLabels : []string {"cluster" },
149153 },
154+ {
155+ name : "aggregate by expression with label_replace, sharding label is not dynamic" ,
156+ expression : `sum by (pod) (label_replace(metric, "dst_label", "$1", "src_label", "re"))` ,
157+ shardingLabels : []string {"pod" },
158+ },
159+ {
160+ name : "aggregate by expression with label_join, sharding label is not dynamic" ,
161+ expression : `sum by (pod) (label_join(metric, "dst_label", ",", "src_label"))` ,
162+ shardingLabels : []string {"pod" },
163+ },
164+ {
165+ name : "label_join and aggregation on multiple labels. Can be sharded by the static one" ,
166+ expression : `sum by (pod, dst_label) (label_join(metric, "dst_label", ",", "src_label"))` ,
167+ shardingLabels : []string {"pod" },
168+ },
169+ {
170+ name : "binary expression with vector matching and label_replace" ,
171+ expression : `http_requests_total{code="400"} / on (pod) label_replace(metric, "dst_label", "$1", "src_label", "re")` ,
172+ shardingLabels : []string {"pod" },
173+ },
174+ {
175+ name : "nested label joins" ,
176+ expression : `label_join(sum by (pod) (label_join(metric, "dst_label", ",", "src_label")), "dst_label1", ",", "dst_label")` ,
177+ shardingLabels : []string {"pod" },
178+ },
179+ {
180+ name : "complex query with label_replace, binary expr and aggregations on dynamic label" ,
181+ expression : `sum(sum_over_time(container_memory_working_set_bytes{container_name!="POD",container_name!="",namespace="kube-system"}[1d:5m])) by (instance, cluster) / avg(label_replace(sum(sum_over_time(kube_node_status_capacity_memory_bytes[1d:5m])) by (node, cluster), "instance", "$1", "node", "(.*)")) by (instance, cluster)` ,
182+ shardingLabels : []string {"cluster" },
183+ },
150184 }
151185
152186 // Shardable by labels instant queries with matrix response
@@ -197,6 +231,21 @@ sum by (container) (
197231http_requests_total` ,
198232 shardingLabels : []string {"cluster" , "pod" , model .MetricNameLabel },
199233 },
234+ {
235+ name : "aggregate without expression with label_replace, sharding label is not dynamic" ,
236+ expression : `sum without (dst_label) (label_replace(metric, "dst_label", "$1", "src_label", "re"))` ,
237+ shardingLabels : []string {"dst_label" },
238+ },
239+ {
240+ name : "aggregate without expression with label_join, sharding label is not dynamic" ,
241+ expression : `sum without (dst_label) (label_join(metric, "dst_label", ",", "src_label"))` ,
242+ shardingLabels : []string {"dst_label" },
243+ },
244+ {
245+ name : "aggregate without expression with label_replace" ,
246+ expression : `sum without (pod) (label_replace(metric, "dst_label", "$1", "src_label", "re"))` ,
247+ shardingLabels : []string {"pod" , "dst_label" },
248+ },
200249 }
201250
202251 type testCase struct {
0 commit comments