Skip to content

feat(nat): Report port usage and dispatcher lease - #848

Merged
privateip merged 1 commit into
mainfrom
feat/nat-port-usage-lease-metrics
Oct 12, 2026
Merged

privateip merged 1 commit into
mainfrom
feat/nat-port-usage-lease-metrics

Conversation

@privateip

@privateip privateip commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

On-call learned a shard was out of masquerade ports only once new connections were already failing, and learned its dispatcher lease had stopped renewing only when the shard began passing traffic untranslated.

Shards now report, for each masquerade address and protocol, how many ports are held and how many toward the busiest single destination, which is what runs out first, and both the shard and the edge gateway report every lease renewal and when the lease expires, with three alerts on them.

Nothing changes on the packet path: port usage comes from the session table walk each scrape already does, and the lease series cost three per dispatcher slot, while the port series cost six per masquerade address plus one.

This is stacked on #847, and infra's central rule copy needs the three alerts and their runbook sections too.

Test plan

  • Ports held toward one destination count once per port, a walk that revisits rows does not inflate them, and every served address and protocol reports zero when idle
  • The port alert warns at half a destination's range, where about 0.4% of new flows fail, rather than after failures start
  • A transient renewal error fires nothing, and a lease with no successful renewal in two minutes pages
  • On the lab both binaries serve the lease series, and the NAT collision check raises the serving shard's port gauges

Related to #722

🤖 Generated with Claude Code

@privateip privateip self-assigned this Oct 12, 2026
@privateip

Copy link
Copy Markdown
Contributor Author

New series and alerts:

recommendation 2   galactic_nat_masquerade_ports_in_use{family, address, proto}
                   galactic_nat_masquerade_destination_ports_max{family, address, proto}
                   galactic_nat_masquerade_port_range
recommendation 4   galactic_nat_dispatch_lease_renewals_total{slot, result}
                   galactic_nat_dispatch_lease_expiry_timestamp_seconds{slot}
                   galactic_edge_dispatch_lease_* (same pair, edge gateway's slots)
alerts             GalacticNatPortsNearExhaustion, GalacticNatDispatchLeaseFailing,
                   GalacticNatDispatchLeaseExpiring

Why per destination. A reverse session row is keyed by the reply as it arrives, so a masquerade port is claimed per destination address and port, and a claim probes 8 of the 28000 candidates. Ports held across all destinations can sit near the range on a healthy shard, so the alert reads the busiest destination instead. With a share u of that destination's ports held, a new flow fails with probability about u^8, which is 0.4% at half full and 17% at 80%, so the warning sits at half full.

Why the expiring alert reads the renewal counter. The expiry timestamp is the node's wall clock, and comparing it with the evaluator's time() would page on clock skew alone. The alert fires when no renewal has succeeded for a minute and a half, about 30 seconds before the 120-second lease lapses.

The dispatch lease series exist only in dispatch mode. Lease now reports every renewal's result to its callback, success included, and both callers are updated.

@privateip
privateip force-pushed the feat/nat-port-usage-lease-metrics branch from 46a4b73 to 24b492a Compare October 12, 2026 18:44
GalacticNatPortExhausted fires only once new flows are already failing,
and a dispatcher lease that stopped renewing showed only in an error log
until the slot lapsed and the shard passed traffic untranslated.

A masquerade port is claimed per destination address and port, and a
claim probes 8 candidates, so exhaustion is a property of the busiest
destination, not of the address as a whole. The session table walk now
reports, per family, masquerade address and protocol, the distinct
ports held and the most held toward one destination, against the
range, with every served address reported at zero.

The lease loop is shared by galactic-nat and galactic-gateway, so its
metrics live in xdpdispatch and each binary registers them under its
own namespace. Lease now reports every renewal's result, success
included.

Alerts: GalacticNatPortsNearExhaustion at half the range toward one
destination, GalacticNatDispatchLeaseFailing and
GalacticNatDispatchLeaseExpiring, with promtool tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@privateip
privateip force-pushed the feat/nat-port-usage-lease-metrics branch from 24b492a to fce3d6d Compare October 12, 2026 18:45
@privateip
privateip marked this pull request as ready for review October 12, 2026 19:02
@privateip
privateip requested a review from a team as a code owner October 12, 2026 19:02
scotwells
scotwells previously approved these changes Oct 12, 2026
Base automatically changed from feat/nat-translated-traffic-metrics to main October 12, 2026 19:07
@privateip
privateip dismissed scotwells’s stale review October 12, 2026 19:07

The base branch was changed.

@privateip
privateip requested a review from scotwells October 12, 2026 19:16
@privateip
privateip merged commit 54db1d3 into main Oct 12, 2026
15 checks passed
@privateip
privateip deleted the feat/nat-port-usage-lease-metrics branch October 12, 2026 19:22
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.

2 participants