Documentation
¶
Overview ¶
Package caddymod holds AerolVM's Caddy plugins.
http.reverse_proxy.upstreams.aerolvm_route finds a sandbox host's upstream by asking the sandboxd route responder (internal/routedns) for its A record. It replaces Caddy's stock "a" source on the owner's static sandbox route (pkg/caddy/static_routes.go), where every sandbox request looks up its upstream. The stock source does not hold up there:
- its cache is process-wide and holds 100 names. Past that it thrashes, and every request becomes a lookup;
- every lookup runs under one process-wide write lock, so every request, cache hits included, waits behind it;
- a failed lookup is never cached, and is logged at ERROR. NXDOMAIN is the responder's normal answer for WASM/isolate, masked, waking and in-flux hosts (the router serves them), so each of their requests was a lookup under that lock and an error line;
- it asks for A and AAAA, and the responder only answers A.
With Caddy 2.11.9 and 64 callers that was 2.4M lookups/s at 100 hosts, 27k at 150 and 4.9k at 1,000, for the whole node.
This source keeps a cache per route, sized for a node and split into shards, so a lookup for one host never waits on another host. One lookup per host is in flight at a time. A host the responder does not answer is cached like any answer and served the fallback upstream (the router) directly, with no error.
Index ¶
Constants ¶
const ( SourceName = "aerolvm_route" SourceModuleID = "http.reverse_proxy.upstreams." + SourceName AdminModuleID = "admin.api." + SourceName // AdminPath answers 200 on a Caddy built with this package. sandboxd // asks it before it writes a route that names the source: the route // goes in with one batched /load, and an unknown module would fail the // whole load. AdminPath = "/aerolvm/route-upstream" )
The contract with sandboxd (pkg/caddy/static_routes.go).
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RouteUpstreams ¶
type RouteUpstreams struct {
// Name is the name to look up, with placeholders: "{http.request.host}.".
Name string `json:"name,omitempty"`
// Port is the upstream port, with placeholders: "{sbport}".
Port string `json:"port,omitempty"`
// Resolver is the route responder's UDP host:port.
Resolver string `json:"resolver,omitempty"`
// Fallback is the dial address for a host the responder does not
// answer (NXDOMAIN, or no A record): the sandboxd router.
Fallback string `json:"fallback,omitempty"`
// Refresh is how long an answer, found or not, is reused. Default 1s:
// a moved sandbox is routed to its new address within about a second.
Refresh caddy.Duration `json:"refresh,omitempty"`
// MaxEntries caps the cache. Default 16384, about 4 MiB when full.
MaxEntries int `json:"max_entries,omitempty"`
// contains filtered or unexported fields
}
RouteUpstreams is the upstream source. All four strings are required.
func (RouteUpstreams) CaddyModule ¶
func (RouteUpstreams) CaddyModule() caddy.ModuleInfo
CaddyModule returns the Caddy module information.
func (*RouteUpstreams) Cleanup ¶
func (ru *RouteUpstreams) Cleanup() error
Cleanup drops the cache from the admin counters.
func (*RouteUpstreams) GetUpstreams ¶
func (ru *RouteUpstreams) GetUpstreams(r *http.Request) ([]*reverseproxy.Upstream, error)
GetUpstreams returns the one upstream for the request's host.