Skip to content

Commit 1317cd0

Browse files
CopilotCharlieTLe
andauthored
Fix flaky TestGetRules: stop scheduled evaluations from racing pre-evaluation state assertions (#7857)
* Initial plan * 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> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: CharlieTLe <3375195+CharlieTLe@users.noreply.github.com> Co-authored-by: Charlie Le <charlie_le@apple.com>
1 parent a3773c2 commit 1317cd0

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

‎pkg/ruler/ruler_test.go‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -917,10 +917,10 @@ func TestGetRules(t *testing.T) {
917917
"user3": 0,
918918
},
919919
},
920-
"No Sharding with Alert state filter for inactive alerts": {
920+
"No Sharding with Alert state filter for unknown alerts": {
921921
sharding: false,
922922
rulesRequest: RulesRequest{
923-
State: unknownStateFilter, // Prometheus v2.x uses "unknown" for unevaluated alerts
923+
State: unknownStateFilter, // Prometheus uses the "unknown" state for alerting rules that have not been evaluated yet.
924924
MaxRuleGroups: -1,
925925
},
926926
rulerStateMap: rulerStateMapAllActive,
@@ -1363,7 +1363,13 @@ func TestGetRules(t *testing.T) {
13631363
cfg.Ring.InstanceZone = tc.rulerAZMap[id]
13641364
}
13651365

1366-
r, _ := buildRuler(t, cfg, nil, store, rulerAddrMap)
1366+
// Use a no-op GroupEvalIterationFunc to keep rules in their pre-evaluation state ("unknown"
1367+
// alert state and "unknown" health). The scheduled evaluation of a group can otherwise fire
1368+
// within the test window (the first evaluation is slotted at a hash-based offset within the
1369+
// group interval) and move rules out of the state asserted by the state/health filter cases.
1370+
noopEvalIterationFunc := func(ctx context.Context, g *promRules.Group, evalTimestamp time.Time) {}
1371+
1372+
r, _ := buildRulerWithIterFunc(t, cfg, nil, store, rulerAddrMap, noopEvalIterationFunc)
13671373
r.limits = &ruleLimits{tenantShard: tc.shuffleShardSize}
13681374
rulerAddrMap[id] = r
13691375
if r.ring != nil {

0 commit comments

Comments
 (0)