Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using subring on getShardedRules when shuffle sharding #4466

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
* [ENHANCEMENT] Updated Prometheus to include changes from prometheus/prometheus#9083. Now whenever `/labels` API calls include matchers, blocks store is queried for `LabelNames` with matchers instead of `Series` calls which was inefficient. #4380
* [ENHANCEMENT] Exemplars are now emitted for all gRPC calls and many operations tracked by histograms. #4462
* [ENHANCEMENT] New options `-server.http-listen-network` and `-server.grpc-listen-network` allow binding as 'tcp4' or 'tcp6'. #4462
* [ENHANCEMENT] Rulers: Using shuffle sharding subring on GetRules API. #4466
* [BUGFIX] Fixes a panic in the query-tee when comparing result. #4465
* [BUGFIX] Frontend: Fixes @ modifier functions (start/end) when splitting queries by time. #4464
* [BUGFIX] Compactor: compactor will no longer try to compact blocks that are already marked for deletion. Previously compactor would consider blocks marked for deletion within `-compactor.deletion-delay / 2` period as eligible for compaction. #4328
Expand Down
12 changes: 9 additions & 3 deletions pkg/ruler/ruler.go
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ func (r *Ruler) GetRules(ctx context.Context) ([]*GroupStateDesc, error) {
}

if r.cfg.EnableSharding {
return r.getShardedRules(ctx)
return r.getShardedRules(ctx, userID)
}

return r.getLocalRules(userID)
Expand Down Expand Up @@ -744,8 +744,14 @@ func (r *Ruler) getLocalRules(userID string) ([]*GroupStateDesc, error) {
return groupDescs, nil
}

func (r *Ruler) getShardedRules(ctx context.Context) ([]*GroupStateDesc, error) {
rulers, err := r.ring.GetReplicationSetForOperation(RingOp)
func (r *Ruler) getShardedRules(ctx context.Context, userID string) ([]*GroupStateDesc, error) {
ring := ring.ReadRing(r.ring)

if shardSize := r.limits.RulerTenantShardSize(userID); shardSize > 0 && r.cfg.ShardingStrategy == util.ShardingStrategyShuffle {
ring = r.ring.ShuffleShard(userID, shardSize)
}

rulers, err := ring.GetReplicationSetForOperation(RingOp)
if err != nil {
return nil, err
}
Expand Down
13 changes: 8 additions & 5 deletions pkg/ruler/ruler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,11 +427,14 @@ func TestGetRules(t *testing.T) {
require.NoError(t, err)
require.Equal(t, len(allRulesByUser[u]), len(rules))
if tc.sharding {
mockPoolLClient := r.clientsPool.(*mockRulerClientsPool)

// Right now we are calling all rules even with shuffle sharding
require.Equal(t, int32(len(rulerAddrMap)), mockPoolLClient.numberOfCalls.Load())
mockPoolLClient.numberOfCalls.Store(0)
mockPoolClient := r.clientsPool.(*mockRulerClientsPool)

if tc.shardingStrategy == util.ShardingStrategyShuffle {
require.Equal(t, int32(tc.shuffleShardSize), mockPoolClient.numberOfCalls.Load())
} else {
require.Equal(t, int32(len(rulerAddrMap)), mockPoolClient.numberOfCalls.Load())
}
mockPoolClient.numberOfCalls.Store(0)
}
})
}
Expand Down