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

Method listRules

pkg/ruler/ruler.go:866–899  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

864}
865
866func (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
901func (r *Ruler) listRulesNoSharding(ctx context.Context) (map[string]rulespb.RuleGroupList, map[string]rulespb.RuleGroupList, error) {
902 allRuleGroups, err := r.store.ListAllRuleGroups(ctx)

Callers 5

loadRuleGroupsMethod · 0.95
TestGetRulesFunction · 0.80
TestShardingFunction · 0.80
Test_LoadPartialGroupsFunction · 0.80

Calls 5

listRulesNoShardingMethod · 0.95
IsAllowedMethod · 0.80
LogMethod · 0.45

Tested by 4

TestGetRulesFunction · 0.64
TestShardingFunction · 0.64
Test_LoadPartialGroupsFunction · 0.64