Documentation ¶
Overview ¶
Package eval executes the condition for an alert definition, evaluates the condition results, and returns the alert instance states.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ResultGen ¶
func ResultGen(mutators ...ResultMutator) func() Result
Types ¶
type ConditionEvaluator ¶
type ConditionEvaluator interface { // EvaluateRaw evaluates the condition and returns raw backend response backend.QueryDataResponse EvaluateRaw(ctx context.Context, now time.Time) (resp *backend.QueryDataResponse, err error) // Evaluate evaluates the condition and converts the response to Results Evaluate(ctx context.Context, now time.Time) (Results, error) }
type EvaluationContext ¶
type EvaluationContext struct { Ctx context.Context User *user.SignedInUser }
EvaluationContext represents the context in which a condition is evaluated.
func NewContext ¶
func NewContext(ctx context.Context, user *user.SignedInUser) EvaluationContext
type EvaluatorFactory ¶
type EvaluatorFactory interface { // Validate validates that the condition is correct. Returns nil if the condition is correct. Otherwise, error that describes the failure Validate(ctx EvaluationContext, condition models.Condition) error // Create builds an evaluator pipeline ready to evaluate a rule's query Create(ctx EvaluationContext, condition models.Condition) (ConditionEvaluator, error) }
func NewEvaluatorFactory ¶
func NewEvaluatorFactory( cfg setting.UnifiedAlertingSettings, datasourceCache datasources.CacheService, expressionService *expr.Service, pluginsStore plugins.Store, ) EvaluatorFactory
type ExecutionResults ¶
type ExecutionResults struct { // Condition contains the results of the condition Condition data.Frames // Results contains the results of all queries, reduce and math expressions Results map[string]data.Frames // NoData contains the DatasourceUID for RefIDs that returned no data. NoData map[string]string Error error }
ExecutionResults contains the unevaluated results from executing a condition.
type NumberValueCapture ¶
type Result ¶
type Result struct { Instance data.Labels State State // Enum // Error message for Error state. should be nil if State != Error. Error error // Results contains the results of all queries, reduce and math expressions Results map[string]data.Frames // Values contains the labels and values for all Threshold, Reduce and Math expressions, // and all conditions of a Classic Condition that are firing. Threshold, Reduce and Math // expressions are indexed by their Ref ID, while conditions in a Classic Condition are // indexed by their Ref ID and the index of the condition. For example, B0, B1, etc. Values map[string]NumberValueCapture EvaluatedAt time.Time EvaluationDuration time.Duration // EvaluationString is a string representation of evaluation data such // as EvalMatches (from "classic condition"), and in the future from operations // like SSE "math". EvaluationString string }
Result contains the evaluated State of an alert instance identified by its labels.
type ResultMutator ¶
type ResultMutator func(r *Result)
func WithEvaluatedAt ¶
func WithEvaluatedAt(time time.Time) ResultMutator
func WithLabels ¶
func WithLabels(labels data.Labels) ResultMutator
func WithState ¶
func WithState(state State) ResultMutator
type Results ¶
type Results []Result
Results is a slice of evaluated alert instances states.
func GenerateResults ¶
func (Results) AsDataFrame ¶
AsDataFrame forms the EvalResults in Frame suitable for displaying in the table panel of the front end. It displays one row per alert instance, with a column for each label and one for the alerting state.
type State ¶
type State int
State is an enum of the evaluation State for an alert instance.
const ( // Normal is the eval state for an alert instance condition // that evaluated to false. Normal State = iota // Alerting is the eval state for an alert instance condition // that evaluated to true (Alerting). Alerting // Pending is the eval state for an alert instance condition // that evaluated to true (Alerting) but has not yet met // the For duration defined in AlertRule. Pending // NoData is the eval state for an alert rule condition // that evaluated to NoData. NoData // Error is the eval state for an alert rule condition // that evaluated to Error. Error )
func RandomState ¶
func RandomState() State