From bd217c58a7356bdc74f74b5a5645bfa85265942e Mon Sep 17 00:00:00 2001 From: Julien Pivotto Date: Wed, 15 Sep 2021 16:02:41 +0200 Subject: [PATCH] Backfill: Do not query after --end (#9340) Signed-off-by: Julien Pivotto --- cmd/promtool/rules.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cmd/promtool/rules.go b/cmd/promtool/rules.go index 890e2f287..7140d8aa9 100644 --- a/cmd/promtool/rules.go +++ b/cmd/promtool/rules.go @@ -105,11 +105,15 @@ func (importer *ruleImporter) importRule(ctx context.Context, ruleExpr, ruleName for startWithAlignment.Unix() < currStart { startWithAlignment = startWithAlignment.Add(grp.Interval()) } + end := time.Unix(min(endOfBlock/int64(time.Second/time.Millisecond), end.Unix()), 0).UTC() + if end.Before(startWithAlignment) { + break + } val, warnings, err := importer.apiClient.QueryRange(ctx, ruleExpr, v1.Range{ Start: startWithAlignment, - End: time.Unix(min(endOfBlock/int64(time.Second/time.Millisecond), end.Unix()), 0).UTC(), + End: end, Step: grp.Interval(), }, )