reverseproxy: move DNS SRV+A discovery into modules/internal/network#7790
reverseproxy: move DNS SRV+A discovery into modules/internal/network#7790tannevaled wants to merge 4 commits into
Conversation
9eb4ac3 to
b93be96
Compare
Move the SRV and A/AAAA resolution + caching logic out of reverseproxy into a new, transport-neutral package (dynamicupstreams) that returns neutral targets instead of *reverseproxy.Upstream. reverseproxy's SRVUpstreams and AUpstreams now delegate to it and build their own upstreams from the targets; behavior is unchanged. This lets other proxies (e.g. third-party layer4 proxies) reuse the same DNS discovery + caching instead of copying it, reducing duplication and maintenance burden. reverseproxy/upstreams.go shrinks substantially. RFC for the de-duplication discussed in caddyserver/caddy-l4#429.
b93be96 to
5d83b60
Compare
…und, concurrent refresh Brings the package to 96.8% statement coverage. Adds: - TestResetAllSRV: full-cache drop - TestSRVFilteredRecords: LookupSRV partial-error semantics (usable records returned, error downgraded to a warning) - TestSRVCacheBound / TestACacheBound: eviction keeps the cache bounded at maxCacheEntries - TestSRVConcurrentRefreshDeduplicates / TestAConcurrentRefreshDeduplicates: two goroutines missing the read-lock fast path trigger only one lookup (verified under -race) The grace-period and filtered-records logs now use a level-enabled logger so the log-write branches execute. The only uncovered statements are the two double-checked-locking re-check returns, which are reachable solely in a narrow race window (the same untested idiom as reverseproxy's SRV/A).
|
I don't think it should be a top-level package/directory, it has nothing to do with Caddy as a runtime specifically. We typically put things in I would say this would end up becoming a package in So I'm thinking we can probably just put it in |
checkout v4→v7, setup-go v5→v6, cache→v5, upload-artifact→v7, download-artifact→v8. Clears the deprecated Node.js 20 action runtime; all downloads are by name/pattern (no artifact-ids), so the v5 by-ID path change does not apply. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Per review feedback, the shared discovery code does not belong in a top-level package: it is internal helper code, not part of Caddy's runtime surface. Move it from the top-level dynamicupstreams package into the existing modules/internal/network package and update reverse_proxy's upstreams.go to consume it from there. Being under modules/internal means third-party modules (e.g. layer4) cannot import it yet; they keep their own copy until layer4 is part of Caddy's standard distribution, at which point they can switch over.
|
Thanks, that placement makes sense. Done: I moved it out of the top-level package into the existing Agreed that being under |
@francislavoie, is it possible we find an exportable place in the mainline code, so that the layer4 app could easily reuse this code before it gets merged? Same as you, I suggest we find a solution to avoid duplicating things. |
|
Happy to go whichever way you two prefer — it's a one-line move for me. One option that threads both concerns: keep it under If you'd rather keep it |
|
Thing is, it's not really a module, so that's my reticence here. I'd like to see l4 moved into Caddy sooner rather than later but I'm not actively maintaining this project |
|
I don't insist on moving the code into a new module either. Do you mind if we simply make some relevant types and functions exportable and reusable while keeping them within the |
What
Reverse proxy's dynamic-upstream DNS discovery (SRV and A/AAAA resolution, with caching/refresh/grace) was duplicated between
SRVUpstreamsandAUpstreams, and is the kind of logic third-party proxies want to reuse. This extracts it into a single shared place and refactorsreverse_proxyto consume it (behavior unchanged).Placement (per review)
Following @francislavoie's feedback, this is not a top-level package — it's internal helper code, not part of Caddy's runtime surface. It now lives in the existing
modules/internal/networkpackage, alongside the other shared network helper there.reverse_proxy'supstreams.gocallsnetwork.SRV(...)/network.A(...).Because it's under
modules/internal, third-party modules (e.g. layer4) can't import it yet, so they keep their own copy for now; they can switch over once layer4 is part of Caddy's standard distribution.Changes
modules/internal/network/dynamicupstreams.go: transport-neutralTarget+SRV(...)/A(...)with the existing caching/refresh/grace semantics, plusResetSRV/ResetAllSRV.modules/caddyhttp/reverseproxy/upstreams.go:SRVUpstreams/AUpstreamsdelegate to the shared functions (−177 lines of duplicated logic).-race).No change to
reverse_proxy's Caddyfile/JSON surface or behavior.