mirror of
https://github.com/grafana/grafana.git
synced 2024-11-29 04:04:00 -06:00
30fc075cd7
* add test for the bug * update backtesting evaluators to accept a number of evaluations instead of `to` to have control over the number evaluations in one place
28 lines
623 B
Go
28 lines
623 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 time.Time, interval time.Duration, evaluations int, callback callbackFunc) error {
|
|
for idx, now := 0, from; idx < evaluations; idx, now = idx+1, now.Add(interval) {
|
|
results, err := d.eval.Evaluate(ctx, now)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
err = callback(idx, now, results)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|