@@ -45,18 +45,6 @@ func TestQueryShardQuery(t *testing.T, instantQueryCodec Codec, shardedPrometheu
45
45
name : "outer aggregation with without grouping" ,
46
46
expression : "count(sum without (pod) (http_requests_total))" ,
47
47
},
48
- {
49
- name : "aggregate expression with label_replace" ,
50
- expression : `sum by (pod) (label_replace(metric, "dst_label", "$1", "src_label", "re"))` ,
51
- },
52
- {
53
- name : "aggregate without expression with label_replace" ,
54
- expression : `sum without (pod) (label_replace(metric, "dst_label", "$1", "src_label", "re"))` ,
55
- },
56
- {
57
- name : "binary expression" ,
58
- expression : `http_requests_total{code="400"} / http_requests_total` ,
59
- },
60
48
{
61
49
name : "binary expression with constant" ,
62
50
expression : `http_requests_total{code="400"} / 4` ,
@@ -69,10 +57,6 @@ func TestQueryShardQuery(t *testing.T, instantQueryCodec Codec, shardedPrometheu
69
57
name : "binary aggregation with different grouping labels" ,
70
58
expression : `sum by (pod) (http_requests_total{code="400"}) / sum by (cluster) (http_requests_total)` ,
71
59
},
72
- {
73
- name : "multiple binary expressions" ,
74
- expression : `(http_requests_total{code="400"} + http_requests_total{code="500"}) / http_requests_total` ,
75
- },
76
60
{
77
61
name : "multiple binary expressions with empty vector matchers" ,
78
62
expression : `
@@ -193,6 +177,11 @@ sum by (container) (
193
177
expression : `sort_desc(avg(label_replace(label_replace(label_replace(count_over_time(container_memory_working_set_bytes{container!="", container!="POD", instance!="", }[1h] ), "node", "$1", "instance", "(.+)"), "container_name", "$1", "container", "(.+)"), "pod_name", "$1", "pod", "(.+)")*label_replace(label_replace(label_replace(avg_over_time(container_memory_working_set_bytes{container!="", container!="POD", instance!="", }[1h] ), "node", "$1", "instance", "(.+)"), "container_name", "$1", "container", "(.+)"), "pod_name", "$1", "pod", "(.+)")) by (namespace, container_name, pod_name, node, cluster_id))` ,
194
178
shardingLabels : []string {"namespace" , "cluster_id" },
195
179
},
180
+ {
181
+ name : "aggregate expression with label_replace" ,
182
+ expression : `sum by (pod) (label_replace(metric, "dst_label", "$1", "src_label", "re"))` ,
183
+ shardingLabels : []string {"pod" },
184
+ },
196
185
}
197
186
198
187
// Shardable by labels instant queries with matrix response
@@ -233,7 +222,7 @@ sum by (container) (
233
222
{
234
223
name : "binary expression with outer without grouping" ,
235
224
expression : `sum(http_requests_total{code="400"} * http_requests_total) without (pod)` ,
236
- shardingLabels : []string {"pod" },
225
+ shardingLabels : []string {model . MetricNameLabel , "pod" },
237
226
},
238
227
{
239
228
name : "binary expression with vector matching and outer without grouping" ,
@@ -268,6 +257,26 @@ http_requests_total`,
268
257
expression : `sum without (pod) (label_replace(metric, "dst_label", "$1", "src_label", "re"))` ,
269
258
shardingLabels : []string {"pod" , "dst_label" },
270
259
},
260
+ {
261
+ name : "binary expression" ,
262
+ expression : `http_requests_total{code="400"} / http_requests_total` ,
263
+ shardingLabels : []string {model .MetricNameLabel },
264
+ },
265
+ {
266
+ name : "binary expression among vector and scalar" ,
267
+ expression : `aaaa - bbb > 1000` ,
268
+ shardingLabels : []string {model .MetricNameLabel },
269
+ },
270
+ {
271
+ name : "binary expression with set operation" ,
272
+ expression : `aaaa and bbb` ,
273
+ shardingLabels : []string {model .MetricNameLabel },
274
+ },
275
+ {
276
+ name : "multiple binary expressions" ,
277
+ expression : `(http_requests_total{code="400"} + http_requests_total{code="500"}) / http_requests_total` ,
278
+ shardingLabels : []string {model .MetricNameLabel },
279
+ },
271
280
}
272
281
273
282
type testCase struct {
@@ -324,6 +333,7 @@ http_requests_total`,
324
333
name : fmt .Sprintf ("non shardable query: %s" , query .name ),
325
334
path : fmt .Sprintf (`/api/v1/query?time=120&query=%s` , url .QueryEscape (query .expression )),
326
335
codec : instantQueryCodec ,
336
+ shardSize : 2 ,
327
337
isShardable : false ,
328
338
responses : []string {
329
339
`{"status":"success","data":{"resultType":"vector","result":[{"metric":{"__name__":"up","job":"foo"},"value":[1,"1"]}],"stats":{"samples":{"totalQueryableSamples":10,"totalQueryableSamplesPerStep":[[1,10]]}}}}` ,
@@ -334,6 +344,7 @@ http_requests_total`,
334
344
name : fmt .Sprintf ("non shardable query_range: %s" , query .name ),
335
345
path : fmt .Sprintf (`/api/v1/query_range?start=1&end=2&step=1&query=%s` , url .QueryEscape (query .expression )),
336
346
codec : shardedPrometheusCodec ,
347
+ shardSize : 2 ,
337
348
isShardable : false ,
338
349
responses : []string {
339
350
`{"status":"success","data":{"resultType":"matrix","result":[{"metric":{"__job__":"a","__name__":"metric"},"values":[[1,"1"],[2,"2"],[3,"3"]]}],"stats":{"samples":{"totalQueryableSamples":6,"totalQueryableSamplesPerStep":[[1,1],[2,2],[3,3]]}}}}` ,
0 commit comments