Skip to content

Commit 77583b3

Browse files
committed
Addressing PR comments
Signed-off-by: Wilbert Guo <[email protected]>
1 parent d5252ce commit 77583b3

File tree

2 files changed

+13
-25
lines changed

2 files changed

+13
-25
lines changed

pkg/ruler/ruler.go

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -856,12 +856,17 @@ func (r *Ruler) listRulesShuffleSharding(ctx context.Context) (map[string]rulesp
856856
// Only users in userRings will be used in the to load the rules.
857857
userRings := map[string]ring.ReadRing{}
858858
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))
861861

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
865870
}
866871
}
867872

@@ -1321,27 +1326,18 @@ func (r *Ruler) ruleGroupListToGroupStateDesc(userID string, backupGroups rulesp
13211326
}
13221327

13231328
func (r *Ruler) getShardSizeForUser(userID string) int {
1324-
var newShardSize int
1325-
numInstances := r.ring.InstancesCount()
13261329
rulerTenantShardSize := r.limits.RulerTenantShardSize(userID)
1330+
newShardSize := util.DynamicShardSize(rulerTenantShardSize, r.ring.InstancesCount())
13271331

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)
13351332
// We want to guarantee that shard size will be at replication factor
13361333
return max(newShardSize, r.cfg.Ring.ReplicationFactor)
13371334
}
13381335

13391336
func (r *Ruler) getShardedRules(ctx context.Context, userID string, rulesRequest RulesRequest) (*RulesResponse, error) {
13401337
ring := ring.ReadRing(r.ring)
13411338

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))
13451341
}
13461342

13471343
rulers, failedZones, err := GetReplicationSetForListRule(ring, &r.cfg.Ring)

pkg/ruler/ruler_test.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3146,14 +3146,6 @@ func TestGetShardSizeForUser(t *testing.T) {
31463146
tenantShardSize: 0.25,
31473147
expectedShardSize: 20,
31483148
},
3149-
{
3150-
name: "User with default 0 shard size",
3151-
userID: "user1",
3152-
rulerInstanceCount: 10,
3153-
replicationFactor: 1,
3154-
tenantShardSize: 0,
3155-
expectedShardSize: 10,
3156-
},
31573149
{
31583150
name: "Ensure shard size is at least replication factor",
31593151
userID: "user1",

0 commit comments

Comments
 (0)