mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-09 23:24:05 -08:00
Propagate more errors during rule evaluation.
This commit is contained in:
parent
6146116e2f
commit
c4d0969c00
6
main.go
6
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue