| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- package alerting
- import (
- "time"
- "github.com/grafana/grafana/pkg/log"
- "github.com/grafana/grafana/pkg/metrics"
- )
- type DefaultEvalHandler struct {
- log log.Logger
- alertJobTimeout time.Duration
- }
- func NewEvalHandler() *DefaultEvalHandler {
- return &DefaultEvalHandler{
- log: log.New("alerting.evalHandler"),
- alertJobTimeout: time.Second * 5,
- }
- }
- func (e *DefaultEvalHandler) Eval(context *EvalContext) {
- firing := true
- for _, condition := range context.Rule.Conditions {
- cr, err := condition.Eval(context)
- if err != nil {
- context.Error = err
- }
- // break if condition could not be evaluated
- if context.Error != nil {
- break
- }
- // break if result has not triggered yet
- if cr.Firing == false {
- firing = false
- break
- }
- context.EvalMatches = append(context.EvalMatches, cr.EvalMatches...)
- }
- context.Firing = firing
- context.EndTime = time.Now()
- elapsedTime := context.EndTime.Sub(context.StartTime) / time.Millisecond
- metrics.M_Alerting_Exeuction_Time.Update(elapsedTime)
- }
|