Skip to content

refactor(xds): reduce cognitive complexity to <=15 in snapshot cache (lane 2, part of #556) - #562

Merged
bpalermo merged 1 commit into
mainfrom
refactor/cognit-lane2-xds-cache
Jul 19, 2026
Merged

bpalermo merged 1 commit into
mainfrom
refactor/cognit-lane2-xds-cache

Conversation

@bpalermo

Copy link
Copy Markdown
Owner

Summary

Reduces gocognit cognitive complexity of all non-test functions in agent/internal/xds/cache/ to ≤15. This is Lane 2 of the parallel campaign tracking issue #556.

Per-function extraction summary

Function File Before After Strategy
LoadClustersFromRegistry cluster.go 98 9 Extracted coldFillHTTPEndpoints, coldFillTCPEndpoints (package-level), buildHTTPClustersLocked, buildHTTPServiceEntryLocked, buildHTTPEndpointBuckets, endpointSANNamespaces, endpointSubsetKeys, buildTCPClustersLocked, retainAbsentClustersLocked
rebuildEdgeDependencies edge.go 41 10 Extracted collectVhostDeps method + collectEdgeTCPDeps/collectEdgeTLSDeps package-level functions; replaced inline addVhost closure
buildEdgeVhostsLocked edge.go 39 12 Extracted admitVhostRoutes, buildEnvoyRouteLocked, buildEnvoyWeightedRouteLocked; introduced domainRouteGroup struct
dependencySetLocked dependencies.go 33 8 Extracted populateStaticDepsLocked, populatePodDepsLocked, populateObservedDepsLocked, populateRouteDepsLocked
edgeTCPClusters capture.go 32 8 Extracted collectEdgeTCPServices
edgeK8sBackendClusters edge.go 32 9 Extracted collectK8sBackends, buildK8sClustersLocked, addK8sBackend, collectK8sRoutesBackends; introduced k8sBackend struct
equalGammaHeaderMutation gamma.go 24 6 Extracted equalGammaHMutationLengths, equalGammaHeaderKVs, equalGammaHeaderStrings
equalRoutes edge.go 22 4 Extracted equalRoute per-element comparator
equalEdgeTLSRoutes edge.go 21 6 Extracted equalEdgeTLSRules
edgeClusterNameLocked edge.go 18 9 Extracted edgeMeshClusterNameLocked returning (string, bool)
equalGammaRoute gamma.go 18 10 Extracted equalGammaMatches
captureVhosts capture.go 16 4 Extracted appendSABackedCaptureVhosts, appendRouteOnlyCaptureVhosts, captureVhostDomains
edgeGatewayListeners edge.go 16 5 Extracted appendGatewayListenerLocked
Listeners listener.go 16 4 Extracted edgeListeners, appendEdgePhase1Listeners, meshListeners

All extractions are pure structure-preserving refactors: verbatim code movement, guard clauses, and named helpers. No behavior was changed. The clusterMu outer / localMu inner lock ordering (mtls.go #548), depGen memos (#549), gamma/capture memos (#551), and snapshot semantics (snapshot.go) are all preserved exactly.

Test plan

  • gocognit -over 15 agent/internal/xds/cache/ (excluding _test.go) outputs nothing
  • bazel test --test_output=errors //agent/... — 26/26 pass
  • bazel test --test_output=errors --@rules_go//go/config:race=true //agent/internal/xds/cache/... — 3/3 pass (race-clean)
  • make gazelle — no BUILD.bazel changes
  • make format — clean

Part of #556

🤖 Generated with Claude Code

https://claude.ai/code/session_01EioJVuoepwStjHoRLB52WR

@bpalermo
bpalermo merged commit c6e6a56 into main Jul 19, 2026
14 checks passed
@bpalermo
bpalermo deleted the refactor/cognit-lane2-xds-cache branch July 19, 2026 19:31
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