Alerting: Fix panic in backtesting API when the testing interval is not times of evaluation interval (#68727)
* 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
This commit is contained in:
@@ -12,13 +12,13 @@ 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) {
|
||||
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(now, results)
|
||||
err = callback(idx, now, results)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user