Propagate more errors during rule evaluation.

pull/123/head
Julius Volz 2013-04-09 13:47:20 +02:00
parent 6146116e2f
commit c4d0969c00
4 changed files with 16 additions and 9 deletions

View File

@ -94,8 +94,10 @@ func main() {
} }
case ruleResult := <-ruleResults: case ruleResult := <-ruleResults:
for _, sample := range ruleResult.Samples { if ruleResult.Err == nil {
ts.AppendSample(sample) for _, sample := range ruleResult.Samples {
ts.AppendSample(sample)
}
} }
} }
} }

View File

@ -258,12 +258,13 @@ func labelsToKey(labels model.Metric) string {
return strings.Join(keyParts, ",") // TODO not safe when label value contains comma. 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) viewAdapter, err := viewAdapterForInstantQuery(node, timestamp)
if err != nil { if err != nil {
return 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) { func EvalVectorRange(node VectorNode, start time.Time, end time.Time, interval time.Duration) (matrix Matrix, err error) {

View File

@ -68,9 +68,10 @@ func (m *ruleManager) runIteration(results chan *Result) {
now := time.Now() now := time.Now()
for _, rule := range m.rules { for _, rule := range m.rules {
go func() { go func() {
vector := rule.Eval(&now) vector, err := rule.Eval(&now)
m.results <- &Result{ m.results <- &Result{
Samples: vector, Samples: vector,
Err: err,
} }
}() }()
} }

View File

@ -30,13 +30,16 @@ type Rule struct {
func (rule *Rule) Name() string { return rule.name } 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) 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. // 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. // Override the metric name and labels.
for _, sample := range vector { 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 { func (rule *Rule) RuleToDotGraph() string {