Remove EvalRaw methods from Rule interface

pull/779/head
Fabian Reinartz 10 years ago
parent 7943aa834c
commit 83d07516e8

@ -126,19 +126,14 @@ func (rule *AlertingRule) Name() string {
return rule.name return rule.name
} }
// EvalRaw returns the raw value of the rule expression, without creating alerts. // Eval evaluates the rule expression and then creates pending alerts and fires
func (rule *AlertingRule) EvalRaw(timestamp clientmodel.Timestamp, engine *promql.Engine) (promql.Vector, error) { // 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) query, err := engine.NewInstantQuery(rule.Vector.String(), timestamp)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return query.Exec().Vector() exprResult, err := 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)
if err != nil { if err != nil {
return nil, err return nil, err
} }

@ -34,18 +34,13 @@ type RecordingRule struct {
// Name returns the rule name. // Name returns the rule name.
func (rule RecordingRule) Name() string { return rule.name } func (rule RecordingRule) Name() string { return rule.name }
// EvalRaw returns the raw value of the rule expression. // Eval evaluates the rule and then overrides the metric names and labels accordingly.
func (rule RecordingRule) EvalRaw(timestamp clientmodel.Timestamp, engine *promql.Engine) (promql.Vector, error) { func (rule RecordingRule) Eval(timestamp clientmodel.Timestamp, engine *promql.Engine) (promql.Vector, error) {
query, err := engine.NewInstantQuery(rule.vector.String(), timestamp) query, err := engine.NewInstantQuery(rule.vector.String(), timestamp)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return query.Exec().Vector() vector, err := 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)
if err != nil { if err != nil {
return nil, err return nil, err
} }

@ -26,9 +26,6 @@ import (
type Rule interface { type Rule interface {
// Name returns the name of the rule. // Name returns the name of the rule.
Name() string 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 evaluates the rule, including any associated recording or alerting actions.
Eval(clientmodel.Timestamp, *promql.Engine) (promql.Vector, error) Eval(clientmodel.Timestamp, *promql.Engine) (promql.Vector, error)
// DotGraph returns a Graphviz dot graph of the rule. // DotGraph returns a Graphviz dot graph of the rule.

Loading…
Cancel
Save