Skip to content

refactor(vrf): Create ingress sidecar metrics with the library - #1187

Merged
privateip merged 2 commits into
fix/issue-1149-gateway-natfrom
fix/issue-1149-ingress
Oct 28, 2026
Merged

privateip merged 2 commits into
fix/issue-1149-gateway-natfrom
fix/issue-1149-ingress

Conversation

@privateip

@privateip privateip commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The ingress sidecar built seven metric types unregistered and registered each on controller-runtime's registry at startup, so the instrumentation library's checks skipped them.

They are now created by the library, and the three custom collectors register through it once per process.

The library keeps a series across constructions, so each constructor now starts its series over, which keeps every test reading only the series it set up.

Stack

Merge in order:

  1. refactor(cni): Create datapath metrics with the instrumentation library #1184 CNI datapath, onto main
  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 (this PR)
  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

The sidecar endpoint exports the same families as before. Rolling back restores the previous code with no other effect.

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 every series the sidecar creates is identical before and after.
  • The sidecar's tests pass with repeated, shuffled and race-checked runs.

Related to #1149

🤖 Generated with Claude Code

privateip and others added 2 commits October 28, 2026 10:22
The ingress sidecar built seven metric types unregistered and
registered each on controller-runtime's registry at startup, so the
instrumentation library's reserved-label check and lint skipped them.

- Every counter, gauge and histogram is created by the library's
  constructors. The library's registry keeps a series across
  constructions, so each constructor starts its series over, as an
  unregistered value used to: vectors are reset, gauges set to their
  initial value, and the label-free counters and histograms are held
  as vectors with no labels so they can be reset too.
- The three types that own a custom collector (startup stage, datapath
  check and node source address status) keep a MustRegister method,
  now without a registry, which registers it through the library once
  per process. The other MustRegister methods are gone.
- galactic-vrf creates all of them in newSidecarMetrics, which its
  scrape test also calls, so the test scrapes and lints every series
  the sidecar serves.

Tests register a type's collectors on their own registry, as before,
so each reads only the series it set up. The endpoint exports the same
series as before.

Refs: #1149

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
newSidecarMetrics registers three custom collectors, which a process
can register once, as runCmd does. TestMetricsScrape called it on every
run, so a second run in the same test process, such as go test
-count=2, panicked on the duplicate. Its setup now runs once.

Refs: #1149

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@privateip
privateip force-pushed the fix/issue-1149-ingress branch from 8cdeb49 to be404a1 Compare October 28, 2026 14:22
@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
scotwells
scotwells previously approved these changes Oct 28, 2026
ecv
ecv previously approved these changes Oct 28, 2026

@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.

All galactic_sidecar_* series keep their names, labels and buckets. Counters and histograms that had no labels are now created as zero-label vectors and re-fetched with WithLabelValues(), which exposes the identical un-labelled series at zero.

  • Each constructor does its Reset() before seeding the label values, so the zero-valued series that rate queries rely on are still present at startup.
  • The status collectors (stageStatus, datapath status, node-source check) are still registered once, via MustRegister.
  • Re-running a constructor resets the shared series and detaches the earlier handle. Safe because runCmd builds them once, but a second call in production would silently orphan the counters in use.

@privateip
privateip merged commit 23de5d9 into main Oct 28, 2026
23 checks passed
@privateip
privateip dismissed stale reviews from ecv and scotwells October 28, 2026 15:06

The merge-base changed after approval.

@privateip
privateip deleted the fix/issue-1149-ingress 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