Skip to content

feat(nat): Count NAT translations and shard state - #847

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

privateip merged 1 commit into
mainfrom
feat/nat-translated-traffic-metrics

Conversation

@privateip

@privateip privateip commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

An egress shard reported what it dropped but not what it translated, so on-call could not compute a drop ratio or tell a quiet broken shard from an idle one.

Whether a shard was programmed or covered all its uplinks showed only in its logs.

The shard now counts translated packets and bytes by family and direction, reports whether it is turned on, attached and programmed and which uplinks it covers, and four alerts use them, at one counter update per translated packet and at most 16 traffic series, six state series and one per uplink for each shard.

The alerts need the same change in infra's central rule copy plus four runbook sections, and the first comment lists every new series and alert and the merge order against other open PRs.

Test plan

  • Each translated leg counts once in its own family, direction and action, and the shard's own error messages count nothing
  • A turned-off shard reports itself off rather than broken, with no coverage series
  • On the lab every edge node serves the new series, and the NAT egress check moves the serving shard's outbound and return counters
  • Lint, unit, privileged datapath and alert rule tests pass

Related to #722

🤖 Generated with Claude Code

@privateip privateip self-assigned this Oct 12, 2026
A shard reported its drops, session table and uplink queues, but nothing
it translated successfully, so a drop ratio could not be computed and a
shard that stopped receiving traffic read the same as an idle one.
Whether it was attached, programmed or covering every uplink showed only
in its logs.

- nat_traffic, a per-CPU array of 8 slots (family x direction x
  action), counts every packet a leg translates as it leaves, in one
  slot update. Messages the shard sends on its own behalf and packets
  it passes on unclaimed are not counted.
- galactic_nat_packets_total and galactic_nat_bytes_total export it,
  bytes being the translated IP packet without Ethernet or the SRv6
  outer header.
- A state collector, registered whether or not the datapath is on,
  exports datapath_enabled, datapath_attached, programmed,
  uplink_covered{interface}, family_enabled{family} and info.
- Alerts: GalacticNatNotProgrammed, GalacticNatUplinkUncovered,
  GalacticNatForwardDropRatio and GalacticNatNotTranslating, with
  promtool tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@privateip
privateip force-pushed the feat/nat-translated-traffic-metrics branch from 58999ad to 7261dd4 Compare October 12, 2026 18:27
@privateip privateip changed the title feat(nat): Count translated traffic and shard state feat(nat): Count NAT translations and shard state Oct 12, 2026
@privateip

Copy link
Copy Markdown
Contributor Author

New series and alerts:

recommendation 1   galactic_nat_packets_total, galactic_nat_bytes_total
                   {family, direction=outbound|return, action=redirect|tx}
                   new pinned map nat_traffic (8 slots), no existing map changes layout
recommendation 3   galactic_nat_datapath_enabled, galactic_nat_datapath_attached,
                   galactic_nat_programmed, galactic_nat_uplink_covered{interface},
                   galactic_nat_family_enabled{family},
                   galactic_nat_info{shard_sid, nat64_prefix, xdp_attach, version}
alerts             GalacticNatNotProgrammed, GalacticNatUplinkUncovered,
                   GalacticNatForwardDropRatio, GalacticNatNotTranslating

A failed read of the translated traffic map or the drop map is now logged and its series skipped, rather than reported as an invalid metric. The metrics server turns an invalid metric into a failed scrape of every other series, the shard's state included. While a read fails, the drop-ratio alert sees no drops for that shard.

Merge order. #597 adds a map and metrics to the same NAT program and collector, and #580 and #613 edit the NAT configuration doc. Whichever lands second needs a rebase, and the infra rule copy and runbook sections should land the same day as this. Port usage, the dispatcher lease, session creation and the control loop follow in PRs stacked on this one.

@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
@privateip
privateip enabled auto-merge October 12, 2026 19:02
@privateip
privateip merged commit c009eb5 into main Oct 12, 2026
15 checks passed
@privateip
privateip deleted the feat/nat-translated-traffic-metrics branch October 12, 2026 19:07
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