Skip to content

Create every metric through the instrumentation library #1149

Closed

Description

@privateip

Parent: #1144

Deliverable: Every Galactic metric is created through the instrumentation library, on the one registry each binary serves.

Today most metric constructors receive a registry as a parameter, and a few components (the CNI's datapath metrics, the fabric-api node sidecar, and the fabric config agent's next-hop check) serve a private registry. The library has one shared registry and refuses reserved label names at startup. Custom collectors that read datapath state at scrape time stay custom but register through the library.

This milestone can be split into one pull request per subsystem: CNI datapath, router, gateway and NAT, ingress sidecar, edge, fabric routing, and fabric-api.

Work items:

  • Replace direct metric construction and registration with the library's constructors, and custom collectors with its registration call.
  • Serve the library's handler wherever a binary serves metrics outside a controller-runtime manager, and merge private registries into it without changing any series name.
  • Rework tests that relied on a private registry per test, so they don't share series state across tests.
  • Remove each migrated directory from the adoption test's skip list.

Dependencies: #1148.

Acceptance: Every metrics endpoint serves the same series names and types as before, plus the build-info metric, and its scrape test passes. Alert rule tests pass unchanged. The adoption test passes with no metrics directory skipped.

Pull requests: one stack, merged bottom to top. #1192 fixes main and merges first.

Activity

  1. added
    tech-debt
    on Oct 27, 2026
  2. added theissue type on Oct 27, 2026
  3. self-assigned this
    on Oct 28, 2026
  4. privateip commented on Oct 28, 2026

    @privateip
    ContributorAuthor

    Confirmed on main at 1885f0f.

    With the pending skip list in internal/instrumentation/adoption_test.go emptied, go test ./internal/instrumentation -run 'TestAdopted|TestNoMetricsOutsideLibrary' fails with 171 findings in 35 files. These are the 19 pending directories plus internal/edge/diag/diagtest and internal/plumbing/nldump/nldumptest, which sit below pending directories. The unmodified suite passes.

    What the findings are:

    • Most metric types take a prometheus.Registerer and build collectors with prometheus.New*. The commands then register them on ctrlmetrics.Registry at startup.
    • Three components serve a private prometheus.NewRegistry(): the CNI run daemon (internal/plumbing/ebpf/metrics.New), the fabric config agent's next-hop guard (internal/fabricconfig.NewNextHopMetrics) and the fabric-api node sidecar (internal/fabric/node).
    • The fabric-router-controller and galactic-router register custom collectors directly with ctrlmetrics.Registry.Register.
    • The PSC fixture disables its manager's metrics server, which the library flags until a command in the module serves metrics.Handler.

    Two things beyond the issue text:

    • The edge foundation failure counters set a component constant label (internal/edge/diag/diag.go). The library's constructors refuse that label at startup, so it has to be renamed when those counters move. No alert rule or rule test reads it.
    • The provider and namespace labels on the edge and fabric routing state collectors, and on the traffic-policy node collector, are custom-collector labels, which the library doesn't check. They stay with Rename metric labels reserved by the collection pipeline #1150.
  5. privateip commented on Oct 28, 2026

    @privateip
    ContributorAuthor

    Plan, delivered as a stack of 7 pull requests. Each one moves one subsystem and removes its directories from pending.

    1. CNI datapath: internal/plumbing/ebpf/metrics, internal/plumbing/nldump, internal/installer, cmd/galactic-cni. The run daemon serves metrics.Handler(), which also takes tests/psc/fixture off the list.
    2. Router: internal/serviceroute, internal/gateway, cmd/galactic-router.
    3. Gateway and NAT: internal/plumbing/ebpf/xdpdispatch, cmd/galactic-gateway, cmd/galactic-nat.
    4. Ingress sidecar: internal/ingresssidecar, cmd/galactic-vrf.
    5. Edge: internal/edge/diag, cmd/galactic-edge, cmd/galactic-controller.
    6. Fabric routing: internal/fabricconfig, cmd/fabric-config-agent, cmd/fabric-router-controller.
    7. Fabric API: internal/fabric/gateway, internal/fabric/node, cmd/fabric-api. This one empties pending, and its PR closes this issue.

    How the code changes:

    • Each metric is still created in the constructor that the binary already calls at startup, now with the library's constructors. Collectors that read state at scrape time register with metrics.MustRegister.
    • Metrics don't move to package-level variables. Several of these packages are linked into binaries that never served their metrics, and some metrics only exist in one mode, so creating them at package load would add series to other endpoints. The exception is nldump, because every binary that serves metrics and links it already registers it.
    • Each binary's metric setup moves into a function that both main and its scrape test call. The scrape test then covers every series the binary creates at startup, not only the ones registered at package load.
    • Tests that used a private registry check the collector they exercise, or the change in its value, so tests don't share series state.

    Compatibility:

    • No series is renamed, removed or retyped. Every endpoint gains instrumentation_build_info.
    • The CNI daemon and the fabric config agent served a private registry with no Go runtime metrics. On the shared registry they also export the standard go_* and process_* series. The fabric-api node sidecar already exported those.
    • The edge foundation counters' component constant label is renamed, because the library refuses it at startup. No alert rule reads it. The release notes list the rename.
    • The gateway and the node sidecar both define fabric_api_certificate_expiry_timestamp_seconds and fabric_api_credentials_loaded with different help text. The help text is unified so both roles can share one definition.

    Validation per layer: task lint, task build, task test:unit and task test:alerts with no rule-test changes. task ci, which adds the end-to-end suite, runs on the final layer.

  6. privateip commented on Oct 28, 2026

    @privateip
    ContributorAuthor

    The fix is up for review as a stack of 7 pull requests, linked in order: #1184, #1185, #1186, #1187, #1188, #1189, #1190. The last one closes this issue.

    Two points differ from the plan above.

    The plan said the fabric config agent would gain the Go runtime series. It doesn't. controller-runtime registers those collectors only when a binary links its controller package, and the agent links no controllers. Its endpoint gains only the build-info series.

    The acceptance criterion asks for the same series as before plus build-info. Two endpoints that served a private registry now also export the standard Go runtime and process families from the shared registry, which the library's handler always serves. They are the CNI daemon (about 150 families) and the fabric-api node sidecar (about 115, where it had the basic Go collector). No existing series is renamed, removed or retyped. Please say on #1184 or #1190 if those extra families should be dropped rather than accepted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

tech-debt

Type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions