diff --git a/main.go b/main.go index 2f3cd78fa..c41bb10bc 100644 --- a/main.go +++ b/main.go @@ -94,8 +94,10 @@ func main() { } case ruleResult := <-ruleResults: - for _, sample := range ruleResult.Samples { - ts.AppendSample(sample) + if ruleResult.Err == nil { + for _, sample := range ruleResult.Samples { + ts.AppendSample(sample) + } } } } diff --git a/rules/ast/ast.go b/rules/ast/ast.go index bfc4d39f2..7dc89f3a0 100644 --- a/rules/ast/ast.go +++ b/rules/ast/ast.go @@ -258,12 +258,13 @@ func labelsToKey(labels model.Metric) string { return strings.Join(keyParts, ",") // TODO not safe when label value contains comma. } -func EvalVectorInstant(node VectorNode, timestamp time.Time) (vector Vector) { +func EvalVectorInstant(node VectorNode, timestamp time.Time) (vector Vector, err error) { viewAdapter, err := viewAdapterForInstantQuery(node, timestamp) if err != nil { return } - return node.Eval(timestamp, viewAdapter) + vector = node.Eval(timestamp, viewAdapter) + return } func EvalVectorRange(node VectorNode, start time.Time, end time.Time, interval time.Duration) (matrix Matrix, err error) { diff --git a/rules/manager.go b/rules/manager.go index c80440058..80022d07a 100644 --- a/rules/manager.go +++ b/rules/manager.go @@ -68,9 +68,10 @@ func (m *ruleManager) runIteration(results chan *Result) { now := time.Now() for _, rule := range m.rules { go func() { - vector := rule.Eval(&now) + vector, err := rule.Eval(&now) m.results <- &Result{ Samples: vector, + Err: err, } }() } diff --git a/rules/rules.go b/rules/rules.go index 4de793741..ef4ffca1d 100644 --- a/rules/rules.go +++ b/rules/rules.go @@ -30,13 +30,16 @@ type Rule struct { func (rule *Rule) Name() string { return rule.name } -func (rule *Rule) EvalRaw(timestamp *time.Time) (vector ast.Vector) { +func (rule *Rule) EvalRaw(timestamp *time.Time) (vector ast.Vector, err error) { return ast.EvalVectorInstant(rule.vector, *timestamp) } -func (rule *Rule) Eval(timestamp *time.Time) ast.Vector { +func (rule *Rule) Eval(timestamp *time.Time) (vector ast.Vector, err error) { // Get the raw value of the rule expression. - vector := rule.EvalRaw(timestamp) + vector, err = rule.EvalRaw(timestamp) + if err != nil { + return + } // Override the metric name and labels. for _, sample := range vector { @@ -49,7 +52,7 @@ func (rule *Rule) Eval(timestamp *time.Time) ast.Vector { } } } - return vector + return } func (rule *Rule) RuleToDotGraph() string {