ruler

package
v3.3.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	AlertForStateMetricName = "ALERTS_FOR_STATE"
)
View Source
const EvalModeLocal = "local"
View Source
const (
	EvalModeRemote = "remote"
)
View Source
const MetricsPrefix = "loki_ruler_wal_"

MetricsPrefix defines the prefix to use for all metrics in this package

Variables

This section is empty.

Functions

func DialQueryFrontend

func DialQueryFrontend(cfg *QueryFrontendConfig) (httpgrpc.HTTPClient, error)

DialQueryFrontend creates and initializes a new httpgrpc.HTTPClient taking a QueryFrontendConfig configuration.

func ForStateMetric

func ForStateMetric(base labels.Labels, alertName string) labels.Labels

func MultiTenantManagerAdapter

func MultiTenantManagerAdapter(mgr ruler.MultiTenantManager) ruler.MultiTenantManager

MultiTenantManagerAdapter will wrap a MultiTenantManager which validates loki rules

func MultiTenantRuleManager

func MultiTenantRuleManager(cfg Config, evaluator Evaluator, overrides RulesLimits, logger log.Logger, reg prometheus.Registerer) ruler.ManagerFactory

func NewRuler

func NewRuler(cfg Config, evaluator Evaluator, reg prometheus.Registerer, logger log.Logger, ruleStore rulestore.RuleStore, limits RulesLimits, metricsNamespace string) (*ruler.Ruler, error)

func ValidateGroups

func ValidateGroups(grps ...rulefmt.RuleGroup) (errs []error)

Types

type CachingGroupLoader

type CachingGroupLoader struct {
	// contains filtered or unexported fields
}

func NewCachingGroupLoader

func NewCachingGroupLoader(l rules.GroupLoader) *CachingGroupLoader

func (*CachingGroupLoader) AlertingRules

func (l *CachingGroupLoader) AlertingRules() []rulefmt.Rule

func (*CachingGroupLoader) Load

func (l *CachingGroupLoader) Load(identifier string) (*rulefmt.RuleGroups, []error)

func (*CachingGroupLoader) Parse

func (l *CachingGroupLoader) Parse(query string) (parser.Expr, error)

func (*CachingGroupLoader) Prune

func (l *CachingGroupLoader) Prune(toKeep []string)

type CachingRulesManager

type CachingRulesManager struct {
	// contains filtered or unexported fields
}

CachingRulesManager holds a CachingGroupLoader to make sure the GroupLoader has consistent state after update operations. Manager needs to hold the same caching grouploader

func (*CachingRulesManager) RuleGroups

func (m *CachingRulesManager) RuleGroups() []*rules.Group

func (*CachingRulesManager) Run

func (m *CachingRulesManager) Run()

func (*CachingRulesManager) Stop

func (m *CachingRulesManager) Stop()

func (*CachingRulesManager) Update

func (m *CachingRulesManager) Update(interval time.Duration, files []string, externalLabels labels.Labels, externalURL string, ruleGroupPostProcessFunc rules.GroupEvalIterationFunc) error

Update reconciles the state of the CachingGroupLoader after a manager.Update. The GroupLoader is mutated as part of a call to Update but it might still contain removed files. Update tells the loader which files to keep

type Config

type Config struct {
	ruler.Config `yaml:",inline"`

	WAL instance.Config `yaml:"wal,omitempty"`

	WALCleaner  cleaner.Config    `yaml:"wal_cleaner,omitempty"`
	RemoteWrite RemoteWriteConfig `` /* 134-byte string literal not displayed */

	Evaluation EvaluationConfig `yaml:"evaluation,omitempty" doc:"description=Configuration for rule evaluation."`
}

func (*Config) RegisterFlags

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

func (*Config) Validate

func (c *Config) Validate() error

Validate overrides the embedded cortex variant which expects a cortex limits struct. Instead, copy the relevant bits over.

type EvaluationConfig

type EvaluationConfig struct {
	Mode      string        `yaml:"mode,omitempty"`
	MaxJitter time.Duration `yaml:"max_jitter"`

	QueryFrontend QueryFrontendConfig `yaml:"query_frontend,omitempty"`
}

func (*EvaluationConfig) RegisterFlags

func (c *EvaluationConfig) RegisterFlags(f *flag.FlagSet)

func (*EvaluationConfig) Validate

func (c *EvaluationConfig) Validate() error

type Evaluator

type Evaluator interface {
	// Eval evaluates the given rule and returns the result.
	Eval(ctx context.Context, qs string, now time.Time) (*logqlmodel.Result, error)
}

Evaluator is the interface that must be satisfied in order to accept rule evaluations from the Ruler.

func NewEvaluatorWithJitter

func NewEvaluatorWithJitter(inner Evaluator, maxJitter time.Duration, hasher hash.Hash32, logger log.Logger) Evaluator

type EvaluatorWithJitter

type EvaluatorWithJitter struct {
	// contains filtered or unexported fields
}

EvaluatorWithJitter wraps a given Evaluator. It applies a consistent jitter based on a rule's query string by hashing the query string to produce a 32-bit unsigned integer. From this hash, we calculate a ratio between 0 and 1 and multiply it by the configured max jitter. This ratio is used to delay evaluation by a consistent amount of random time.

Consistent jitter is important because it allows rules to be evaluated on a regular, predictable cadence while also ensuring that we spread evaluations across the configured jitter window to avoid resource contention scenarios.

func (*EvaluatorWithJitter) Eval

type GroupLoader

type GroupLoader struct{}

func (GroupLoader) Load

func (g GroupLoader) Load(identifier string) (*rulefmt.RuleGroups, []error)

func (GroupLoader) Parse

func (GroupLoader) Parse(query string) (parser.Expr, error)

type LocalEvaluator

type LocalEvaluator struct {
	// contains filtered or unexported fields
}

func NewLocalEvaluator

func NewLocalEvaluator(engine *logql.Engine, logger log.Logger) (*LocalEvaluator, error)

func (*LocalEvaluator) Eval

func (l *LocalEvaluator) Eval(ctx context.Context, qs string, now time.Time) (*logqlmodel.Result, error)

type MemStore

type MemStore struct {
	// contains filtered or unexported fields
}

func NewMemStore

func NewMemStore(userID string, queryFunc rules.QueryFunc, metrics *memstoreMetrics, cleanupInterval time.Duration, logger log.Logger) *MemStore

func (*MemStore) Querier

func (m *MemStore) Querier(_, maxt int64) (storage.Querier, error)

implement storage.Queryable. It is only called with the desired ts as maxtime. Mint is parameterized via the outage tolerance, but since we're synthetically generating these, we only care about the desired time.

func (*MemStore) Start

func (m *MemStore) Start(iter RuleIter)

Calling Start will set the RuleIter, unblock the MemStore, and start the run() function in a separate goroutine.

func (*MemStore) Stop

func (m *MemStore) Stop()

type Middleware

type Middleware func(ctx context.Context, req *httpgrpc.HTTPRequest) error

Middleware provides a mechanism to inspect outgoing remote querier requests.

type MultiTenantManager

type MultiTenantManager struct {
	// contains filtered or unexported fields
}

MultiTenantManager wraps a cortex MultiTenantManager but validates loki rules

func (*MultiTenantManager) GetRules

func (m *MultiTenantManager) GetRules(userID string) []*rules.Group

func (*MultiTenantManager) Stop

func (m *MultiTenantManager) Stop()

func (*MultiTenantManager) SyncRuleGroups

func (m *MultiTenantManager) SyncRuleGroups(ctx context.Context, ruleGroups map[string]rulespb.RuleGroupList)

func (*MultiTenantManager) ValidateRuleGroup

func (m *MultiTenantManager) ValidateRuleGroup(grp rulefmt.RuleGroup) []error

ValidateRuleGroup validates a rulegroup

type QueryFrontendConfig

type QueryFrontendConfig struct {
	// The address of the remote querier to connect to.
	Address string `yaml:"address"`

	// TLSEnabled tells whether TLS should be used to establish remote connection.
	TLSEnabled bool `yaml:"tls_enabled"`

	// TLS is the config for client TLS.
	TLS tls.ClientConfig `yaml:",inline"`
}

QueryFrontendConfig defines query-frontend transport configuration.

func (*QueryFrontendConfig) RegisterFlags

func (c *QueryFrontendConfig) RegisterFlags(f *flag.FlagSet)

type RemoteEvaluator

type RemoteEvaluator struct {
	// contains filtered or unexported fields
}

func NewRemoteEvaluator

func NewRemoteEvaluator(client httpgrpc.HTTPClient, overrides RulesLimits, logger log.Logger, registerer prometheus.Registerer) (*RemoteEvaluator, error)

func (*RemoteEvaluator) Eval

func (r *RemoteEvaluator) Eval(ctx context.Context, qs string, now time.Time) (*logqlmodel.Result, error)

func (*RemoteEvaluator) Query

func (r *RemoteEvaluator) Query(ctx context.Context, ch chan<- queryResponse, orgID, qs string, t time.Time)

Query performs a query for the given time.

type RemoteWriteConfig

type RemoteWriteConfig struct {
	Client              *config.RemoteWriteConfig           `yaml:"client,omitempty" doc:"deprecated|description=Use 'clients' instead. Configure remote write client."`
	Clients             map[string]config.RemoteWriteConfig `` /* 214-byte string literal not displayed */
	Enabled             bool                                `yaml:"enabled"`
	ConfigRefreshPeriod time.Duration                       `yaml:"config_refresh_period"`
	AddOrgIDHeader      bool                                `yaml:"add_org_id_header" doc:"description=Add X-Scope-OrgID header in remote write requests."`
}

func (*RemoteWriteConfig) Clone

func (c *RemoteWriteConfig) Clone() (*RemoteWriteConfig, error)

func (*RemoteWriteConfig) RegisterFlags

func (c *RemoteWriteConfig) RegisterFlags(f *flag.FlagSet)

RegisterFlags adds the flags required to config this to the given FlagSet.

func (*RemoteWriteConfig) Validate

func (c *RemoteWriteConfig) Validate() error

type RuleCache

type RuleCache struct {
	// contains filtered or unexported fields
}

func NewRuleCache

func NewRuleCache(metrics *memstoreMetrics) *RuleCache

func (*RuleCache) CleanupOldSamples

func (c *RuleCache) CleanupOldSamples(olderThan time.Time) (empty bool)

CleanupOldSamples removes samples that are outside of the rule's `For` duration.

func (*RuleCache) Get

func (c *RuleCache) Get(ts time.Time, ls labels.Labels) (*promql.Sample, bool)

Get returns ok if that timestamp's result is cached.

func (*RuleCache) Set

func (c *RuleCache) Set(ts time.Time, vec promql.Vector)

type RuleIter

type RuleIter interface {
	AlertingRules() []rulefmt.Rule
}

type RulesLimits

type RulesLimits interface {
	ruler.RulesLimits

	RulerRemoteWriteDisabled(userID string) bool
	RulerRemoteWriteURL(userID string) string
	RulerRemoteWriteTimeout(userID string) time.Duration
	RulerRemoteWriteHeaders(userID string) map[string]string
	RulerRemoteWriteRelabelConfigs(userID string) []*rulerutil.RelabelConfig
	RulerRemoteWriteConfig(userID string, id string) *config.RemoteWriteConfig
	RulerRemoteWriteQueueCapacity(userID string) int
	RulerRemoteWriteQueueMinShards(userID string) int
	RulerRemoteWriteQueueMaxShards(userID string) int
	RulerRemoteWriteQueueMaxSamplesPerSend(userID string) int
	RulerRemoteWriteQueueBatchSendDeadline(userID string) time.Duration
	RulerRemoteWriteQueueMinBackoff(userID string) time.Duration
	RulerRemoteWriteQueueMaxBackoff(userID string) time.Duration
	RulerRemoteWriteQueueRetryOnRateLimit(userID string) bool
	RulerRemoteWriteSigV4Config(userID string) *sigv4.SigV4Config

	RulerRemoteEvaluationTimeout(userID string) time.Duration
	RulerRemoteEvaluationMaxResponseSize(userID string) int64
}

RulesLimits is the one function we need from limits.Overrides, and is here to limit coupling.

Directories

Path Synopsis
storage
cleaner
This directory was copied and adapted from https://github.com/grafana/agent/tree/main/pkg/metrics.
This directory was copied and adapted from https://github.com/grafana/agent/tree/main/pkg/metrics.
instance
This directory was copied and adapted from https://github.com/grafana/agent/tree/main/pkg/metrics.
This directory was copied and adapted from https://github.com/grafana/agent/tree/main/pkg/metrics.
util
This directory was copied and adapted from https://github.com/grafana/agent/tree/main/pkg/metrics.
This directory was copied and adapted from https://github.com/grafana/agent/tree/main/pkg/metrics.
wal
This directory was copied and adapted from https://github.com/grafana/agent/tree/main/pkg/metrics.
This directory was copied and adapted from https://github.com/grafana/agent/tree/main/pkg/metrics.

Jump to

Keyboard shortcuts

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