diff --git a/rules/alerting.go b/rules/alerting.go index d7cf5545e..b3fe2ea2a 100644 --- a/rules/alerting.go +++ b/rules/alerting.go @@ -126,19 +126,14 @@ func (rule *AlertingRule) Name() string { return rule.name } -// EvalRaw returns the raw value of the rule expression, without creating alerts. -func (rule *AlertingRule) EvalRaw(timestamp clientmodel.Timestamp, engine *promql.Engine) (promql.Vector, error) { +// Eval evaluates the rule expression and then creates pending alerts and fires +// or removes previously pending alerts accordingly. +func (rule *AlertingRule) Eval(timestamp clientmodel.Timestamp, engine *promql.Engine) (promql.Vector, error) { query, err := engine.NewInstantQuery(rule.Vector.String(), timestamp) if err != nil { return nil, err } - return query.Exec().Vector() -} - -// Eval evaluates the rule expression and then creates pending alerts and fires -// or removes previously pending alerts accordingly. -func (rule *AlertingRule) Eval(timestamp clientmodel.Timestamp, engine *promql.Engine) (promql.Vector, error) { - exprResult, err := rule.EvalRaw(timestamp, engine) + exprResult, err := query.Exec().Vector() if err != nil { return nil, err } diff --git a/rules/recording.go b/rules/recording.go index 95bb3d262..8a94048b6 100644 --- a/rules/recording.go +++ b/rules/recording.go @@ -34,18 +34,13 @@ type RecordingRule struct { // Name returns the rule name. func (rule RecordingRule) Name() string { return rule.name } -// EvalRaw returns the raw value of the rule expression. -func (rule RecordingRule) EvalRaw(timestamp clientmodel.Timestamp, engine *promql.Engine) (promql.Vector, error) { +// Eval evaluates the rule and then overrides the metric names and labels accordingly. +func (rule RecordingRule) Eval(timestamp clientmodel.Timestamp, engine *promql.Engine) (promql.Vector, error) { query, err := engine.NewInstantQuery(rule.vector.String(), timestamp) if err != nil { return nil, err } - return query.Exec().Vector() -} - -// Eval evaluates the rule and then overrides the metric names and labels accordingly. -func (rule RecordingRule) Eval(timestamp clientmodel.Timestamp, engine *promql.Engine) (promql.Vector, error) { - vector, err := rule.EvalRaw(timestamp, engine) + vector, err := query.Exec().Vector() if err != nil { return nil, err } diff --git a/rules/rules.go b/rules/rules.go index 2af1d5c61..88a89705f 100644 --- a/rules/rules.go +++ b/rules/rules.go @@ -26,9 +26,6 @@ import ( type Rule interface { // Name returns the name of the rule. Name() string - // EvalRaw evaluates the rule's vector expression without triggering any - // other actions, like recording or alerting. - EvalRaw(clientmodel.Timestamp, *promql.Engine) (promql.Vector, error) // Eval evaluates the rule, including any associated recording or alerting actions. Eval(clientmodel.Timestamp, *promql.Engine) (promql.Vector, error) // DotGraph returns a Graphviz dot graph of the rule.