eval

package
v0.0.85-test Latest Latest
Warning

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

Go to latest
Published: May 8, 2023 License: AGPL-3.0 Imports: 19 Imported by: 0

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 GetExprRequest

func GetExprRequest(ctx AlertExecCtx, data []models.AlertQuery, now time.Time, dsCacheService datasources.CacheService, secretsService secrets.Service, cfg *setting.Cfg) (*expr.Request, error)

GetExprRequest validates the condition, gets the datasource information and creates an expr.Request from it.

Types

type AlertExecCtx

type AlertExecCtx struct {
	OrgID              int64
	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(condition *models.Condition, now time.Time, expressionService *expr.Service) (Results, error)
	// QueriesAndExpressionsEval executes queries and expressions and returns the result.
	QueriesAndExpressionsEval(orgID int64, data []models.AlertQuery, now time.Time, expressionService *expr.Service) (*backend.QueryDataResponse, error)
}

func NewEvaluator

func NewEvaluator(
	cfg *setting.Cfg,
	log log.Logger,
	datasourceCache datasources.CacheService,
	secretsService secrets.Service) Evaluator

type ExecutionResults

type ExecutionResults struct {
	Error error

	// NoData contains the DatasourceUID for RefIDs that returned no data.
	NoData map[string]string

	Results data.Frames
}

ExecutionResults contains the unevaluated results from executing a condition.

type FakeEvaluator

type FakeEvaluator struct {
	mock.Mock
}

FakeEvaluator is an autogenerated mock type for the Evaluator type

func (*FakeEvaluator) ConditionEval

func (_m *FakeEvaluator) ConditionEval(condition *models.Condition, now time.Time, expressionService *expr.Service) (Results, error)

ConditionEval provides a mock function with given fields: condition, now, expressionService

func (*FakeEvaluator) EXPECT

func (_m *FakeEvaluator) EXPECT() *FakeEvaluator_Expecter

func (*FakeEvaluator) QueriesAndExpressionsEval

func (_m *FakeEvaluator) QueriesAndExpressionsEval(orgID int64, data []models.AlertQuery, now time.Time, expressionService *expr.Service) (*backend.QueryDataResponse, error)

QueriesAndExpressionsEval provides a mock function with given fields: orgID, data, now, expressionService

type FakeEvaluator_ConditionEval_Call

type FakeEvaluator_ConditionEval_Call struct {
	*mock.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 (*FakeEvaluator_ConditionEval_Call) Run

func (_c *FakeEvaluator_ConditionEval_Call) Run(run func(condition *models.Condition, now time.Time, expressionService *expr.Service)) *FakeEvaluator_ConditionEval_Call

type FakeEvaluator_Expecter

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

func (*FakeEvaluator_Expecter) ConditionEval

func (_e *FakeEvaluator_Expecter) ConditionEval(condition interface{}, now interface{}, expressionService interface{}) *FakeEvaluator_ConditionEval_Call

ConditionEval is a helper method to define mock.On call

  • condition *models.Condition
  • now time.Time
  • expressionService *expr.Service

func (*FakeEvaluator_Expecter) QueriesAndExpressionsEval

func (_e *FakeEvaluator_Expecter) QueriesAndExpressionsEval(orgID interface{}, data interface{}, now interface{}, expressionService interface{}) *FakeEvaluator_QueriesAndExpressionsEval_Call

QueriesAndExpressionsEval is a helper method to define mock.On call

  • orgID int64
  • data []models.AlertQuery
  • now time.Time
  • expressionService *expr.Service

type FakeEvaluator_QueriesAndExpressionsEval_Call

type FakeEvaluator_QueriesAndExpressionsEval_Call struct {
	*mock.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 (*FakeEvaluator_QueriesAndExpressionsEval_Call) Run

type NumberValueCapture

type NumberValueCapture struct {
	Var    string // RefID
	Labels data.Labels
	Value  *float64
}

type Result

type Result struct {
	Instance data.Labels
	State    State // Enum
	// Error message for Error state. should be nil if State != Error.
	Error              error
	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

	// 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
}

Result contains the evaluated State of an alert instance identified by its labels.

type Results

type Results []Result

Results is a slice of evaluated alert instances states.

func (Results) AsDataFrame

func (evalResults Results) AsDataFrame() data.Frame

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 (State) String

func (s State) String() string

Jump to

Keyboard shortcuts

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