Skip to content

Commit 1d40924

Browse files
authored
enable vertical sharding on binary expr (cortexproject#5507)
Signed-off-by: Ben Ye <[email protected]>
1 parent 734cf0b commit 1d40924

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+3824
-1396
lines changed

go.mod

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ require (
5151
github.com/sony/gobreaker v0.5.0
5252
github.com/spf13/afero v1.9.5
5353
github.com/stretchr/testify v1.8.4
54-
github.com/thanos-io/objstore v0.0.0-20230721074820-89475d4508df
55-
github.com/thanos-io/promql-engine v0.0.0-20230526105742-791d78b260ea
56-
github.com/thanos-io/thanos v0.31.1-0.20230809185825-46339760e526
54+
github.com/thanos-io/objstore v0.0.0-20230804084840-c042a6a16c58
55+
github.com/thanos-io/promql-engine v0.0.0-20230816062837-c64fc7b373db
56+
github.com/thanos-io/thanos v0.0.0-20230816172224-2b4f2a7061f9
5757
github.com/uber/jaeger-client-go v2.30.0+incompatible
5858
github.com/weaveworks/common v0.0.0-20221201103051-7c2720a9024d
5959
go.etcd.io/etcd/api/v3 v3.5.9
@@ -117,6 +117,7 @@ require (
117117
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
118118
github.com/davecgh/go-spew v1.1.1 // indirect
119119
github.com/dennwc/varint v1.0.0 // indirect
120+
github.com/dgryski/go-metro v0.0.0-20200812162917-85c65e2d0165 // indirect
120121
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
121122
github.com/docker/go-units v0.5.0 // indirect
122123
github.com/edsrzf/mmap-go v1.1.0 // indirect
@@ -187,6 +188,7 @@ require (
187188
github.com/rs/cors v1.9.0 // indirect
188189
github.com/rs/xid v1.5.0 // indirect
189190
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 // indirect
191+
github.com/seiflotfy/cuckoofilter v0.0.0-20220411075957-e3b120b3f5fb // indirect
190192
github.com/sercand/kuberesolver v2.4.0+incompatible // indirect
191193
github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749 // indirect
192194
github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546 // indirect
@@ -209,8 +211,8 @@ require (
209211
go.uber.org/goleak v1.2.1 // indirect
210212
go.uber.org/multierr v1.9.0 // indirect
211213
go.uber.org/zap v1.21.0 // indirect
212-
go4.org/intern v0.0.0-20230205224052-192e9f60865c // indirect
213-
go4.org/unsafe/assume-no-moving-gc v0.0.0-20230221090011-e4bae7ad2296 // indirect
214+
go4.org/intern v0.0.0-20230525184215-6c62f75575cb // indirect
215+
go4.org/unsafe/assume-no-moving-gc v0.0.0-20230525183740-e7c30c78aeb2 // indirect
214216
golang.org/x/crypto v0.11.0 // indirect
215217
golang.org/x/exp v0.0.0-20230321023759-10a507213a29 // indirect
216218
golang.org/x/mod v0.10.0 // indirect

go.sum

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
549549
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
550550
github.com/dennwc/varint v1.0.0 h1:kGNFFSSw8ToIy3obO/kKr8U9GZYUAxQEVuix4zfDWzE=
551551
github.com/dennwc/varint v1.0.0/go.mod h1:hnItb35rvZvJrbTALZtY/iQfDs48JKRG1RPpgziApxA=
552+
github.com/dgryski/go-metro v0.0.0-20200812162917-85c65e2d0165 h1:BS21ZUJ/B5X2UVUbczfmdWH7GapPWAhxcMsDnjJTU1E=
553+
github.com/dgryski/go-metro v0.0.0-20200812162917-85c65e2d0165/go.mod h1:c9O8+fpSOX1DM8cPNSkX/qsBWdkD4yd2dpciOWQjpBw=
552554
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
553555
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
554556
github.com/dhui/dktest v0.3.16 h1:i6gq2YQEtcrjKbeJpBkWjE8MmLZPYllcjOFbTZuPDnw=
@@ -1066,7 +1068,7 @@ github.com/opentracing-contrib/go-stdlib v1.0.0/go.mod h1:qtI1ogk+2JhVPIXVc6q+NH
10661068
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
10671069
github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs=
10681070
github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc=
1069-
github.com/oracle/oci-go-sdk/v65 v65.13.0 h1:0+9ea5goYfhI3/MPfbIQU6yzHYWE6sCk6VuUepxk5Nk=
1071+
github.com/oracle/oci-go-sdk/v65 v65.41.1 h1:+lbosOyNiib3TGJDvLq1HwEAuFqkOjPJDIkyxM15WdQ=
10701072
github.com/ovh/go-ovh v1.4.1 h1:VBGa5wMyQtTP7Zb+w97zRCh9sLtM/2YKRyy+MEJmWaM=
10711073
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
10721074
github.com/pascaldekloe/goe v0.1.0 h1:cBOtyMzM9HTpWjXfbbunk26uA6nG3a8n06Wieeh0MwY=
@@ -1150,6 +1152,8 @@ github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 h1:nn5Wsu0esKSJiIVhscUt
11501152
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
11511153
github.com/segmentio/fasthash v1.0.3 h1:EI9+KE1EwvMLBWwjpRDc+fEM+prwxDYbslddQGtrmhM=
11521154
github.com/segmentio/fasthash v1.0.3/go.mod h1:waKX8l2N8yckOgmSsXJi7x1ZfdKZ4x7KRMzBtS3oedY=
1155+
github.com/seiflotfy/cuckoofilter v0.0.0-20220411075957-e3b120b3f5fb h1:XfLJSPIOUX+osiMraVgIrMR27uMXnRJWGm1+GL8/63U=
1156+
github.com/seiflotfy/cuckoofilter v0.0.0-20220411075957-e3b120b3f5fb/go.mod h1:bR6DqgcAl1zTcOX8/pE2Qkj9XO00eCNqmKb7lXP8EAg=
11531157
github.com/sercand/kuberesolver/v4 v4.0.0 h1:frL7laPDG/lFm5n98ODmWnn+cvPpzlkf3LhzuPhcHP4=
11541158
github.com/sercand/kuberesolver/v4 v4.0.0/go.mod h1:F4RGyuRmMAjeXHKL+w4P7AwUnPceEAPAhxUgXZjKgvM=
11551159
github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749 h1:bUGsEnyNbVPw06Bs80sCeARAlK8lhwqGyi6UT8ymuGk=
@@ -1202,12 +1206,12 @@ github.com/subosito/gotenv v1.4.1/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNG
12021206
github.com/tencentyun/cos-go-sdk-v5 v0.7.40 h1:W6vDGKCHe4wBACI1d2UgE6+50sJFhRWU4O8IB2ozzxM=
12031207
github.com/thanos-community/galaxycache v0.0.0-20211122094458-3a32041a1f1e h1:f1Zsv7OAU9iQhZwigp50Yl38W10g/vd5NC8Rdk1Jzng=
12041208
github.com/thanos-community/galaxycache v0.0.0-20211122094458-3a32041a1f1e/go.mod h1:jXcofnrSln/cLI6/dhlBxPQZEEQHVPCcFaH75M+nSzM=
1205-
github.com/thanos-io/objstore v0.0.0-20230721074820-89475d4508df h1:QEQsto338hS1gvB904Pr6gE0RRM7kIcvIu2YF8Dsqks=
1206-
github.com/thanos-io/objstore v0.0.0-20230721074820-89475d4508df/go.mod h1:IS7Z25+0KaknyU2P5PTP/5hwY6Yr/FzbInF88Yd5auU=
1207-
github.com/thanos-io/promql-engine v0.0.0-20230526105742-791d78b260ea h1:kzK8sBn2+mo3NAxP+XjAjAqr1hwfxxFUy5CybaBkjAI=
1208-
github.com/thanos-io/promql-engine v0.0.0-20230526105742-791d78b260ea/go.mod h1:eIgPaXWgOhNAv6CPPrgu09r0AtT7byBTZy+7WkX0D18=
1209-
github.com/thanos-io/thanos v0.31.1-0.20230809185825-46339760e526 h1:QpAdI+mFTgZ1UUviL7Wzxi+h45LZEoxErHQHdYFb+Z4=
1210-
github.com/thanos-io/thanos v0.31.1-0.20230809185825-46339760e526/go.mod h1:4MiWDaeClW8CSHiOR57bnuUOID3HDYQphMthOPwtpJY=
1209+
github.com/thanos-io/objstore v0.0.0-20230804084840-c042a6a16c58 h1:4cDXsvm3mb1NvW1B1qJ9/fy6h+OOYit0h8oVA957hLM=
1210+
github.com/thanos-io/objstore v0.0.0-20230804084840-c042a6a16c58/go.mod h1:oJ82xgcBDzGJrEgUsjlTj6n01+ZWUMMUR8BlZzX5xDE=
1211+
github.com/thanos-io/promql-engine v0.0.0-20230816062837-c64fc7b373db h1:05Tp4pfeTTJlRnwLtgvXCJvKYeZCRBoxwDFC+uYqGyM=
1212+
github.com/thanos-io/promql-engine v0.0.0-20230816062837-c64fc7b373db/go.mod h1:eIgPaXWgOhNAv6CPPrgu09r0AtT7byBTZy+7WkX0D18=
1213+
github.com/thanos-io/thanos v0.0.0-20230816172224-2b4f2a7061f9 h1:KuVECxBG1Q8WoYWlY8dk1wi3OtPSSxv+tWPV9S9qGFk=
1214+
github.com/thanos-io/thanos v0.0.0-20230816172224-2b4f2a7061f9/go.mod h1:zfpzKCtqaqCy1D9/6ksZfL+U+KKt8mkcX6v3btuDHgg=
12111215
github.com/themihai/gomemcache v0.0.0-20180902122335-24332e2d58ab h1:7ZR3hmisBWw77ZpO1/o86g+JV3VKlk3d48jopJxzTjU=
12121216
github.com/themihai/gomemcache v0.0.0-20180902122335-24332e2d58ab/go.mod h1:eheTFp954zcWZXCU8d0AT76ftsQOTo4DTqkN/h3k1MY=
12131217
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
@@ -1312,11 +1316,10 @@ go.uber.org/zap v1.17.0/go.mod h1:MXVU+bhUf/A7Xi2HNOnopQOrmycQ5Ih87HtOu4q5SSo=
13121316
go.uber.org/zap v1.18.1/go.mod h1:xg/QME4nWcxGxrpdeYfq7UvYrLh66cuVKdrbD1XF/NI=
13131317
go.uber.org/zap v1.21.0 h1:WefMeulhovoZ2sYXz7st6K0sLj7bBhpiFaud4r4zST8=
13141318
go.uber.org/zap v1.21.0/go.mod h1:wjWOCqI0f2ZZrJF/UufIOkiC8ii6tm1iqIsLo76RfJw=
1315-
go4.org/intern v0.0.0-20230205224052-192e9f60865c h1:b8WZ7Ja8nKegYxfwDLLwT00ZKv4lXAQrw8LYPK+cHSI=
1316-
go4.org/intern v0.0.0-20230205224052-192e9f60865c/go.mod h1:RJ0SVrOMpxLhgb5noIV+09zI1RsRlMsbUcSxpWHqbrE=
1317-
go4.org/unsafe/assume-no-moving-gc v0.0.0-20230204201903-c31fa085b70e/go.mod h1:FftLjUGFEDu5k8lt0ddY+HcrH/qU/0qk+H8j9/nTl3E=
1318-
go4.org/unsafe/assume-no-moving-gc v0.0.0-20230221090011-e4bae7ad2296 h1:QJ/xcIANMLApehfgPCHnfK1hZiaMmbaTVmPv7DAoTbo=
1319-
go4.org/unsafe/assume-no-moving-gc v0.0.0-20230221090011-e4bae7ad2296/go.mod h1:FftLjUGFEDu5k8lt0ddY+HcrH/qU/0qk+H8j9/nTl3E=
1319+
go4.org/intern v0.0.0-20230525184215-6c62f75575cb h1:ae7kzL5Cfdmcecbh22ll7lYP3iuUdnfnhiPcSaDgH/8=
1320+
go4.org/intern v0.0.0-20230525184215-6c62f75575cb/go.mod h1:Ycrt6raEcnF5FTsLiLKkhBTO6DPX3RCUCUVnks3gFJU=
1321+
go4.org/unsafe/assume-no-moving-gc v0.0.0-20230525183740-e7c30c78aeb2 h1:WJhcL4p+YeDxmZWg141nRm7XC8IDmhz7lk5GpadO1Sg=
1322+
go4.org/unsafe/assume-no-moving-gc v0.0.0-20230525183740-e7c30c78aeb2/go.mod h1:FftLjUGFEDu5k8lt0ddY+HcrH/qU/0qk+H8j9/nTl3E=
13201323
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
13211324
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
13221325
golang.org/x/crypto v0.0.0-20190422162423-af44ce270edf/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE=

pkg/querier/tripperware/test_shard_by_query_utils.go

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,6 @@ func TestQueryShardQuery(t *testing.T, instantQueryCodec Codec, shardedPrometheu
4545
name: "outer aggregation with without grouping",
4646
expression: "count(sum without (pod) (http_requests_total))",
4747
},
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-
},
6048
{
6149
name: "binary expression with constant",
6250
expression: `http_requests_total{code="400"} / 4`,
@@ -69,10 +57,6 @@ func TestQueryShardQuery(t *testing.T, instantQueryCodec Codec, shardedPrometheu
6957
name: "binary aggregation with different grouping labels",
7058
expression: `sum by (pod) (http_requests_total{code="400"}) / sum by (cluster) (http_requests_total)`,
7159
},
72-
{
73-
name: "multiple binary expressions",
74-
expression: `(http_requests_total{code="400"} + http_requests_total{code="500"}) / http_requests_total`,
75-
},
7660
{
7761
name: "multiple binary expressions with empty vector matchers",
7862
expression: `
@@ -193,6 +177,11 @@ sum by (container) (
193177
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))`,
194178
shardingLabels: []string{"namespace", "cluster_id"},
195179
},
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+
},
196185
}
197186

198187
// Shardable by labels instant queries with matrix response
@@ -233,7 +222,7 @@ sum by (container) (
233222
{
234223
name: "binary expression with outer without grouping",
235224
expression: `sum(http_requests_total{code="400"} * http_requests_total) without (pod)`,
236-
shardingLabels: []string{"pod"},
225+
shardingLabels: []string{model.MetricNameLabel, "pod"},
237226
},
238227
{
239228
name: "binary expression with vector matching and outer without grouping",
@@ -268,6 +257,26 @@ http_requests_total`,
268257
expression: `sum without (pod) (label_replace(metric, "dst_label", "$1", "src_label", "re"))`,
269258
shardingLabels: []string{"pod", "dst_label"},
270259
},
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+
},
271280
}
272281

273282
type testCase struct {
@@ -324,6 +333,7 @@ http_requests_total`,
324333
name: fmt.Sprintf("non shardable query: %s", query.name),
325334
path: fmt.Sprintf(`/api/v1/query?time=120&query=%s`, url.QueryEscape(query.expression)),
326335
codec: instantQueryCodec,
336+
shardSize: 2,
327337
isShardable: false,
328338
responses: []string{
329339
`{"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`,
334344
name: fmt.Sprintf("non shardable query_range: %s", query.name),
335345
path: fmt.Sprintf(`/api/v1/query_range?start=1&end=2&step=1&query=%s`, url.QueryEscape(query.expression)),
336346
codec: shardedPrometheusCodec,
347+
shardSize: 2,
337348
isShardable: false,
338349
responses: []string{
339350
`{"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]]}}}}`,

vendor/github.com/dgryski/go-metro/LICENSE

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/dgryski/go-metro/README

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)