Skip to content

Commit 80df113

Browse files
committed
Fix test + changelog
Signed-off-by: Alan Protasio <[email protected]>
1 parent ee7919c commit 80df113

File tree

2 files changed

+33
-18
lines changed

2 files changed

+33
-18
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
* [FEATURE] Added `-api.http-request-headers-to-log` allowing for the addition of HTTP Headers to logs #4803
5757
* [FEATURE] Distributor: Added a new limit `-validation.max-labels-size-bytes` allowing to limit the combined size of labels for each timeseries. #4848
5858
* [FEATURE] Storage/Bucket: Added `-*.s3.bucket-lookup-type` allowing to configure the s3 bucket lookup type. #4794
59+
* [FEATURE] QueryFrontend: Implement experimental vertical sharding at query frontend for range/instance queries. #4863
5960
* [BUGFIX] Memberlist: Add join with no retrying when starting service. #4804
6061
* [BUGFIX] Ruler: Fix /ruler/rule_groups returns YAML with extra fields. #4767
6162
* [BUGFIX] Respecting `-tracing.otel.sample-ratio` configuration when enabling OpenTelemetry tracing with X-ray. #4862

pkg/querier/tripperware/test_shard_by_query_utils.go

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"net/http"
99
"net/http/httptest"
1010
"net/url"
11+
"sort"
1112
"testing"
1213
"time"
1314

@@ -92,6 +93,11 @@ http_requests_total`,
9293
expression: "sum by (pod) (http_requests_total)",
9394
shardingLabels: []string{"pod"},
9495
},
96+
{
97+
name: "aggregation with comparison",
98+
expression: "avg by (Roles,type) (rss_service_message_handling) > 0.5",
99+
shardingLabels: []string{"Roles", "type"},
100+
},
95101
{
96102
name: "multiple aggregations with grouping",
97103
expression: "max by (pod) (sum by (pod, cluster) (http_requests_total))",
@@ -185,23 +191,25 @@ http_requests_total`,
185191
}
186192
tests := []testCase{
187193
{
188-
name: "should shard range query when query is shardable",
189-
path: `/api/v1/query_range?end=1&start=0&step=120&query=sum(metric) by (pod,cluster_name)`,
190-
isShardable: true,
191-
codec: shardedPrometheusCodec,
192-
shardSize: 2,
194+
name: "should shard range query when query is shardable",
195+
path: `/api/v1/query_range?end=1&start=0&step=120&query=sum(metric) by (pod,cluster_name)`,
196+
isShardable: true,
197+
codec: shardedPrometheusCodec,
198+
shardingLabels: []string{"pod", "cluster_name"},
199+
shardSize: 2,
193200
responses: []string{
194201
`{"status":"success","data":{"resultType":"matrix","result":[{"metric":{"__name__":"metric","__job__":"a"},"values":[[1,"1"],[2,"2"],[3,"3"]]}],"stats":{"samples":{"totalQueryableSamples":6,"totalQueryableSamplesPerStep":[[1,1],[2,2],[3,3]]}}}}`,
195202
`{"status":"success","data":{"resultType":"matrix","result":[{"metric":{"__name__":"metric","__job__":"b"},"values":[[1,"1"],[2,"2"],[3,"3"]]}],"stats":{"samples":{"totalQueryableSamples":6,"totalQueryableSamplesPerStep":[[1,1],[2,2],[3,3]]}}}}`,
196203
},
197204
response: `{"status":"success","data":{"resultType":"matrix","result":[{"metric":{"__job__":"a","__name__":"metric"},"values":[[1,"1"],[2,"2"],[3,"3"]]},{"metric":{"__job__":"b","__name__":"metric"},"values":[[1,"1"],[2,"2"],[3,"3"]]}],"stats":{"samples":{"totalQueryableSamples":12,"totalQueryableSamplesPerStep":[[1,2],[2,4],[3,6]]}}}}`,
198205
},
199206
{
200-
name: "should shard instant query when query is shardable",
201-
path: `/api/v1/query?time=120&query=sum(metric) by (pod,cluster_name)`,
202-
codec: instantQueryCodec,
203-
shardSize: 2,
204-
isShardable: true,
207+
name: "should shard instant query when query is shardable",
208+
path: `/api/v1/query?time=120&query=sum(metric) by (pod,cluster_name)`,
209+
codec: instantQueryCodec,
210+
shardSize: 2,
211+
shardingLabels: []string{"pod", "cluster_name"},
212+
isShardable: true,
205213
responses: []string{
206214
`{"status":"success","data":{"resultType":"vector","result":[{"metric":{"__name__":"up","job":"foo"},"value":[1,"1"]}],"stats":{"samples":{"totalQueryableSamples":10,"totalQueryableSamplesPerStep":[[1,10]]}}}}`,
207215
`{"status":"success","data":{"resultType":"vector","result":[{"metric":{"__name__":"up","job":"bar"},"value":[2,"2"]}],"stats":{"samples":{"totalQueryableSamples":10,"totalQueryableSamplesPerStep":[[1,10]]}}}}`,
@@ -258,11 +266,12 @@ http_requests_total`,
258266
response: `{"status":"success","data":{"resultType":"vector","result":[{"metric":{"__name__":"up","job":"bar"},"value":[2,"2"]},{"metric":{"__name__":"up","job":"foo"},"value":[1,"1"]}],"stats":{"samples":{"totalQueryableSamples":20,"totalQueryableSamplesPerStep":[[1,20]]}}}}`,
259267
})
260268
tests = append(tests, testCase{
261-
name: fmt.Sprintf("shardable query_range: %s", query.name),
262-
path: fmt.Sprintf(`/api/v1/query_range?start=1&end=2&step=1&query=%s`, url.QueryEscape(query.expression)),
263-
codec: shardedPrometheusCodec,
264-
isShardable: true,
265-
shardSize: 2,
269+
name: fmt.Sprintf("shardable query_range: %s", query.name),
270+
path: fmt.Sprintf(`/api/v1/query_range?start=1&end=2&step=1&query=%s`, url.QueryEscape(query.expression)),
271+
codec: shardedPrometheusCodec,
272+
isShardable: true,
273+
shardSize: 2,
274+
shardingLabels: query.shardingLabels,
266275
responses: []string{
267276
`{"status":"success","data":{"resultType":"matrix","result":[{"metric":{"__name__":"metric","__job__":"a"},"values":[[1,"1"],[2,"2"],[3,"3"]]}],"stats":{"samples":{"totalQueryableSamples":6,"totalQueryableSamplesPerStep":[[1,1],[2,2],[3,3]]}}}}`,
268277
`{"status":"success","data":{"resultType":"matrix","result":[{"metric":{"__name__":"metric","__job__":"b"},"values":[[1,"1"],[2,"2"],[3,"3"]]}],"stats":{"samples":{"totalQueryableSamples":6,"totalQueryableSamplesPerStep":[[1,1],[2,2],[3,3]]}}}}`,
@@ -273,28 +282,33 @@ http_requests_total`,
273282

274283
for _, tt := range tests {
275284
t.Run(tt.name, func(t *testing.T) {
285+
sort.Strings(tt.shardingLabels)
276286
s := httptest.NewServer(
277287
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
278288
q := r.FormValue("query")
279289
expr, _ := parser.ParseExpr(q)
280-
shardInfo := storepb.ShardInfo{}
290+
shardIndex := int64(0)
281291

282292
parser.Inspect(expr, func(n parser.Node, _ []parser.Node) error {
283293
if selector, ok := n.(*parser.VectorSelector); ok {
284294
for _, matcher := range selector.LabelMatchers {
285295
if matcher.Name == querysharding.CortexShardByLabel {
286296

287297
decoded, _ := base64.StdEncoding.DecodeString(matcher.Value)
298+
shardInfo := storepb.ShardInfo{}
288299
err := shardInfo.Unmarshal(decoded)
289300
require.NoError(t, err)
301+
sort.Strings(shardInfo.Labels)
302+
require.Equal(t, tt.shardingLabels, shardInfo.Labels)
303+
require.Equal(t, tt.isShardable, shardInfo.TotalShards > 0)
304+
shardIndex = shardInfo.ShardIndex
290305
}
291306
}
292307
}
293308
return nil
294309
})
295310

296-
require.Equal(t, tt.isShardable, shardInfo.TotalShards > 0)
297-
_, _ = w.Write([]byte(tt.responses[shardInfo.ShardIndex]))
311+
_, _ = w.Write([]byte(tt.responses[shardIndex]))
298312
}),
299313
)
300314
defer s.Close()

0 commit comments

Comments
 (0)