mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* tech(routines): move the async logic from notification to alerting notifier
* tech(notification): reduce code dupe
* fix(notification): dont touch the response unless its an error
* feat(alerting): make alerting exeuction async but flow sync
* tech(alerting): remove commented code
* tech(alerting): remove unused code
* tech(alerting): fix typo
* tech(alerting): implement Context on EvalContext
* tech(alerting): wait for all alerts to return
* feat(alerting): dont allow alert responses to cancel
* Revert "feat(alerting): dont allow alert responses to cancel"
This reverts commit 324b006c96.
* feat(alerting): give alerts some time to finish before closing down
41 lines
860 B
Go
41 lines
860 B
Go
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) {
|
|
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()
|
|
elapsedTime := context.EndTime.Sub(context.StartTime) / time.Millisecond
|
|
metrics.M_Alerting_Exeuction_Time.Update(elapsedTime)
|
|
}
|