Skip to content

refactor(registrar,agent): reduce cognitive complexity to ≤15 in registrar + route reconcilers - #558

Merged
bpalermo merged 1 commit into
mainfrom
refactor/cognit-lane5-registrar-reconcilers
Jul 19, 2026
Merged

bpalermo merged 1 commit into
mainfrom
refactor/cognit-lane5-registrar-reconcilers

Conversation

@bpalermo

Copy link
Copy Markdown
Owner

Summary

Structure-only refactoring to reduce gocognit cognitive complexity to ≤15 in all non-test functions across the Lane 5 scope. Zero behavior change — guard clauses and helper extractions only. Part of #556.

Per-function extraction summary

Function Before After Helpers extracted
gamma (*Reconciler).Reconcile 59 ≤15 listGammaResources, listHTTPFilters, buildScopedFilters, resolveTargetRefFilters, projectAllRoutes, buildRouteTargetPorts, writeHTTPRouteStatuses, writeGRPCRouteStatuses
configexport (*Controller).Reconcile 44 ≤15 listExportResources, buildExportedSet, projectHTTPRoutes, projectGRPCRoutes, resolveChainFilters, ownCurrentProjections, applyDesired, pruneStale
l4route (*Reconciler).Reconcile 42 ≤15 listL4Resources, projectTCPRoutes, projectTLSRoutes, projectUDPRoutes, writeTCPRouteStatuses, writeTLSRouteStatuses, writeUDPRouteStatuses
server (*RegistrarServer).WatchEndpoints 35 ≤15 buildWatchFilter, sendFilteredSnapshot, sendServiceCatalog, streamEvents
configimport (*Importer).materialize 24 ≤15 selectProjections, buildRouteOutputs, chosenProjection type
server (*WriteBehindQueue).flushDue 23 ≤15 collectDueOps, flushOp
services (*Generator).reconcile 21 ≤15 buildDesiredServices, pruneServices
server (*Broadcaster).Broadcast 18 ≤15 closeDroppedWatchers, package-level droppedWatcher type
replicator (*Replicator).mirrorPeer 17 ≤15 runSyncWatchLoop
replicator (*Replicator).watchMirror 17 ≤15 mirrorEvent
server (*Snapshot).Replace 16 ≤15 computeTransitions

Caution zones preserved

  • WatchEndpoints / Broadcast: catalog events (SERVICE_ADDED/SERVICE_REMOVED) deliberately bypass watch filters — preserved exactly; sendServiceCatalog sends to all watchers regardless of filter; server_test "catalog bypasses the filter" assertion still passes.
  • gamma/l4route Reconcilers: CRD-detection gating, status writes, and projected-route ordering (portSets/sorting) preserved verbatim.
  • Replicator: origin-heartbeat lease semantics unchanged — lease is granted before runSyncWatchLoop, keepalive goroutine wires the same connCtx; no revoke on shutdown.

Verification

  • gocognit -over 15 <all scope dirs> (excl _test.go) → no output
  • bazel test //registrar/... //agent/... → 33/33 PASSED
  • make gazelle && make format → clean

🤖 Generated with Claude Code

https://claude.ai/code/session_01EioJVuoepwStjHoRLB52WR

@bpalermo
bpalermo merged commit 4166344 into main Jul 19, 2026
14 checks passed
@bpalermo
bpalermo deleted the refactor/cognit-lane5-registrar-reconcilers branch July 19, 2026 19:25
bpalermo added a commit that referenced this pull request Jul 19, 2026
The #556 campaign (PRs #558-#563) refactored all 65 production functions
over 15. This flips the ratchet from 109 to the 15 target, scopes the
aspect to go_library/go_binary (complexity-gating validated e2e and
conformance test harnesses adds churn risk for no production value), and
fixes the one offender the lane partition missed: RegistryRefresher.Start
(23 -> extracted refreshLoop helpers, semantics byte-identical).

Closes #556


Claude-Session: https://claude.ai/code/session_01EioJVuoepwStjHoRLB52WR

Co-authored-by: Claude Fable 5 <[email protected]>
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.

1 participant