@@ -856,12 +856,17 @@ func (r *Ruler) listRulesShuffleSharding(ctx context.Context) (map[string]rulesp
856
856
// Only users in userRings will be used in the to load the rules.
857
857
userRings := map [string ]ring.ReadRing {}
858
858
for _ , u := range users {
859
- shardSize := r .getShardSizeForUser (u )
860
- subRing := r .ring .ShuffleShard (u , shardSize )
859
+ if shardSize := r .limits . RulerTenantShardSize (u ); shardSize > 0 {
860
+ subRing := r .ring .ShuffleShard (u , r . getShardSizeForUser ( u ) )
861
861
862
- // Include the user only if it belongs to this ruler shard.
863
- if subRing .HasInstance (r .lifecycler .GetInstanceID ()) {
864
- userRings [u ] = subRing
862
+ // Include the user only if it belongs to this ruler shard.
863
+ if subRing .HasInstance (r .lifecycler .GetInstanceID ()) {
864
+ userRings [u ] = subRing
865
+ }
866
+ } else {
867
+ // A shard size of 0 means shuffle sharding is disabled for this specific user.
868
+ // In that case we use the full ring so that rule groups will be sharded across all rulers.
869
+ userRings [u ] = r .ring
865
870
}
866
871
}
867
872
@@ -1321,27 +1326,18 @@ func (r *Ruler) ruleGroupListToGroupStateDesc(userID string, backupGroups rulesp
1321
1326
}
1322
1327
1323
1328
func (r * Ruler ) getShardSizeForUser (userID string ) int {
1324
- var newShardSize int
1325
- numInstances := r .ring .InstancesCount ()
1326
1329
rulerTenantShardSize := r .limits .RulerTenantShardSize (userID )
1330
+ newShardSize := util .DynamicShardSize (rulerTenantShardSize , r .ring .InstancesCount ())
1327
1331
1328
- if rulerTenantShardSize == 0 {
1329
- // A shard size of 0 means shuffle sharding is disabled for this specific user.
1330
- // In that case we use the full ring so that rule groups will be sharded across all rulers.
1331
- return numInstances
1332
- }
1333
-
1334
- newShardSize = util .DynamicShardSize (rulerTenantShardSize , numInstances )
1335
1332
// We want to guarantee that shard size will be at replication factor
1336
1333
return max (newShardSize , r .cfg .Ring .ReplicationFactor )
1337
1334
}
1338
1335
1339
1336
func (r * Ruler ) getShardedRules (ctx context.Context , userID string , rulesRequest RulesRequest ) (* RulesResponse , error ) {
1340
1337
ring := ring .ReadRing (r .ring )
1341
1338
1342
- if r .cfg .ShardingStrategy == util .ShardingStrategyShuffle {
1343
- shardSize := r .getShardSizeForUser (userID )
1344
- ring = r .ring .ShuffleShard (userID , shardSize )
1339
+ if shardSize := r .limits .RulerTenantShardSize (userID ); shardSize > 0 && r .cfg .ShardingStrategy == util .ShardingStrategyShuffle {
1340
+ ring = r .ring .ShuffleShard (userID , r .getShardSizeForUser (userID ))
1345
1341
}
1346
1342
1347
1343
rulers , failedZones , err := GetReplicationSetForListRule (ring , & r .cfg .Ring )
0 commit comments