mirror of https://github.com/prometheus/prometheus
Propagate more errors during rule evaluation.
parent
6146116e2f
commit
c4d0969c00
6
main.go
6
main.go
|
@ -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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
|
@ -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,
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
Loading…
Reference in New Issue