2016-07-27 16:29:28 +02:00
|
|
|
package alerting
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/log"
|
2016-08-11 21:12:39 +02:00
|
|
|
"github.com/grafana/grafana/pkg/metrics"
|
2016-07-27 16:29:28 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type DefaultEvalHandler struct {
|
|
|
|
|
log log.Logger
|
|
|
|
|
alertJobTimeout time.Duration
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewEvalHandler() *DefaultEvalHandler {
|
|
|
|
|
return &DefaultEvalHandler{
|
2016-07-28 17:03:53 +02:00
|
|
|
log: log.New("alerting.evalHandler"),
|
2016-10-03 09:38:03 +02:00
|
|
|
alertJobTimeout: time.Second * 5,
|
2016-07-27 16:29:28 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (e *DefaultEvalHandler) Eval(context *EvalContext) {
|
|
|
|
|
for _, condition := range context.Rule.Conditions {
|
|
|
|
|
condition.Eval(context)
|
|
|
|
|
|
|
|
|
|
// break if condition could not be evaluated
|
|
|
|
|
if context.Error != nil {
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// break if result has not triggered yet
|
|
|
|
|
if context.Firing == false {
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
context.EndTime = time.Now()
|
2016-09-08 10:45:10 +02:00
|
|
|
elapsedTime := context.EndTime.Sub(context.StartTime) / time.Millisecond
|
2016-08-11 21:12:39 +02:00
|
|
|
metrics.M_Alerting_Exeuction_Time.Update(elapsedTime)
|
2016-07-27 16:29:28 +02:00
|
|
|
}
|