Repository navigation
refactor(xds): split the snapshot cache into per-concern packages (#544) - #553
Merged
Merged
Conversation
Extract the two Envoy-proto-free, self-contained infrastructure concerns out of the agent/internal/xds/cache package into dedicated sub-packages: - snapversion: the xDS snapshot version-string generator (was version.go). Depends only on go.uber.org/atomic. - cachemetrics: the snapshot-generation OTel instruments (was metrics.go). Depends only on the OTel metric API; isolates that dependency (and the sdk/metric test dep) from the root package. The stateful SnapshotCache core stays in the root package unchanged: a naive per-resource split does not compile because nearly every builder is a *SnapshotCache method sharing cross-cutting mutexes (depMu spans 6 files, listenerMu 6, clusterMu 5, localMu 5) and maps, all read under the single generateSnapshot orchestrator. The heavy per-resource Envoy builders already live in the sibling agent/internal/xds/proxy package (28 files). snapshotMu semantics, the unified full-snapshot model, the clusterMu->localMu lock order (#548), and the dep/route memo semantics (#549/#551) are untouched. Tests move with their code (version_test.go -> snapversion, metrics_test.go -> cachemetrics); coverage is identical. No behavior change. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01EioJVuoepwStjHoRLB52WR
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #544.
Mechanical, no-behavior-change package split of
agent/internal/xds/cache. After mapping the whole package I extracted the two Envoy-proto-free, self-contained infrastructure concerns into dedicated sub-packages and left the statefulSnapshotCachecore in the root, because a per-resource split does not compile without a rewrite (see rationale below).What moved
cache/snapversionversion.go(generateSnapshotVersion→snapversion.Generate)go.uber.org/atomiccache/cachemetricsmetrics.go(cacheMetrics→cachemetrics.Metrics, exported ctor + methods)metricAPITests moved with their code (
version_test.go→snapversion,metrics_test.go→cachemetrics); coverage is identical — no test case dropped. The rootgo_libraryno longer depends onotel/metric, and the rootgo_testno longer pullsotel/sdk/metric+atomic— those are now isolated in the two sub-packages.Why not a full per-resource split
The package is one
SnapshotCachestruct whose methods share cross-cutting mutexes and maps:depMu→ 6 files,listenerMu→ 6,clusterMu→ 5 (incl.mtls.go),localMu→ 5,secretMu/subsetMu/edgeMu→ 3 each.subsetMu/secretMuare written in one file but read inside the singlegenerateSnapshotorchestrator (snapshot.go), so their state cannot leave the root without cross-package lock coordination in the hottest path.VirtualHost,Route,RouteBackend,EdgeGatewayEntry,EdgeTLSCert) areSnapshotCachefields and the public API consumed by the externalagent/internal/edge/gatewayapireconciler + its tests (thesinkinterface). Moving them (and their boundequal*comparison helpers) would create a wide external blast radius and risk an import cycle (root imports the type; the helpers can't import root) — exactly the risk refactor(xds): split agent/internal/xds/cache into per-resource sub-packages #544 warns against.agent/internal/xds/proxypackage (28 files, each importing only the protos it needs). Thecachepackage is the stateful orchestrator overproxy.So the largest safe split is the two infra concerns above.
Preserved exactly
snapshotMuserialization semantics, the unified full-snapshot model, theclusterMu(outer)→localMu(inner) lock order (#548), and the dependency/route memo semantics (#549/#551). No lock acquisition was reordered; no builder logic changed.Testing
bazel build //...— pass.bazel test --@rules_go//go/config:race=true --build_tests_only //agent/... //agent/internal/xds/...— all cache targets pass (cache_test,cachemetrics_test,snapversion_test,proxy_test, ...). One unrelated failure,//agent/internal/cni/server:server_test(TestHandlePodTerminatingPoolClosePhase), reproduces identically on the clean base commit under-raceand is in a package this PR does not touch.make gazelle+make formatclean.🤖 Generated with Claude Code
https://claude.ai/code/session_01EioJVuoepwStjHoRLB52WR