From 2ed2d284e071324d0ccece7a4ea2d48fe609d765 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 21 Sep 2026 19:22:06 +0000 Subject: [PATCH 1/2] Initial plan From bc50fdfe00be728e776cd10970c5b064fc4d4fe3 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 21 Sep 2026 19:32:40 +0000 Subject: [PATCH 2/2] Fix flaky TestGetRules by preventing scheduled rule evaluation The unknown-state and unknown/ok-health filter subtests assert the transient pre-evaluation state of rules. Build the test rulers with a no-op GroupEvalIterationFunc so a scheduled group evaluation (slotted at a hash-based offset within the group interval) cannot fire within the test window and move rules out of StateUnknown/HealthUnknown. Also rename the subtest to match the filter it actually exercises. Signed-off-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: CharlieTLe <3375195+CharlieTLe@users.noreply.github.com> --- pkg/ruler/ruler_test.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pkg/ruler/ruler_test.go b/pkg/ruler/ruler_test.go index cebcb2502d4..b31d7af9ff6 100644 --- a/pkg/ruler/ruler_test.go +++ b/pkg/ruler/ruler_test.go @@ -917,10 +917,10 @@ func TestGetRules(t *testing.T) { "user3": 0, }, }, - "No Sharding with Alert state filter for inactive alerts": { + "No Sharding with Alert state filter for unknown alerts": { sharding: false, rulesRequest: RulesRequest{ - State: unknownStateFilter, // Prometheus v2.x uses "unknown" for unevaluated alerts + State: unknownStateFilter, // Prometheus uses the "unknown" state for alerting rules that have not been evaluated yet. MaxRuleGroups: -1, }, rulerStateMap: rulerStateMapAllActive, @@ -1363,7 +1363,13 @@ func TestGetRules(t *testing.T) { cfg.Ring.InstanceZone = tc.rulerAZMap[id] } - r, _ := buildRuler(t, cfg, nil, store, rulerAddrMap) + // Use a no-op GroupEvalIterationFunc to keep rules in their pre-evaluation state ("unknown" + // alert state and "unknown" health). The scheduled evaluation of a group can otherwise fire + // within the test window (the first evaluation is slotted at a hash-based offset within the + // group interval) and move rules out of the state asserted by the state/health filter cases. + noopEvalIterationFunc := func(ctx context.Context, g *promRules.Group, evalTimestamp time.Time) {} + + r, _ := buildRulerWithIterFunc(t, cfg, nil, store, rulerAddrMap, noopEvalIterationFunc) r.limits = &ruleLimits{tenantShard: tc.shuffleShardSize} rulerAddrMap[id] = r if r.ring != nil {