Skip to content

feat(nat): Count session creation and claim probes - #849

Merged
privateip merged 1 commit into
mainfrom
feat/nat-session-control-metrics
Oct 12, 2026
Merged

privateip merged 1 commit into
mainfrom
feat/nat-session-control-metrics

Conversation

@privateip

Copy link
Copy Markdown
Contributor

Summary

On-call could see port pressure only as the busiest destination's share, and a shard whose uplinks failed to re-resolve after a link change kept stale coverage with nothing but a log line to show it.

Shards now count every new session by family and protocol, and how many port probes each claim took, which estimates how full busy destinations are well before any of them runs out, plus failed uplink re-resolutions.

This covers the review's two second-tier items at one counter increment per new session and nothing per packet, adding 55 series per shard, and it documents that the reconciler's controller metrics were already served on the shard's metrics port.

It is stacked on #848, and adds no alerts, since the review proposed none for these.

Test plan

  • A new session counts one claim in its family, protocol and probe count, and the same session's later packets count nothing
  • Every family, protocol and probe count is reported, zero included, and creates equal the sum over probe counts
  • On the lab the NAT egress and collision checks raise the serving shards' create counters
  • Lint, unit and privileged datapath tests pass

Related to #722

🤖 Generated with Claude Code

Port pressure showed only as the busiest destination's share once
sessions had piled up, and a shard whose uplinks failed to re-resolve
after a link change logged it and kept stale coverage with no metric.

nat_claims, a per-CPU array of 48 slots (family x protocol x probes),
counts every new session's masquerade port claim by how many of its 8
candidates it probed, at one increment per new session and nothing per
packet. A claim that adopts a live session's lost port opens no session
and is not counted. galactic_nat_session_creates_total sums it per
family and protocol, and galactic_nat_masquerade_claim_probes_total
keeps the distribution: with a share u of a destination's ports held, a
claim needs more than k probes with probability u^k, so the share above
one probe estimates fill before any destination nears exhaustion.

galactic_nat_uplink_resolve_errors_total counts failed uplink
re-resolutions. The EgressShard reconciler's controller-runtime metrics
were already served on the same port; the docs now say so.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@privateip privateip self-assigned this Oct 12, 2026
@privateip

Copy link
Copy Markdown
Contributor Author

New series:

recommendation 5   galactic_nat_session_creates_total{family, proto}
                   galactic_nat_masquerade_claim_probes_total{family, proto, probes=1..8}
                   new pinned map nat_claims (48 slots), no existing map changes layout
recommendation 6   galactic_nat_uplink_resolve_errors_total
                   controller_runtime_reconcile_total{controller="egressshard"},
                   controller_runtime_reconcile_errors_total, workqueue_* (already on :9182)

Why a distribution rather than one "more than N probes" counter. A claim probes up to 8 consecutive candidates, so with a share u of a destination's ports held it needs more than k probes with probability of roughly u^k. N=1 is the most sensitive early sign, since the share of claims needing more than one probe approximates how full the destinations taking new flows are. Keeping the whole distribution lets any N be read at query time for 48 series, and docs/metrics.md gives the N=1 query.

A claim that adopts a live session's lost port opens no session and is not counted. A claim that finds no port is a *_pat_exhausted drop, already counted there.

@privateip
privateip marked this pull request as ready for review October 12, 2026 19:01
@privateip
privateip requested a review from a team as a code owner October 12, 2026 19:01
scotwells
scotwells previously approved these changes Oct 12, 2026
Base automatically changed from feat/nat-port-usage-lease-metrics to main October 12, 2026 19:22
@privateip
privateip dismissed scotwells’s stale review October 12, 2026 19:22

The base branch was changed.

@privateip
privateip requested a review from scotwells October 12, 2026 19:22
@privateip
privateip enabled auto-merge October 12, 2026 19:23
@privateip
privateip merged commit def1ec4 into main Oct 12, 2026
15 checks passed
@privateip
privateip deleted the feat/nat-session-control-metrics branch October 12, 2026 19:26
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