Documentation
¶
Overview ¶
Package eval executes the condition for an alert definition, evaluates the condition results, and returns the alert instance states.
Index ¶
- func ResultGen(mutators ...ResultMutator) func() Result
- type AlertExecCtx
- type Evaluator
- type ExecutionResults
- type FakeEvaluator
- func (_m *FakeEvaluator) ConditionEval(ctx context.Context, _a1 *user.SignedInUser, condition models.Condition, ...) Results
- func (_m *FakeEvaluator) EXPECT() *FakeEvaluator_Expecter
- func (_m *FakeEvaluator) QueriesAndExpressionsEval(ctx context.Context, _a1 *user.SignedInUser, data []models.AlertQuery, ...) (*backend.QueryDataResponse, error)
- func (_m *FakeEvaluator) Validate(ctx context.Context, _a1 *user.SignedInUser, condition models.Condition) error
- type FakeEvaluator_ConditionEval_Call
- type FakeEvaluator_Expecter
- func (_e *FakeEvaluator_Expecter) ConditionEval(ctx interface{}, _a1 interface{}, condition interface{}, now interface{}) *FakeEvaluator_ConditionEval_Call
- func (_e *FakeEvaluator_Expecter) QueriesAndExpressionsEval(ctx interface{}, _a1 interface{}, data interface{}, now interface{}) *FakeEvaluator_QueriesAndExpressionsEval_Call
- func (_e *FakeEvaluator_Expecter) Validate(ctx interface{}, _a1 interface{}, condition interface{}) *FakeEvaluator_Validate_Call
- type FakeEvaluator_QueriesAndExpressionsEval_Call
- type FakeEvaluator_Validate_Call
- type NumberValueCapture
- type Result
- type ResultMutator
- type Results
- type State
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ResultGen ¶
func ResultGen(mutators ...ResultMutator) func() Result
Types ¶
type AlertExecCtx ¶
type AlertExecCtx struct {
User *user.SignedInUser
ExpressionsEnabled bool
Log log.Logger
Ctx context.Context
}
AlertExecCtx is the context provided for executing an alert condition.
type Evaluator ¶
type Evaluator interface {
// ConditionEval executes conditions and evaluates the result.
ConditionEval(ctx context.Context, user *user.SignedInUser, condition models.Condition, now time.Time) Results
// QueriesAndExpressionsEval executes queries and expressions and returns the result.
QueriesAndExpressionsEval(ctx context.Context, user *user.SignedInUser, data []models.AlertQuery, now time.Time) (*backend.QueryDataResponse, error)
// Validate validates that the condition is correct. Returns nil if the condition is correct. Otherwise, error that describes the failure
Validate(ctx context.Context, user *user.SignedInUser, condition models.Condition) error
}
func NewEvaluator ¶
func NewEvaluator( cfg *setting.Cfg, log log.Logger, datasourceCache datasources.CacheService, expressionService *expr.Service) Evaluator
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 FakeEvaluator ¶
FakeEvaluator is an autogenerated mock type for the Evaluator type
func (*FakeEvaluator) ConditionEval ¶
func (_m *FakeEvaluator) ConditionEval(ctx context.Context, _a1 *user.SignedInUser, condition models.Condition, now time.Time) Results
ConditionEval provides a mock function with given fields: ctx, _a1, condition, now
func (*FakeEvaluator) EXPECT ¶
func (_m *FakeEvaluator) EXPECT() *FakeEvaluator_Expecter
func (*FakeEvaluator) QueriesAndExpressionsEval ¶
func (_m *FakeEvaluator) QueriesAndExpressionsEval(ctx context.Context, _a1 *user.SignedInUser, data []models.AlertQuery, now time.Time) (*backend.QueryDataResponse, error)
QueriesAndExpressionsEval provides a mock function with given fields: ctx, _a1, data, now
func (*FakeEvaluator) Validate ¶
func (_m *FakeEvaluator) Validate(ctx context.Context, _a1 *user.SignedInUser, condition models.Condition) error
Validate provides a mock function with given fields: ctx, _a1, condition
type FakeEvaluator_ConditionEval_Call ¶
FakeEvaluator_ConditionEval_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ConditionEval'
func (*FakeEvaluator_ConditionEval_Call) Return ¶
func (_c *FakeEvaluator_ConditionEval_Call) Return(_a0 Results) *FakeEvaluator_ConditionEval_Call
func (*FakeEvaluator_ConditionEval_Call) Run ¶
func (_c *FakeEvaluator_ConditionEval_Call) Run(run func(ctx context.Context, _a1 *user.SignedInUser, condition models.Condition, now time.Time)) *FakeEvaluator_ConditionEval_Call
type FakeEvaluator_Expecter ¶
type FakeEvaluator_Expecter struct {
// contains filtered or unexported fields
}
func (*FakeEvaluator_Expecter) ConditionEval ¶
func (_e *FakeEvaluator_Expecter) ConditionEval(ctx interface{}, _a1 interface{}, condition interface{}, now interface{}) *FakeEvaluator_ConditionEval_Call
ConditionEval is a helper method to define mock.On call
- ctx context.Context
- _a1 *user.SignedInUser
- condition models.Condition
- now time.Time
func (*FakeEvaluator_Expecter) QueriesAndExpressionsEval ¶
func (_e *FakeEvaluator_Expecter) QueriesAndExpressionsEval(ctx interface{}, _a1 interface{}, data interface{}, now interface{}) *FakeEvaluator_QueriesAndExpressionsEval_Call
QueriesAndExpressionsEval is a helper method to define mock.On call
- ctx context.Context
- _a1 *user.SignedInUser
- data []models.AlertQuery
- now time.Time
func (*FakeEvaluator_Expecter) Validate ¶
func (_e *FakeEvaluator_Expecter) Validate(ctx interface{}, _a1 interface{}, condition interface{}) *FakeEvaluator_Validate_Call
Validate is a helper method to define mock.On call
- ctx context.Context
- _a1 *user.SignedInUser
- condition models.Condition
type FakeEvaluator_QueriesAndExpressionsEval_Call ¶
FakeEvaluator_QueriesAndExpressionsEval_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'QueriesAndExpressionsEval'
func (*FakeEvaluator_QueriesAndExpressionsEval_Call) Return ¶
func (_c *FakeEvaluator_QueriesAndExpressionsEval_Call) Return(_a0 *backend.QueryDataResponse, _a1 error) *FakeEvaluator_QueriesAndExpressionsEval_Call
func (*FakeEvaluator_QueriesAndExpressionsEval_Call) Run ¶
func (_c *FakeEvaluator_QueriesAndExpressionsEval_Call) Run(run func(ctx context.Context, _a1 *user.SignedInUser, data []models.AlertQuery, now time.Time)) *FakeEvaluator_QueriesAndExpressionsEval_Call
type FakeEvaluator_Validate_Call ¶
FakeEvaluator_Validate_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Validate'
func (*FakeEvaluator_Validate_Call) Return ¶
func (_c *FakeEvaluator_Validate_Call) Return(_a0 error) *FakeEvaluator_Validate_Call
func (*FakeEvaluator_Validate_Call) Run ¶
func (_c *FakeEvaluator_Validate_Call) Run(run func(ctx context.Context, _a1 *user.SignedInUser, condition models.Condition)) *FakeEvaluator_Validate_Call
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 RefID and value of reduce and math expressions.
// It does not contain values for classic conditions as the values
// in classic conditions do not have a RefID.
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