Skip to content

Commit 8b15216

Browse files
authored
Distributor default sharding should support default 0 value. (#5759)
* Distributor: allow 0 value in config value Signed-off-by: Ryan West <[email protected]> * Updating CHANGELOG Signed-off-by: Ryan West <[email protected]> * Removing log line, specifying shuffle sharding on validate, and moving code back to L680 Signed-off-by: Ryan West <[email protected]> * Improving the error message readability Signed-off-by: Ryan West <[email protected]> --------- Signed-off-by: Ryan West <[email protected]>
1 parent 292c423 commit 8b15216

File tree

4 files changed

+28
-6
lines changed

4 files changed

+28
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
* [BUGFIX] Distributor: Do not use label with empty values for sharding #5717
2121
* [BUGFIX] Query Frontend: queries with negative offset should check whether it is cacheable or not. #5719
2222
* [BUGFIX] Redis Cache: pass `cache_size` config correctly. #5734
23+
* [BUGFIX] Distributor: Shuffle-Sharding with IngestionTenantShardSize == 0, default sharding strategy should be used #5189
2324

2425

2526
## 1.16.0 2023-11-20

integration/ingester_sharding_test.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,28 @@ func TestIngesterSharding(t *testing.T) {
2727
tenantShardSize int
2828
expectedIngestersWithSeries int
2929
}{
30-
"default sharding strategy should spread series across all ingesters": {
30+
//Default Sharding Strategy
31+
"default sharding strategy should be ignored and spread across all ingesters": {
3132
shardingStrategy: "default",
3233
tenantShardSize: 2, // Ignored by default strategy.
3334
expectedIngestersWithSeries: 3,
3435
},
36+
"default sharding strategy should spread series across all ingesters": {
37+
shardingStrategy: "default",
38+
tenantShardSize: 0, // Ignored by default strategy.
39+
expectedIngestersWithSeries: 3,
40+
},
41+
//Shuffle Sharding Strategy
3542
"shuffle-sharding strategy should spread series across the configured shard size number of ingesters": {
3643
shardingStrategy: "shuffle-sharding",
3744
tenantShardSize: 2,
3845
expectedIngestersWithSeries: 2,
3946
},
47+
"Tenant Shard Size of 0 should leverage all ingesters": {
48+
shardingStrategy: "shuffle-sharding",
49+
tenantShardSize: 0,
50+
expectedIngestersWithSeries: 3,
51+
},
4052
}
4153

4254
for testName, testData := range tests {
@@ -125,7 +137,7 @@ func TestIngesterSharding(t *testing.T) {
125137
// We expect that only ingesters belonging to tenant's shard have been queried if
126138
// shuffle sharding is enabled.
127139
expectedIngesters := ingesters.NumInstances()
128-
if testData.shardingStrategy == "shuffle-sharding" {
140+
if testData.shardingStrategy == "shuffle-sharding" && testData.tenantShardSize > 0 {
129141
expectedIngesters = testData.tenantShardSize
130142
}
131143

pkg/distributor/distributor.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ var (
4949

5050
// Validation errors.
5151
errInvalidShardingStrategy = errors.New("invalid sharding strategy")
52-
errInvalidTenantShardSize = errors.New("invalid tenant shard size, the value must be greater than 0")
52+
errInvalidTenantShardSize = errors.New("invalid tenant shard size. The value must be greater than or equal to 0")
5353

5454
// Distributor instance limits errors.
5555
errTooManyInflightPushRequests = errors.New("too many inflight push requests in distributor")
@@ -178,7 +178,7 @@ func (cfg *Config) Validate(limits validation.Limits) error {
178178
return errInvalidShardingStrategy
179179
}
180180

181-
if cfg.ShardingStrategy == util.ShardingStrategyShuffle && limits.IngestionTenantShardSize <= 0 {
181+
if cfg.ShardingStrategy == util.ShardingStrategyShuffle && limits.IngestionTenantShardSize < 0 {
182182
return errInvalidTenantShardSize
183183
}
184184

pkg/distributor/distributor_test.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,14 @@ func TestConfig_Validate(t *testing.T) {
7676
initLimits: func(_ *validation.Limits) {},
7777
expected: errInvalidShardingStrategy,
7878
},
79-
"should fail if the default shard size is 0 on when sharding strategy = shuffle-sharding": {
79+
"should pass sharding strategy when IngestionTenantShardSize = 0": {
8080
initConfig: func(cfg *Config) {
8181
cfg.ShardingStrategy = "shuffle-sharding"
8282
},
8383
initLimits: func(limits *validation.Limits) {
8484
limits.IngestionTenantShardSize = 0
8585
},
86-
expected: errInvalidTenantShardSize,
86+
expected: nil,
8787
},
8888
"should pass if the default shard size > 0 on when sharding strategy = shuffle-sharding": {
8989
initConfig: func(cfg *Config) {
@@ -94,6 +94,15 @@ func TestConfig_Validate(t *testing.T) {
9494
},
9595
expected: nil,
9696
},
97+
"should fail because the ingestionTenantShardSize is a non-positive number": {
98+
initConfig: func(cfg *Config) {
99+
cfg.ShardingStrategy = "shuffle-sharding"
100+
},
101+
initLimits: func(limits *validation.Limits) {
102+
limits.IngestionTenantShardSize = -1
103+
},
104+
expected: errInvalidTenantShardSize,
105+
},
97106
}
98107

99108
for testName, testData := range tests {

0 commit comments

Comments
 (0)