Files
grafana/pkg/services/ngalert/backtesting/eval_query.go
Yuri Tseretyan ad09feed83 Alerting: rule backtesting API (#57318)
* Implement backtesting engine that can process regular rule specification (with queries to datasource) as well as special kind of rules that have data frame instead of query.
* declare a new API endpoint and model
* add feature toggle `alertingBacktesting`
2022-12-14 09:44:14 -05:00

28 lines
582 B
Go

package backtesting
import (
"context"
"time"
"github.com/grafana/grafana/pkg/services/ngalert/eval"
)
// QueryEvaluator is evaluator of regular alert rule queries
type queryEvaluator struct {
eval eval.ConditionEvaluator
}
func (d *queryEvaluator) Eval(ctx context.Context, from, to time.Time, interval time.Duration, callback callbackFunc) error {
for now := from; now.Before(to); now = now.Add(interval) {
results, err := d.eval.Evaluate(ctx, now)
if err != nil {
return err
}
err = callback(now, results)
if err != nil {
return err
}
}
return nil
}