Skip to content

refactor(api): serve /metrics through the shared metrics-endpoint crate#3527

Merged
chet merged 1 commit into
NVIDIA:mainfrom
chet:gh-issue-3180-apicore
Jul 15, 2026
Merged

refactor(api): serve /metrics through the shared metrics-endpoint crate#3527
chet merged 1 commit into
NVIDIA:mainfrom
chet:gh-issue-3180-apicore

Conversation

@chet

@chet chet commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

api-core served /metrics from its own copy of the metrics server -- a fork of the shared metrics-endpoint crate carrying two things the shared one lacked: mirroring metrics under an alternate name prefix, and stopping the listener on a cancellation token. Both now live in the shared crate (#3474), so this deletes the fork and points api-core at it.

  • run.rs builds the shared MetricsEndpointConfig over the API's registry and serves it with run_metrics_endpoint_with_cancellation, turning the configured alt_metric_prefix into a PrefixMigration { old: "carbide_", new }.
  • crates/api-core/src/logging/metrics_endpoint.rs, the forked server, is deleted along with its module declaration.
  • create_metrics and the meter setup, with their custom histogram views, are untouched.

The shared endpoint serves the same registry, so /metrics stays byte-identical: test_integration's catalogue regenerates with no diff, and the alt_metric_ mirroring test (test_metrics_integration) still passes through the shared crate.

This supports #3180

api-core served `/metrics` from its own copy of the metrics server -- a fork of the shared `metrics-endpoint` crate carrying two things the shared one lacked: mirroring metrics under an alternate name prefix, and stopping the listener on a cancellation token. Both now live in the shared crate, so this deletes the fork and points api-core at it.

- `run.rs` builds the shared `MetricsEndpointConfig` over the API's registry and serves it with `run_metrics_endpoint_with_cancellation`, turning the configured `alt_metric_prefix` into a `PrefixMigration { old: "carbide_", new }`.
- `crates/api-core/src/logging/metrics_endpoint.rs`, the forked server, is deleted along with its module declaration.
- `create_metrics` and the meter setup, with their custom histogram views, are untouched.

The shared endpoint serves the same registry, so `/metrics` stays byte-identical: the integration test's catalogue regenerates with no diff, and the `alt_metric_` mirroring test still passes through the shared crate.

Tests pass!

This supports NVIDIA#3180

Signed-off-by: Chet Nichols III <chetn@nvidia.com>
@chet chet requested a review from a team as a code owner July 15, 2026 00:22
@chet

chet commented Jul 15, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai full_review, thanks!

@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

@chet, sure thing — kicking off a full review of all the changes in this PR now.

✅ Action performed

Full review finished.

@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Summary by CodeRabbit

  • New Features

    • Updated the metrics endpoint integration to use the latest shared metrics service interface.
    • Continued support for metric prefix migrations and configurable metrics endpoint startup.
  • Refactor

    • Reworked how the metrics endpoint is wired and started, switching to the new cancellation-based startup flow while keeping the externally visible /metrics behavior intact.

Walkthrough

api-core replaces its local HTTP metrics server with the shared metrics-endpoint crate and updates startup wiring for prefix migration, cancellation-aware execution, and optional health-controller configuration.

Changes

Metrics endpoint migration

Layer / File(s) Summary
Adopt shared metrics endpoint
crates/api-core/Cargo.toml, crates/api-core/src/logging/mod.rs
Adds the local metrics-endpoint dependency and removes the in-crate metrics endpoint module export.
Update metrics startup wiring
crates/api-core/src/run.rs
Uses PrefixMigration, calls run_metrics_endpoint_with_cancellation, and passes health_controller: None in the endpoint configuration.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: api-core now serves /metrics through the shared metrics-endpoint crate.
Description check ✅ Passed The description is directly related to the changeset and accurately explains the refactor and endpoint behavior.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/api-core/src/run.rs`:
- Around line 169-172: Update the MetricsEndpointConfig construction in the run
flow to pass metrics.health_controller.clone() instead of None. Preserve the
shared health controller so health and readiness endpoints reflect api-core’s
actual state.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: b276d872-a9dd-4ecd-b729-fe4df2c8d014

📥 Commits

Reviewing files that changed from the base of the PR and between 8abff94 and 71df214.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (4)
  • crates/api-core/Cargo.toml
  • crates/api-core/src/logging/metrics_endpoint.rs
  • crates/api-core/src/logging/mod.rs
  • crates/api-core/src/run.rs
💤 Files with no reviewable changes (2)
  • crates/api-core/src/logging/mod.rs
  • crates/api-core/src/logging/metrics_endpoint.rs

Comment on lines +169 to +172
&metrics_endpoint::MetricsEndpointConfig {
address: metrics_address,
registry: metrics.registry,
health_controller: None,

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.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

set -euo pipefail

printf '\n== crates/api-core/src/run.rs (around target lines) ==\n'
nl -ba crates/api-core/src/run.rs | sed -n '145,195p'

printf '\n== search health_controller usages in api-core and metrics-endpoint ==\n'
rg -n "health_controller" crates/api-core crates/metrics-endpoint -S

printf '\n== crates/metrics-endpoint/src/lib.rs (relevant section) ==\n'
nl -ba crates/metrics-endpoint/src/lib.rs | sed -n '1,180p'

Repository: NVIDIA/infra-controller

Length of output: 257


🏁 Script executed:

Inspect the relevant code:
- crates/api-core/src/run.rs around lines 145-195
- crates/metrics-endpoint/src/lib.rs around the health controller defaults
- any health_controller wiring in crates/api-core and crates/metrics-endpoint

Repository: NVIDIA/infra-controller

Length of output: 311


🏁 Script executed:

set -euo pipefail

printf '\n== crates/api-core/src/run.rs (excerpt) ==\n'
sed -n '145,195p' crates/api-core/src/run.rs

printf '\n== health_controller references ==\n'
rg -n "health_controller" crates/api-core crates/metrics-endpoint -S || true

printf '\n== crates/metrics-endpoint/src/lib.rs (excerpt) ==\n'
sed -n '1,180p' crates/metrics-endpoint/src/lib.rs

Repository: NVIDIA/infra-controller

Length of output: 10159


🏁 Script executed:

set -euo pipefail

printf '\n== api-core health controller usage ==\n'
rg -n "set_ready|set_healthy|health_controller" crates/api-core -S

printf '\n== metrics-endpoint setup and tests around health defaults ==\n'
sed -n '200,240p' crates/metrics-endpoint/src/lib.rs
printf '\n---\n'
sed -n '400,540p' crates/metrics-endpoint/src/lib.rs

Repository: NVIDIA/infra-controller

Length of output: 7165


Preserve the shared health controller. health_controller: None creates a new controller that starts healthy and ready, so /health and /ready can succeed before api-core is actually ready. Pass metrics.health_controller.clone() through here.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/api-core/src/run.rs` around lines 169 - 172, Update the
MetricsEndpointConfig construction in the run flow to pass
metrics.health_controller.clone() instead of None. Preserve the shared health
controller so health and readiness endpoints reflect api-core’s actual state.

@chet

chet commented Jul 15, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @coderabbitai -- declining this one: there's no health controller to preserve. api-core's forked MetricsEndpointConfig had only address, registry, and additional_prefix -- no health_controller field -- so the fork never served /health or /ready, and metrics.health_controller doesn't exist (the suggested metrics.health_controller.clone() wouldn't compile). None is the faithful migration: /metrics stays byte-identical, and the /health,/ready,/ routes the shared endpoint adds are new and default to always-ok, consistent with the agent and fmds migrations.

Wiring api-core's real readiness into the shared endpoint's /ready would be a genuine enhancement (it needs a HealthController that doesn't exist yet), but it's out of scope for a byte-identical mechanism swap.

@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

@chet, understood — thanks for the detailed clarification. Since the forked MetricsEndpointConfig never had a health_controller field (only address, registry, and additional_prefix), passing health_controller: None is indeed the correct, byte-identical migration, and my suggested metrics.health_controller.clone() was based on a field that doesn't exist. Withdrawing that comment.

Agreed that wiring real readiness into the shared endpoint's /ready is a legitimate follow-up enhancement, not an in-scope requirement for this mechanism swap. Let me know if you'd like me to open a tracking issue for that follow-up.

ᕮ(´• ω •`)ᕮ


✏️ Learnings added
Learnt from: chet
URL: https://github.com/NVIDIA/infra-controller/pull/3527

Timestamp: 2026-07-15T00:57:29.489Z
Learning: In the NVIDIA/infra-controller repository, `crates/api-core`'s forked metrics endpoint (`crates/api-core/src/logging/metrics_endpoint.rs`, since removed in favor of the shared `metrics-endpoint` crate) had a `MetricsEndpointConfig` with only `address`, `registry`, and `additional_prefix` fields — no `health_controller`. It never served `/health` or `/ready`. When migrating `crates/api-core/src/run.rs` to use the shared `metrics-endpoint` crate's `run_metrics_endpoint_with_cancellation`, passing `health_controller: None` is the faithful, byte-identical migration for `/metrics`; the shared endpoint's new `/health`, `/ready`, `/` routes default to always-ok when no health controller is provided. Wiring api-core's real readiness into `/ready` is a separate future enhancement requiring a `HealthController` that does not yet exist, consistent with the "agent" and "fmds" migrations mentioned by the maintainer chet.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

@github-actions

Copy link
Copy Markdown

🔍 Container Scan Summary

Service Total Critical High Medium Low Other
boot-artifacts-aarch64 3 0 0 3 0 0
boot-artifacts-x86_64 3 0 0 3 0 0
forge-admin-cli-x86_64 259 13 30 78 7 131
machine-validation-runner 807 40 234 288 36 209
machine_validation 807 40 234 288 36 209
machine_validation-aarch64 807 40 234 288 36 209
nvmetal-carbide 807 40 234 288 36 209
TOTAL 3493 173 966 1236 151 967

Per-CVE detail lives in the per-service grype-* artifacts (JSON + SARIF). Severity counts only — no CVE IDs published here.

@chet chet merged commit f4ebb84 into NVIDIA:main Jul 15, 2026
59 checks passed
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