Skip to content

refactor(checker): split the reconcile functions and checker.go by topic - #322

Merged
Saremox merged 11 commits into
mainfrom
claude/quality-r6-checker
Oct 16, 2026
Merged

Saremox merged 11 commits into
mainfrom
claude/quality-r6-checker

Conversation

@Saremox

@Saremox Saremox commented Oct 16, 2026 •

Copy link
Copy Markdown
Owner

Changes proposed on the PR:

  • Split UpdateRedisesPods, checkAndHeal, checkAndHealOperatorManagedMode, checkAndHealBootstrapMode, applyPassword, checkAndHealSentinels and readSentinelFailovers into helpers, so that each function has a cyclomatic complexity of at most 15, a cognitive complexity of at most 20 and at most 80 lines.

  • Replace the copies of the stopping master check (5), the oldest pod election (3), the config and rollout step (2), the Sentinel quorum check (2) and the status of a failed promotion (3) with one helper each, to remove duplicated code.

  • Move the declarations of checker.go without a change to topic files (rollout, master, password, Sentinel-managed mode, operator-managed mode, Sentinel heal), so that each file has less than 800 lines. An AST script checked that all 101 declarations are byte-identical.

  • TestOperatorElectedText (soak module) reads the status text from checker.go. The text moved to checker_sentinel_mode.go, so the test now reads all checker*.go files, and the CI path filter of the soak job is operator/redisfailover/checker*.go (it was checker.go), so that the soak job runs when a split file changes. The first CI run of this PR failed on that test.

No change of behavior: no exported identifier, message text, metric, log line, defer order or call order changed. User-visible effect: none.

Evidence:

  • The unit and golden tests of operator/redisfailover pass unchanged with 100% statement coverage of the checker files, also with -race.
  • A deterministic simulation gave identical traces of every API and Redis call on 402 seeds for main and this branch.
  • An independent review extended the simulation with the patch bodies, a tracing logger, a metrics recorder and the requeues, plus a Sentinel failover model (in-progress states, jitter, read errors). On new seeds (212) the traces are identical with and without the failover model; the failover paths reached 100% coverage in that run (11,263 failover reads).
  • A real Redis and Sentinel failover run gives the same operator log lines (one run differed by one hold line because of Sentinel timing; repeated runs are within the same noise on both builds).

Not tested: a cluster run (kind, minikube); the Sentinel-unreachable branch inside findSentinelFailover under the failover model.

Found and not changed: reportRolloutWait uses time.Now and time.Since, not the handler clock r.now(). A fake clock never reaches the rollout stall message.

🤖 Generated with Claude Code

https://claude.ai/code/session_01G4mmyo3sqLwf23m5FE2nBE


Generated by Claude Code

UpdateRedisesPods: cyclomatic 49 -> 12, cognitive 109 -> 13, length 177 -> 47
lines. The replica scan, the replica replacement, the master replacement and
the gate before the master delete are helpers. No behavior change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G4mmyo3sqLwf23m5FE2nBE
checkAndHeal: cyclomatic 48 -> 5, cognitive 89 -> 5, length 368 -> 50 lines.
The Sentinel-managed mode, the master count, the election without a Sentinel
failover, the config and rollout step and the Sentinel monitor step are
helpers. stoppingMasterStatus and setOldestAsMaster replace copies of the
same code. No behavior change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G4mmyo3sqLwf23m5FE2nBE
checkAndHealOperatorManagedMode: cyclomatic 41 -> 9, cognitive 87 -> 8,
length 268 -> 37 lines. Each master count has a helper. The redis quorum
check, the config and rollout step, the stopping master check, the master
pod wait and the status of a failed promotion use the helpers of the
Sentinel-managed mode. No behavior change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G4mmyo3sqLwf23m5FE2nBE
…pMode

checkAndHealBootstrapMode: cyclomatic 16 -> 8, cognitive 33 -> 8, length
104 -> 59 lines. healBootstrapSentinels holds the Sentinel monitor step of
the bootstrap mode. No behavior change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G4mmyo3sqLwf23m5FE2nBE
applyPassword: cyclomatic 31 -> 14, cognitive 34 -> 12, length 68 -> 36
lines. applyRedisPassword and applySentinelPassword hold the two steps, and
passwordState.current holds the check of a state with nothing to do. No
behavior change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G4mmyo3sqLwf23m5FE2nBE
checkAndHealSentinels: cyclomatic 18 -> 10, cognitive 32 -> 14, length 73 ->
41 lines. restoreSentinelMismatches holds the loop that the Sentinel count
and the replica count checks shared. No behavior change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G4mmyo3sqLwf23m5FE2nBE
readSentinelFailovers: cyclomatic 24 -> 13, cognitive 27 -> 13, length 88 ->
61 lines. findSentinelFailover reads the Sentinels and returns the failover
of the leader, and sentinelFailover.continues compares it with the stored
one. No behavior change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G4mmyo3sqLwf23m5FE2nBE
checker.go: 2374 -> 355 lines. The declarations move without a change to
checker_rollout.go (pod rollout and master handover), checker_master.go
(master pod state and failover timeout), checker_password.go,
checker_sentinel_mode.go, checker_operator_mode.go and checker_sentinel.go
(Sentinel heal and failover hold). Each file has less than 800 lines. No
behavior change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G4mmyo3sqLwf23m5FE2nBE
The doc comments of rolloutScan, replaceStaleReplica and waitForMasterPod
name the caller that returns on each result. Comment change only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G4mmyo3sqLwf23m5FE2nBE
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-16T12:08:23.924221Z 9eff650 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@codecov

codecov Bot commented Oct 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

TestOperatorElectedText read only checker.go. The split of checker.go moved
the status message of electMasterForSentinel to checker_sentinel_mode.go,
so the test failed. The test reads each checker*.go file of the package.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G4mmyo3sqLwf23m5FE2nBE
TestOperatorElectedText reads the status text from each checker*.go file,
so the path filter of the soak job matches all of them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G4mmyo3sqLwf23m5FE2nBE

Saremox commented Oct 16, 2026

Copy link
Copy Markdown
Owner Author

@codex review


Generated by Claude Code

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: 9eff650850

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Saremox
Saremox merged commit 84622c1 into main Oct 16, 2026
17 checks passed
@Saremox
Saremox deleted the claude/quality-r6-checker branch October 16, 2026 12:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants