Repository navigation
feat(fabric-api): Enforce aggregate probe budgets across every caller - #1115
Conversation
Nothing bounded the probe traffic a cell sends as a whole. The executor's slots and each node's packet pacer are local, operator probes sent straight to a node bypass the gateway entirely, and the Looking Glass service had no request rate, duplicate check, live-stream cap or per-project share. The service contract requires all of these before customer execution can be enabled. With the gateway's new --aggregate-budgets flag, the elected leader holds the contract's budgets in bounded memory (internal/fabric/gateway/limit). Each RunDiagnostic is charged one token from the cell and one from its project, its request ID is recorded so a repeat is DuplicateRequest or DuplicateConflict, it counts against 16 live streams per cell and 2 per project, and all its selected routers are reserved in the queue together or refused with QueueFull before the snapshot is sent. Each principal (a service project, a FabricQuery source, an operator) holds at most 2 executor slots and 32 queued jobs, served round robin. Every probe, whoever sends it, is charged its worst case (ping 3 packets, traceroute 20) to the cell, its principal, the destination host and the destination /24 or /64, all or nothing and never refunded. Refusals carry ErrorInfo scope and RetryInfo; a refused router in a stream carries the same in new Failure fields. The leader reads the election Lease uncached, bounded to 1 s, before every admission and probe and once a second besides. It holds its election under its own identity (<pod>_<uuid>) so it can recognise the Lease as its own. On start, on taking over, and after any failed read it admits nothing for 125 s, then starts every bucket empty, so neither a failover nor a lost read can reset or bypass the budgets. Losing the Lease cancels running service work, and the stream ends with OwnershipLost after every selected router's outcome. A caller cancelling during the read affects only that caller. Each probe carries a ProbePermit bound to the Lease epoch, its node, request, destination, operation, packet allowance and a deadline at most 30 s away. A node run with --probe-permits consumes each permit once, re-reads the Lease to confirm the epoch, refuses every permit for 32 s after it starts, and sends nothing past the permit's packets or deadline. It reports probe_permits in Info, and the gateway sends probes only to nodes that do. With --require-probe-permits a node refuses probes without a permit, and an operator's direct probe first obtains one from the gateway's new node-only PermitService, charged to that operator; its slot is held until the node releases it or the permit expires plus 2 s. A probe whose node answer was lost holds its slot the same way. FabricQuery keeps its own fairness key, its source namespace and cluster, since it carries no project UID; the contract now says so. GetCapabilities advertises aggregate-probe-budgets and the effective limits only while execution is enabled with admission, since direct operator probes are charged only once every node requires permits. Every flag defaults off and the service stays disabled, so nothing changes until a cell opts in. Once enabled, operator and FabricQuery probes can be throttled and are refused for about two minutes after each gateway restart or failover; reads are unaffected. The rates and caps are the contract's defaults, and only --cell-slots and --cell-queue lower them. Deployment manifests, RBAC and limit flags are left to #1047. Tests cover token and queue refusals with retry guidance, duplicate attempts, the stream caps, atomic queue reservation, the packet envelope across mixed projects in one prefix, every caller type sharing one cell budget, fairness for five projects and a FabricQuery source behind a full executor, the recovery hold, ownership loss within 2 s, caller cancellation, permit replay, epoch, startup and allowance checks on the node, and permit service authorization and forwarding. Related to #1045
Discovery that ends because the election was lost now returns OwnershipLost rather than Cancelled. A permit call from the gateway identity that reaches a replica that is not elected is refused with OwnershipLost instead of forwarded again, matching the service forwarder. FabricQuery budget keys take a fabricquery/ prefix so a FabricQuery in namespace operator cannot share an operator's key. The traceroute packet cost is hops times probes per hop. The limit package comment states its contract itself. The docs say a direct operator probe is charged only on nodes running both --probe-permits and --require-probe-permits.
|
Review record for this PR, two passes. Pass 1 at 9d1ed70. pr-adversary: VERDICT merge, with a warning that direct operator probes are charged only on nodes running both --probe-permits and --require-probe-permits, and a nit that traceroute cost should multiply probes per hop. Decisions on node manifests and unverified end-to-end behaviour were settled by keeping node packaging with #1047. pr-conventions-reviewer: VERDICT hold, over a decision that the docs collide with open docs PR #1111, a warning that the package doc linked to another document, and a nit on commit subject length. Fix commit a179ca1: the limits package doc now states its contract, traceroute cost multiplies probes per hop, the docs state the operator-probe dependency, election loss during discovery reports OwnershipLost, a forwarded permit call is never forwarded again, and FabricQuery principals are prefixed so they cannot collide with operators. Pass 2 at a179ca1. pr-rereviewer confirmed the five fixes with tamper tests (removing each fix makes its new test fail) and held only on PR body wording, which was then fixed. pr-conventions-reviewer: VERDICT merge, with warnings addressed in the body (the election identity changes for every gateway); folding the fix commit and shortening subjects were left as is, since main keeps merge commits. CI: every check on the head passed (build, lint, unit, root unit, e2e, image and bundle publishing); publish-service-api is skipped as release-only. Docs PR #1111 restructures the same fabric-api docs, so whichever lands second must port the other's doc changes. Auto-merge is enabled with the merge method, the only one the ruleset allows. The ruleset requires a code owner approval of the last push, so it waits for a human approval. |
ecv
left a comment
There was a problem hiding this comment.
Approve.
With --aggregate-budgets off the gateway behaves as before, apart from the election identity. The enforcement path is sound: one Lease epoch gates admission, permits are single-use and bound to node, request, operation, destination and epoch, and a failover or lost read starts a 125 s recovery hold instead of resetting budgets.
- The election now always runs under
<pod>_<uuid>.debug.goalready derives the leader pod withstrings.Cut(holder, "_"), so leader forwarding keeps working.LeaderElectionReleaseOnCancelis kept. - The customer service stays disabled:
Enabledis unset ingateway.go, andService.Enabledis now also gated onAdmission != nil. Theaggregate_probe_budgetsfeature is only advertised when both are set. - Nodes without
--probe-permitsrefuse a probe that carries a permit, and a gateway with the flag refuses nodes that do not reportprobe_permits(QueryTypeUnavailable). Node rollout must precede the gateway flag, as the flag text says. - Slot release for probes whose node answer was lost is held to the job deadline plus 2 s, so a lost reply cannot oversubscribe a node.
Follow-ups:
- Once a cell opts in, any failed or slow Lease read (an API blip) restarts the 125 s hold and refuses all probes for that cell, including operator probes. Consider tolerating a short run of failed reads before dropping the epoch.
- Every probe costs an uncached Lease GET on the gateway and another on the node, plus a 1 s
Watchpoll. Check API server load in staging before enabling widely. - Nothing is refunded once charged, so a node refusal after a permit is issued still spends packets. Retry delay on
QueueFullis a constant 1 s. - Nodes need RBAC to get the gateway Lease, and the manifests that pass the new flags are not in this PR.
Summary
Nothing bounds the probe traffic a cell sends as a whole, and operator probes sent straight to a node skip the gateway entirely.
With a new opt-in gateway flag, the elected gateway rate-limits Looking Glass requests, schedules every caller fairly by project, FabricQuery source or operator, and charges each probe's worst-case packets to the cell, its caller and the destination before it runs.
Nodes that verify permits accept only single-use probe permits tied to the current gateway leader, so a failover or a lost limiter cannot reset the budgets, and nodes that also require permits charge an operator's direct probe, which otherwise runs uncharged.
Every gateway now holds its election under a new per-process identity, but the budgets are off by default, the customer service stays disabled, and once a cell opts in, operator and FabricQuery probes can be throttled and are refused for about two minutes after each gateway failover.
Test plan
Fixes #1045
Related to #1047
Related to #1048