mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* 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`
28 lines
582 B
Go
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
|
|
}
|