rulestore

package
v0.0.0-...-9d732f8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 19, 2024 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BackendLocal = "local"
)

Variables

View Source
var (
	// ErrGroupNotFound is returned if a rule group does not exist
	ErrGroupNotFound = errors.New("group does not exist")
	// ErrGroupNamespaceNotFound is returned if a namespace does not exist
	ErrGroupNamespaceNotFound = errors.New("group namespace does not exist")
	// ErrUserNotFound is returned if the user does not currently exist
	ErrUserNotFound = errors.New("no rule groups found for user")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	bucket.Config `yaml:",inline"`
	Local         LocalStoreConfig `yaml:"local"`

	// RulerCache holds the configuration used for the ruler storage cache.
	RulerCache RulerCacheConfig `yaml:"cache"`
}

Config configures a rule store.

func (*Config) IsDefaults

func (cfg *Config) IsDefaults() bool

IsDefaults returns true if the storage options have not been set.

func (*Config) RegisterFlags

func (cfg *Config) RegisterFlags(f *flag.FlagSet)

RegisterFlags registers the backend storage config.

func (*Config) Validate

func (cfg *Config) Validate() error

type LocalStoreConfig

type LocalStoreConfig struct {
	Directory string `yaml:"directory"`
}

func (*LocalStoreConfig) RegisterFlagsWithPrefix

func (cfg *LocalStoreConfig) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet)

RegisterFlagsWithPrefix registers flags with the input prefix.

type Option

type Option func(opts *Options)

Option is a callback the modifies per-call options for RuleStore methods.

func WithCacheDisabled

func WithCacheDisabled() Option

WithCacheDisabled returns an Option callback to disable any caching used by a RuleStore method call.

type Options

type Options struct {
	DisableCache bool
}

Options are per-call options that can be used to modify the behavior of RuleStore methods.

func CollectOptions

func CollectOptions(opts ...Option) *Options

CollectOptions applies one or more Option callbacks to produce an Options struct.

type RuleStore

type RuleStore interface {
	// ListAllUsers returns all users with rule groups configured.
	ListAllUsers(ctx context.Context, opts ...Option) ([]string, error)

	// ListRuleGroupsForUserAndNamespace returns all the active rule groups for a user from given namespace.
	// It *MUST* populate fields User, Namespace, Name of all rule groups.
	// It *MAY* populate the actual rules.
	// If namespace is empty, groups from all namespaces are returned.
	ListRuleGroupsForUserAndNamespace(ctx context.Context, userID string, namespace string, opts ...Option) (rulespb.RuleGroupList, error)

	// LoadRuleGroups loads rules for each rule group in the map.
	//
	// Requirements:
	// - The groupsToLoad parameter  *MUST* be coming from one of the List methods.
	//   The groupsToLoad map can be filtered for sharding purposes before calling
	//   LoadRuleGroups.
	//
	// Specifications:
	// - LoadRuleGroups() *MUST* populate the rules if the List methods have
	//   not populated the rule groups with their actual rules.
	// - If, and only if, a rule group can't be loaded because missing in the storage
	//   then LoadRuleGroups() *MUST* not return error but return the missing rule groups.
	//   This means that missing list *MUST* contain only rule groups that don't exist
	//   in the storage, and not that we failed loading for other reasons.
	LoadRuleGroups(ctx context.Context, groupsToLoad map[string]rulespb.RuleGroupList) (missing rulespb.RuleGroupList, err error)

	GetRuleGroup(ctx context.Context, userID, namespace, group string) (*rulespb.RuleGroupDesc, error)
	SetRuleGroup(ctx context.Context, userID, namespace string, group *rulespb.RuleGroupDesc) error

	// DeleteRuleGroup deletes single rule group.
	DeleteRuleGroup(ctx context.Context, userID, namespace string, group string) error

	// DeleteNamespace lists rule groups for given user and namespace, and deletes all rule groups.
	// If namespace is empty, deletes all rule groups for user.
	DeleteNamespace(ctx context.Context, userID, namespace string) error
}

RuleStore is used to store and retrieve rules. Methods starting with "List" prefix may return partially loaded groups: with only group Name, Namespace and User fields set. To make sure that rules within each group are loaded, client must use LoadRuleGroups method.

type RulerCacheConfig

type RulerCacheConfig struct {
	// RuleGroupEnabled enables caching of rule group contents
	RuleGroupEnabled bool `yaml:"rule_group_enabled" category:"experimental"`

	// Cache holds the configuration used for the ruler storage cache.
	Cache cache.BackendConfig `yaml:",inline"`
}

RulerCacheConfig is configuration for the cache used by ruler storage as well as additional ruler storage specific configuration.

NOTE: This is temporary while caching of rule groups is being tested. This will be removed in the future and cache.BackendConfig will be moved back to the Config struct above.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL