eval

package
v0.0.0-...-900be4e Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2024 License: Apache-2.0 Imports: 8 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

View Source
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 false.
	Alerting
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AlertExecCtx

type AlertExecCtx struct {
	OrgID              int64
	ExpressionsEnabled bool

	Ctx context.Context
}

AlertExecCtx is the context provided for executing an alert condition.

type AlertQuery

type AlertQuery struct {
	// RefID is the unique identifier of the query, set by the frontend call.
	RefID string `json:"refId"`

	// QueryType is an optional identifier for the type of query.
	// It can be used to distinguish different types of queries.
	QueryType string `json:"queryType"`

	// RelativeTimeRange is the relative Start and End of the query as sent by the frontend.
	RelativeTimeRange RelativeTimeRange `json:"relativeTimeRange"`

	DatasourceUID string `json:"-"`

	// JSON is the raw JSON query and includes the above properties as well as custom properties.
	Model json.RawMessage `json:"model"`
	// contains filtered or unexported fields
}

AlertQuery represents a single query associated with an alert definition.

func (*AlertQuery) GetDatasource

func (aq *AlertQuery) GetDatasource() (string, error)

GetDatasource returns the query datasource identifier.

func (*AlertQuery) IsExpression

func (aq *AlertQuery) IsExpression() (bool, error)

IsExpression returns true if the alert query is an expression.

func (*AlertQuery) PreSave

func (aq *AlertQuery) PreSave() error

PreSave sets query's properties. It should be called before being saved.

type Condition

type Condition struct {
	RefID string `json:"refId"`
	OrgID int64  `json:"-"`

	QueriesAndExpressions []AlertQuery `json:"queriesAndExpressions"`
}

Condition contains backend expressions and queries and the RefID of the query or expression that will be evaluated.

func (Condition) IsValid

func (c Condition) IsValid() bool

IsValid checks the condition's validity.

type Duration

type Duration time.Duration

Duration is a type used for marshalling durations.

func (Duration) MarshalJSON

func (d Duration) MarshalJSON() ([]byte, error)

func (Duration) String

func (d Duration) String() string

func (*Duration) UnmarshalJSON

func (d *Duration) UnmarshalJSON(b []byte) error

type Evaluator

type Evaluator struct {
	Cfg *setting.Cfg
}

func (*Evaluator) ConditionEval

func (e *Evaluator) ConditionEval(condition *Condition, now time.Time) (Results, error)

ConditionEval executes conditions and evaluates the result.

type ExecutionResults

type ExecutionResults struct {
	AlertDefinitionID int64

	Error error

	Results data.Frames
}

ExecutionResults contains the unevaluated results from executing a condition.

type RelativeTimeRange

type RelativeTimeRange struct {
	From Duration `json:"from"`
	To   Duration `json:"to"`
}

RelativeTimeRange is the per query start and end time for requests.

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. This may be temporary, as there might be a fair amount we want to display in the frontend, and it might not make sense to store that in data.Frame. For the first pass, I would expect a Frame with a single row, and a column for each instance with a boolean value.

Jump to

Keyboard shortcuts

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