Skip to content

Commit a118689

Browse files
authored
update thanos to bring sharding support for label manipulation functions (#4966)
Signed-off-by: Ben Ye <[email protected]> Signed-off-by: Ben Ye <[email protected]>
1 parent 8c29372 commit a118689

File tree

6 files changed

+115
-33
lines changed

6 files changed

+115
-33
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ require (
4848
github.com/spf13/afero v1.6.0
4949
github.com/stretchr/testify v1.8.0
5050
github.com/thanos-io/objstore v0.0.0-20221006135717-79dcec7fe604
51-
github.com/thanos-io/thanos v0.29.1-0.20221111094505-b2badad930d6
51+
github.com/thanos-io/thanos v0.29.1-0.20221115064008-fe45cfc66b7d
5252
github.com/uber/jaeger-client-go v2.30.0+incompatible
5353
github.com/weaveworks/common v0.0.0-20220706100410-67d27ed40fae
5454
go.etcd.io/etcd/api/v3 v3.5.4

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -927,8 +927,8 @@ github.com/thanos-community/galaxycache v0.0.0-20211122094458-3a32041a1f1e h1:f1
927927
github.com/thanos-community/galaxycache v0.0.0-20211122094458-3a32041a1f1e/go.mod h1:jXcofnrSln/cLI6/dhlBxPQZEEQHVPCcFaH75M+nSzM=
928928
github.com/thanos-io/objstore v0.0.0-20221006135717-79dcec7fe604 h1:9dceDSKKsLWNHjrMpyzK1t7eVcAZv9Dp3FX+uokUS2Y=
929929
github.com/thanos-io/objstore v0.0.0-20221006135717-79dcec7fe604/go.mod h1:Vx5dZs9ElxEhNLnum/OgB0pNTqNdI2zdXL82BeJr3T4=
930-
github.com/thanos-io/thanos v0.29.1-0.20221111094505-b2badad930d6 h1:8q0LB3XOhscrqEYU0g5+ekB1ZHERk8tUl1l/y9DbeXA=
931-
github.com/thanos-io/thanos v0.29.1-0.20221111094505-b2badad930d6/go.mod h1:odqdxSO+o/UaVgNpdkYYaQUW/JpT7LByXyZmxoe6uoc=
930+
github.com/thanos-io/thanos v0.29.1-0.20221115064008-fe45cfc66b7d h1:cfGwZH4LBrkFbQHea7HUlNDOQhILGBRPxDWjy4FhAME=
931+
github.com/thanos-io/thanos v0.29.1-0.20221115064008-fe45cfc66b7d/go.mod h1:odqdxSO+o/UaVgNpdkYYaQUW/JpT7LByXyZmxoe6uoc=
932932
github.com/themihai/gomemcache v0.0.0-20180902122335-24332e2d58ab h1:7ZR3hmisBWw77ZpO1/o86g+JV3VKlk3d48jopJxzTjU=
933933
github.com/themihai/gomemcache v0.0.0-20180902122335-24332e2d58ab/go.mod h1:eheTFp954zcWZXCU8d0AT76ftsQOTo4DTqkN/h3k1MY=
934934
github.com/tidwall/pretty v0.0.0-20180105212114-65a9db5fad51/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=

pkg/querier/tripperware/test_shard_by_query_utils.go

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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) (
197231
http_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 {

vendor/github.com/thanos-io/thanos/pkg/cacheutil/redis_client.go

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/thanos-io/thanos/pkg/querysharding/analyzer.go

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

vendor/modules.txt

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)