rule

package
v1.0.0-victorialogs Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2024 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SkipRandSleepOnGroupStart bool

SkipRandSleepOnGroupStart will skip random sleep delay in group first evaluation

Functions

func CompareRules

func CompareRules(t *testing.T, a, b Rule) error

CompareRules is a test helper func for other tests

func GetRuleStateSize

func GetRuleStateSize(r Rule) int

GetRuleStateSize returns size of rule stateEntry

Types

type AlertingRule

type AlertingRule struct {
	Type          config.Type
	RuleID        uint64
	Name          string
	Expr          string
	For           time.Duration
	KeepFiringFor time.Duration
	Labels        map[string]string
	Annotations   map[string]string
	GroupID       uint64
	GroupName     string
	File          string
	EvalInterval  time.Duration
	Debug         bool
	// contains filtered or unexported fields
}

AlertingRule is basic alert entity

func NewAlertingRule

func NewAlertingRule(qb datasource.QuerierBuilder, group *Group, cfg config.Rule) *AlertingRule

NewAlertingRule creates a new AlertingRule

func (*AlertingRule) GetAlert

func (ar *AlertingRule) GetAlert(id uint64) *notifier.Alert

GetAlert returns alert if id exists

func (*AlertingRule) GetAlerts

func (ar *AlertingRule) GetAlerts() []*notifier.Alert

GetAlerts returns active alerts of rule

func (*AlertingRule) ID

func (ar *AlertingRule) ID() uint64

ID returns unique Rule ID within the parent Group.

func (*AlertingRule) String

func (ar *AlertingRule) String() string

String implements Stringer interface

type Group

type Group struct {
	Name       string
	File       string
	Rules      []Rule
	Type       config.Type
	Interval   time.Duration
	EvalOffset *time.Duration
	// EvalDelay will adjust timestamp for rule evaluation requests to compensate intentional query delay from datasource.
	// see https://github.com/VictoriaMetrics/VictoriaMetrics/issues/5155
	EvalDelay      *time.Duration
	Limit          int
	Concurrency    int
	Checksum       string
	LastEvaluation time.Time

	Labels          map[string]string
	Params          url.Values
	Headers         map[string]string
	NotifierHeaders map[string]string
	// contains filtered or unexported fields
}

Group is an entity for grouping rules

func NewGroup

func NewGroup(cfg config.Group, qb datasource.QuerierBuilder, defaultInterval time.Duration, labels map[string]string) *Group

NewGroup returns a new group

func (*Group) Close

func (g *Group) Close()

Close stops the group and it's rules, unregisters group metrics

func (*Group) DeepCopy

func (g *Group) DeepCopy() *Group

DeepCopy returns a deep copy of group

func (*Group) ExecOnce

func (g *Group) ExecOnce(ctx context.Context, nts func() []notifier.Notifier, rw remotewrite.RWClient, evalTS time.Time) chan error

ExecOnce evaluates all the rules under group for once with given timestamp.

func (*Group) ID

func (g *Group) ID() uint64

ID return unique group ID that consists of rules file and group Name

func (*Group) InterruptEval

func (g *Group) InterruptEval()

InterruptEval interrupts in-flight rules evaluations within the group. It is expected that g.evalCancel will be repopulated after the call.

func (*Group) Replay

func (g *Group) Replay(start, end time.Time, rw remotewrite.RWClient, maxDataPoint, replayRuleRetryAttempts int, replayDelay time.Duration, disableProgressBar bool) int

Replay performs group replay

func (*Group) Start

func (g *Group) Start(ctx context.Context, nts func() []notifier.Notifier, rw remotewrite.RWClient, rr datasource.QuerierBuilder)

Start starts group's evaluation

func (*Group) UpdateWith

func (g *Group) UpdateWith(new *Group)

UpdateWith inserts new group to updateCh

type RecordingRule

type RecordingRule struct {
	Type      config.Type
	RuleID    uint64
	Name      string
	Expr      string
	Labels    map[string]string
	GroupID   uint64
	GroupName string
	File      string
	// contains filtered or unexported fields
}

RecordingRule is a Rule that supposed to evaluate configured Expression and return TimeSeries as result.

func NewRecordingRule

func NewRecordingRule(qb datasource.QuerierBuilder, group *Group, cfg config.Rule) *RecordingRule

NewRecordingRule creates a new RecordingRule

func (*RecordingRule) ID

func (rr *RecordingRule) ID() uint64

ID returns unique Rule ID within the parent Group.

func (*RecordingRule) String

func (rr *RecordingRule) String() string

String implements Stringer interface

type Rule

type Rule interface {
	// ID returns unique ID that may be used for
	// identifying this Rule among others.
	ID() uint64
	// contains filtered or unexported methods
}

Rule represents alerting or recording rule that has unique ID, can be Executed and updated with other Rule.

type StateEntry

type StateEntry struct {
	// stores last moment of time rule.Exec was called
	Time time.Time `json:"time"`
	// stores the timesteamp with which rule.Exec was called
	At time.Time `json:"at"`
	// stores the duration of the last rule.Exec call
	Duration time.Duration `json:"duration"`
	// stores last error that happened in Exec func
	// resets on every successful Exec
	// may be used as Health ruleState
	Err error `json:"error"`
	// stores the number of samples returned during
	// the last evaluation
	Samples int `json:"samples"`
	// stores the number of time series fetched during
	// the last evaluation.
	// Is supported by VictoriaMetrics only, starting from v1.90.0
	// If seriesFetched == nil, then this attribute was missing in
	// datasource response (unsupported).
	SeriesFetched *int `json:"series_fetched"`
	// stores the curl command reflecting the HTTP request used during rule.Exec
	Curl string `json:"curl"`
}

StateEntry stores rule's execution states

func GetAllRuleState

func GetAllRuleState(r Rule) []StateEntry

GetAllRuleState returns rule entire stateEntries

func GetLastEntry

func GetLastEntry(r Rule) StateEntry

GetLastEntry returns latest stateEntry of rule

Jump to

Keyboard shortcuts

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