MCPcopy Index your code
hub / github.com/cortexproject/cortex / isUserOwned

Method isUserOwned

pkg/ruler/ruler.go:775–807  ·  view source on GitHub ↗
(userID string)

Source from the content-addressed store, hash-verified

773}
774
775func (r *Ruler) isUserOwned(userID string) (bool, error) {
776 if !r.allowedTenants.IsAllowed(userID) {
777 return false, nil
778 }
779
780 // If sharding is disabled, any ruler instance owns all users.
781 if !r.cfg.EnableSharding {
782 return true, nil
783 }
784
785 if r.cfg.ShardingStrategy == util.ShardingStrategyShuffle {
786 shardSize := r.getShardSizeForUser(userID)
787 subRing := r.ring.ShuffleShard(userID, shardSize)
788
789 rs, err := subRing.GetAllHealthy(RingOp)
790 if err != nil {
791 r.ringCheckErrors.Inc()
792 level.Error(r.logger).Log("msg", "failed to get rulers from ring", "user", userID, "err", err)
793 return false, err
794 }
795
796 return rs.Includes(r.lifecycler.GetInstanceAddr()), nil
797 }
798
799 rulers, err := r.ring.Get(users.ShardByUser(userID), RingOp, nil, nil, nil)
800 if err != nil {
801 r.ringCheckErrors.Inc()
802 level.Error(r.logger).Log("msg", "failed to get rulers from ring", "user", userID, "err", err)
803 return false, err
804 }
805
806 return rulers.Includes(r.lifecycler.GetInstanceAddr()), nil
807}
808
809func (r *Ruler) syncRules(ctx context.Context, reason string) error {
810 level.Info(r.logger).Log("msg", "syncing rules", "reason", reason)

Callers 1

userIndexUpdateLoopMethod · 0.95

Calls 11

getShardSizeForUserMethod · 0.95
ShardByUserFunction · 0.92
IsAllowedMethod · 0.80
IncludesMethod · 0.80
GetInstanceAddrMethod · 0.80
ShuffleShardMethod · 0.65
GetAllHealthyMethod · 0.65
GetMethod · 0.65
IncMethod · 0.45
LogMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected