| 864 | } |
| 865 | |
| 866 | func (r *Ruler) listRules(ctx context.Context) (owned map[string]rulespb.RuleGroupList, backedUp map[string]rulespb.RuleGroupList, err error) { |
| 867 | switch { |
| 868 | case !r.cfg.EnableSharding: |
| 869 | owned, backedUp, err = r.listRulesNoSharding(ctx) |
| 870 | |
| 871 | case r.cfg.ShardingStrategy == util.ShardingStrategyDefault: |
| 872 | owned, backedUp, err = r.listRulesShardingDefault(ctx) |
| 873 | |
| 874 | case r.cfg.ShardingStrategy == util.ShardingStrategyShuffle: |
| 875 | owned, backedUp, err = r.listRulesShuffleSharding(ctx) |
| 876 | |
| 877 | default: |
| 878 | return nil, nil, errors.New("invalid sharding configuration") |
| 879 | } |
| 880 | |
| 881 | if err != nil { |
| 882 | return |
| 883 | } |
| 884 | |
| 885 | for userID := range owned { |
| 886 | if !r.allowedTenants.IsAllowed(userID) { |
| 887 | level.Debug(r.logger).Log("msg", "ignoring rule groups for user, not allowed", "user", userID) |
| 888 | delete(owned, userID) |
| 889 | } |
| 890 | } |
| 891 | |
| 892 | for userID := range backedUp { |
| 893 | if !r.allowedTenants.IsAllowed(userID) { |
| 894 | level.Debug(r.logger).Log("msg", "ignoring rule groups for user, not allowed", "user", userID) |
| 895 | delete(backedUp, userID) |
| 896 | } |
| 897 | } |
| 898 | return |
| 899 | } |
| 900 | |
| 901 | func (r *Ruler) listRulesNoSharding(ctx context.Context) (map[string]rulespb.RuleGroupList, map[string]rulespb.RuleGroupList, error) { |
| 902 | allRuleGroups, err := r.store.ListAllRuleGroups(ctx) |