@@ -67,10 +67,6 @@ func TestQueryShardQuery(t *testing.T, instantQueryCodec Codec, shardedPrometheu
67
67
name : "binary aggregation with different grouping labels" ,
68
68
expression : `sum by (pod) (http_requests_total{code="400"}) / sum by (cluster) (http_requests_total)` ,
69
69
},
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
- },
74
70
{
75
71
name : "multiple binary expressions" ,
76
72
expression : `(http_requests_total{code="400"} + http_requests_total{code="500"}) / http_requests_total` ,
@@ -86,6 +82,14 @@ http_requests_total`,
86
82
name : "problematic query" ,
87
83
expression : `sum(a by(lanel)` ,
88
84
},
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
+ },
89
93
}
90
94
91
95
shardableByLabels := []queries {
@@ -147,6 +151,36 @@ sum by (container) (
147
151
expression : "histogram_quantile(0.95, sum(rate(metric[1m])) by (le, cluster))" ,
148
152
shardingLabels : []string {"cluster" },
149
153
},
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
+ },
150
184
}
151
185
152
186
// Shardable by labels instant queries with matrix response
@@ -197,6 +231,21 @@ sum by (container) (
197
231
http_requests_total` ,
198
232
shardingLabels : []string {"cluster" , "pod" , model .MetricNameLabel },
199
233
},
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
+ },
200
249
}
201
250
202
251
type testCase struct {
0 commit comments