Propagate more errors during rule evaluation.

This commit is contained in:
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:
for _, sample := range ruleResult.Samples {
ts.AppendSample(sample)
if ruleResult.Err == nil {
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.
}
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) {

View file

@ -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,
}
}()
}

View file

@ -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 {