Skip to content

Commit d5252ce

Browse files
committed
Remove default shardsize value
Signed-off-by: Wilbert Guo <[email protected]>
1 parent 8874ecf commit d5252ce

File tree

2 files changed

+15
-27
lines changed

2 files changed

+15
-27
lines changed

pkg/ruler/ruler.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,6 @@ const (
8989
// query response formats
9090
queryResponseFormatJson = "json"
9191
queryResponseFormatProtobuf = "protobuf"
92-
93-
defaultRulerShardSizePercentage = 0.4
9492
)
9593

9694
type DisabledRuleGroupErr struct {
@@ -1331,14 +1329,11 @@ func (r *Ruler) getShardSizeForUser(userID string) int {
13311329
// A shard size of 0 means shuffle sharding is disabled for this specific user.
13321330
// In that case we use the full ring so that rule groups will be sharded across all rulers.
13331331
return numInstances
1334-
} else if rulerTenantShardSize > 0 {
1335-
newShardSize = util.DynamicShardSize(rulerTenantShardSize, numInstances)
1336-
} else {
1337-
newShardSize = util.DynamicShardSize(defaultRulerShardSizePercentage, numInstances)
13381332
}
13391333

1340-
// We want to guarantee that shard size will be at least 1
1341-
return max(newShardSize, 1)
1334+
newShardSize = util.DynamicShardSize(rulerTenantShardSize, numInstances)
1335+
// We want to guarantee that shard size will be at replication factor
1336+
return max(newShardSize, r.cfg.Ring.ReplicationFactor)
13421337
}
13431338

13441339
func (r *Ruler) getShardedRules(ctx context.Context, userID string, rulesRequest RulesRequest) (*RulesResponse, error) {

pkg/ruler/ruler_test.go

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3108,66 +3108,59 @@ func TestRuler_QueryOffset(t *testing.T) {
31083108
func TestGetShardSizeForUser(t *testing.T) {
31093109
tests := []struct {
31103110
name string
3111-
tenantShardSize float64
31123111
userID string
3112+
replicationFactor int
31133113
rulerInstanceCount int
3114+
tenantShardSize float64
31143115
expectedShardSize int
31153116
}{
31163117
{
31173118
name: "User with fixed shard size with 10 ruler instances",
31183119
userID: "user1",
31193120
rulerInstanceCount: 10,
3121+
replicationFactor: 1,
31203122
tenantShardSize: 2,
31213123
expectedShardSize: 2,
31223124
},
31233125
{
31243126
name: "User with fixed shard size with 50 ruler instances",
31253127
userID: "user1",
31263128
rulerInstanceCount: 50,
3129+
replicationFactor: 1,
31273130
tenantShardSize: 30,
31283131
expectedShardSize: 30,
31293132
},
31303133
{
31313134
name: "User with percentage shard size with 10 ruler instances",
31323135
userID: "user1",
31333136
rulerInstanceCount: 10,
3137+
replicationFactor: 1,
31343138
tenantShardSize: 0.6,
31353139
expectedShardSize: 6,
31363140
},
31373141
{
31383142
name: "User with percentage shard size with 80 ruler instances",
31393143
userID: "user1",
31403144
rulerInstanceCount: 80,
3145+
replicationFactor: 1,
31413146
tenantShardSize: 0.25,
31423147
expectedShardSize: 20,
31433148
},
3144-
{
3145-
name: "User with invalid negative shard size",
3146-
userID: "user1",
3147-
rulerInstanceCount: 10,
3148-
tenantShardSize: -1,
3149-
expectedShardSize: 4,
3150-
},
31513149
{
31523150
name: "User with default 0 shard size",
31533151
userID: "user1",
31543152
rulerInstanceCount: 10,
3153+
replicationFactor: 1,
31553154
tenantShardSize: 0,
31563155
expectedShardSize: 10,
31573156
},
31583157
{
3159-
name: "User with greater shard size than number of ruler instances",
3158+
name: "Ensure shard size is at least replication factor",
31603159
userID: "user1",
31613160
rulerInstanceCount: 10,
3162-
tenantShardSize: 15,
3163-
expectedShardSize: 15,
3164-
},
3165-
{
3166-
name: "Ensure smallest shard size will be 1",
3167-
userID: "user1",
3168-
rulerInstanceCount: 1,
3169-
tenantShardSize: 0.5,
3170-
expectedShardSize: 1,
3161+
replicationFactor: 3,
3162+
tenantShardSize: 0.1,
3163+
expectedShardSize: 3,
31713164
},
31723165
}
31733166

@@ -3206,7 +3199,7 @@ func TestGetShardSizeForUser(t *testing.T) {
32063199
KVStore: kv.Config{
32073200
Mock: kvStore,
32083201
},
3209-
ReplicationFactor: 1,
3202+
ReplicationFactor: tc.replicationFactor,
32103203
ZoneAwarenessEnabled: true,
32113204
InstanceZone: rulerAZEvenSpread[id],
32123205
}

0 commit comments

Comments
 (0)