Skip to content

refactor(cni): Create datapath metrics with the instrumentation library - #1184

Merged
privateip merged 2 commits into
mainfrom
fix/issue-1149-cni
Oct 28, 2026
Merged

privateip merged 2 commits into
mainfrom
fix/issue-1149-cni

Conversation

@privateip

@privateip privateip commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The CNI daemon served its datapath metrics from a private registry, and every binary registered the netlink listing counters on whatever registry it passed in, so the instrumentation library's reserved-label check and lint never saw them.

Both now go through the library, and the CNI daemon serves the library's handler.

This is the first of seven layers that move every Galactic metric onto the library, one subsystem each.

Stack

Merge in order:

  1. refactor(cni): Create datapath metrics with the instrumentation library #1184 CNI datapath, onto main (this PR)
  2. refactor(router): Create router metrics with the instrumentation library #1185 router, onto refactor(cni): Create datapath metrics with the instrumentation library #1184
  3. refactor(gateway,nat): Create metrics with the instrumentation library #1186 gateway and NAT, onto refactor(router): Create router metrics with the instrumentation library #1185
  4. refactor(vrf): Create ingress sidecar metrics with the library #1187 ingress sidecar, onto refactor(gateway,nat): Create metrics with the instrumentation library #1186
  5. refactor(edge): Create edge metrics with the instrumentation library #1188 edge, onto refactor(vrf): Create ingress sidecar metrics with the library #1187
  6. refactor(fabric): Create fabric routing metrics with the library #1189 fabric routing, onto refactor(edge): Create edge metrics with the instrumentation library #1188
  7. refactor(fabric-api): Create metrics with the instrumentation library #1190 fabric-api, onto refactor(fabric): Create fabric routing metrics with the library #1189

Compatibility

Every existing CNI series keeps its name, labels and type. The endpoint also gains the build-info series and about 150 standard Go runtime, process and controller-runtime families from the shared registry, which the private registry left out. No scrape config caps samples.

Rolling back restores the previous endpoint. No state is persisted.

The draft #598 edits two of the CNI files this layer changes. Whichever lands second rebases, and #598's new metrics then go through the library to pass the adoption test.

Test plan

  • Lint, build, unit and alert rule tests pass on this layer. The end-to-end and root-only suites run in CI.
  • A series inventory of the CNI endpoint before and after this change shows every earlier family unchanged.
  • Tests that read the shared registry pass with repeated and shuffled runs.

Related to #1149

🤖 Generated with Claude Code

The CNI run daemon served a private registry, and the netlink listing
counters were registered by every binary on whatever registry it
passed in. Neither went through go.miloapis.com/instrumentation, so
the reserved-label check and its lint never saw them.

- internal/plumbing/ebpf/metrics creates its counters and gauges with
  the library's constructors and registers the map collectors with
  metrics.MustRegister. Metrics no longer carries a registry or a
  handler, and the run daemon serves metrics.Handler.
- The endpoint snapshot collector is shared by every SidecarReturn,
  because a collector can be registered only once per process.
- The nldump counters are created when the package loads. Every
  binary that serves metrics and links nldump registered them before,
  so the explicit MustRegister calls are gone.
- Registering the map collectors can no longer fail at run time; a
  descriptor clash now panics at startup instead of being logged.

Series names, labels and types are unchanged. The CNI endpoint now
also exports instrumentation_build_info and the standard Go runtime,
process and controller-runtime series that controller-runtime's
registry carries, which the private registry did not.

Tests read the shared registry and check how much a counter changed,
so repeated runs and other tests can't change their result. The CNI
scrape test creates the run daemon's series first and lints them.

Refs: #1149

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The root-only suite runs the CNI daemon against a real datapath, which
registers the map collectors on the shared registry and closes their
maps when it stops. A later test in the same process that gathered the
whole registry then failed on those collectors' errors, as the sidecar
return and egress group route tests did.

Those tests now read only the families under the prefix they check,
and fail on a collection error only from one of those families.

Refs: #1149

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@privateip
privateip marked this pull request as ready for review October 28, 2026 14:58
@privateip
privateip requested a review from a team as a code owner October 28, 2026 14:58
@polylane

polylane Bot commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

Warning

Polylane could not verify the production impact of this pull request.

I checked the production account: the only Galactic workload deployed is fabric-identity-system/galactic-controller-fabric, which does not link the changed packages. No galactic-cni, router, NAT, gateway, edge or vrf workload runs in datum-cloud-prod.

View the full analysis →

Also considered · 5 refuted
  • Refuted · Duplicate registration turns the CNI daemon's logged warning into a startup panic · rg over non-test code finds one call site for each register function and one NewMetrics call per process; there is no retry or restart loop that re-runs startEBPFDatapath, so a second registration cannot occur and the panic path is unreachable.
  • Refuted · Run daemon serves a handler whose registry differs from the one the library writes to · Handler() and the constructors resolve to the same controller-runtime registry, and existing series names, labels and types are unchanged; the added scrape test lints exactly the handler the daemon serves.
  • Refuted · Netlink dump counters stop being exported by the five commands that dropped MustRegister · Registration moved from an explicit startup call to package load on the same registry the metrics servers serve, so the exported families are unchanged in every command.
  • Refuted · The shared sidecar-return snapshot loses the last pass each time it is constructed · Production has one construction per process, and the tests now compare before and after values instead of absolute counters, so the reset cannot happen where a scrape observes it.
  • Refuted · The shared registry makes the CNI scrape fail on a collector error and blinds every CNI series · No erroring collector is added to the served registry: the change is additive sample count plus collectors already served, and no scrape config caps samples.
Analysed against 1 cloud account and 1 repository

View in Polylane Pause assessments

Polylane could not find the cloud resources this repository manages, so this review looked at the entire cloud account. Connect this repository to its resources and the next review will focus on exactly what this code deploys to.

Connect resources

Polylane analysed 9ad5db2 for production impact. You can ask follow-ups by mentioning @polylane in a comment.

Did this help? React 👍 or 👎 so the next review is sharper.

@ecv ecv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve.

Every datapath, egress-control, sidecar-return, endpoint-slice-repair, event and nldump series keeps its name, type, labels and help; the library adds no prefix or suffix and no constant labels, and galactic-cni run serves the same registry it now creates on. CI is green.

  • galactic-cni /metrics now also carries the Go and process series, instrumentation_build_info and any client-go series, because it serves the shared registry instead of a private one. All additive; nothing in infra queries the old absence.
  • RegisterDatapathCollector and RegisterEgressShardCollector now MustRegister, so a descriptor clash panics the daemon at startup where it used to log a warning and run without datapath metrics. Same collectors and names as before, so no clash exists today.
  • The plugin ADD/DEL binaries never built metrics.New(), so they lose nothing; only the run daemon exports.

Follow-ups:

  • Binaries that link nldump without having called MustRegister (for example fabric-config-agent, galactic-controller) now export zero-valued galactic_netlink_dump_* series. Harmless, but worth knowing if cardinality is ever audited.

@privateip
privateip merged commit 23de5d9 into main Oct 28, 2026
23 checks passed
@privateip
privateip deleted the fix/issue-1149-cni branch October 28, 2026 15: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.

3 participants