github.com/muhammadn/cortex@v1.9.1-0.20220510110439-46bb7000d03d/pkg/ruler/rulestore/store.go (about) 1 package rulestore 2 3 import ( 4 "context" 5 "errors" 6 7 "github.com/cortexproject/cortex/pkg/ruler/rulespb" 8 ) 9 10 var ( 11 // ErrGroupNotFound is returned if a rule group does not exist 12 ErrGroupNotFound = errors.New("group does not exist") 13 // ErrGroupNamespaceNotFound is returned if a namespace does not exist 14 ErrGroupNamespaceNotFound = errors.New("group namespace does not exist") 15 // ErrUserNotFound is returned if the user does not currently exist 16 ErrUserNotFound = errors.New("no rule groups found for user") 17 ) 18 19 // RuleStore is used to store and retrieve rules. 20 // Methods starting with "List" prefix may return partially loaded groups: with only group Name, Namespace and User fields set. 21 // To make sure that rules within each group are loaded, client must use LoadRuleGroups method. 22 type RuleStore interface { 23 // ListAllUsers returns all users with rule groups configured. 24 ListAllUsers(ctx context.Context) ([]string, error) 25 26 // ListAllRuleGroups returns all rule groups for all users. 27 ListAllRuleGroups(ctx context.Context) (map[string]rulespb.RuleGroupList, error) 28 29 // ListRuleGroupsForUserAndNamespace returns all the active rule groups for a user from given namespace. 30 // If namespace is empty, groups from all namespaces are returned. 31 ListRuleGroupsForUserAndNamespace(ctx context.Context, userID string, namespace string) (rulespb.RuleGroupList, error) 32 33 // LoadRuleGroups loads rules for each rule group in the map. 34 // Parameter with groups to load *MUST* be coming from one of the List methods. 35 // Reason is that some implementations don't do anything, since their List method already loads the rules. 36 LoadRuleGroups(ctx context.Context, groupsToLoad map[string]rulespb.RuleGroupList) error 37 38 GetRuleGroup(ctx context.Context, userID, namespace, group string) (*rulespb.RuleGroupDesc, error) 39 SetRuleGroup(ctx context.Context, userID, namespace string, group *rulespb.RuleGroupDesc) error 40 41 // DeleteRuleGroup deletes single rule group. 42 DeleteRuleGroup(ctx context.Context, userID, namespace string, group string) error 43 44 // DeleteNamespace lists rule groups for given user and namespace, and deletes all rule groups. 45 // If namespace is empty, deletes all rule groups for user. 46 DeleteNamespace(ctx context.Context, userID, namespace string) error 47 }