Skip to content

refactor(agent): serve /metrics through the shared metrics-endpoint crate#3525

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

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

Conversation

@chet

@chet chet commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

The agent stood up its own axum server for /metrics -- a spawn_prometheus_metrics_server wrapper plus a get_metrics_router/export_metrics pair that hand-encoded the registry. That is exactly what the shared metrics-endpoint crate already does for the rest of the fleet, so this hands the agent's existing Prometheus registry to metrics_endpoint::run_metrics_endpoint and deletes the bespoke server.

  • The metrics listener now builds a MetricsEndpointConfig over get_prometheus_registry() and serves it, keeping the same bind address and the same fire-and-forget task.
  • spawn_prometheus_metrics_server, get_metrics_router, and export_metrics are gone, along with their now-unused axum and encoder imports.
  • The meter setup -- the InstrumentationSingleton and its custom network and retry views -- is untouched, so the exposed series are unchanged.

The endpoint serves the same registry through the same TextEncoder, so /metrics stays byte-identical; it also answers /health, /ready, and / on the same port, matching the other migrated services.

The previous server offloaded the encode to spawn_blocking; the shared endpoint encodes inline, as it does for every other consumer. That's the shared crate's established behavior, not a regression here -- moving the encode off the async worker for all consumers is tracked in #3524.

This supports #3180

…rate

The agent stood up its own axum server for `/metrics` -- a `spawn_prometheus_metrics_server` wrapper plus a `get_metrics_router`/`export_metrics` pair that hand-encoded the registry. That is exactly what the shared `metrics-endpoint` crate already does for the rest of the fleet, so this hands the agent's existing Prometheus registry to `metrics_endpoint::run_metrics_endpoint` and deletes the bespoke server.

- The metrics listener now builds a `MetricsEndpointConfig` over `get_prometheus_registry()` and serves it, keeping the same bind address and the same fire-and-forget task.
- `spawn_prometheus_metrics_server`, `get_metrics_router`, and `export_metrics` are gone, along with their now-unused axum and encoder imports.
- The meter setup -- the `InstrumentationSingleton` and its custom network and retry views -- is untouched, so the exposed series are unchanged.

The endpoint serves the same registry through the same `TextEncoder`, so `/metrics` stays byte-identical; it also answers `/health`, `/ready`, and `/` on the same port, matching the other migrated services.

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:08
@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, you're welcome! I'll perform a full review of all changes in this PR.

(=^・ω・^=)

✅ Action performed

Full review finished.

@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: fa8f1254-5bb7-4f34-be9e-85a802680de0

📥 Commits

Reviewing files that changed from the base of the PR and between 8abff94 and 2fd77c7.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (4)
  • crates/agent/Cargo.toml
  • crates/agent/src/instrumentation.rs
  • crates/agent/src/main_loop.rs
  • crates/agent/src/metadata_service.rs
💤 Files with no reviewable changes (1)
  • crates/agent/src/instrumentation.rs

Summary by CodeRabbit

  • New Features
    • Added request tracing for the agent’s HTTP services, capturing request counts and response latency.
    • Exposes Prometheus metrics via a dedicated /metrics endpoint using the configured telemetry metrics address.
    • Split responsibilities so the metadata service and metrics endpoint are handled independently.
  • Bug Fixes
    • Detects invalid metrics endpoint addresses and reports a warning without blocking the agent from starting.

Walkthrough

The agent adds shared metrics-endpoint integration, removes its local Prometheus server implementation, and adds Axum tracing middleware that records HTTP request counts and latency.

Changes

Agent metrics and tracing

Layer / File(s) Summary
HTTP tracing instrumentation
crates/agent/src/instrumentation.rs
Adds WithTracingLayer for Axum routers, recording HTTP counters and latency while logging request and response details.
Shared metrics endpoint integration
crates/agent/Cargo.toml, crates/agent/src/main_loop.rs, crates/agent/src/metadata_service.rs
Starts metrics_endpoint::run_metrics_endpoint with the shared Prometheus registry, skips startup for invalid addresses, and removes the metadata service’s local metrics server.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Sequence Diagram(s)

sequenceDiagram
  participant AgentSetup
  participant PrometheusRegistry
  participant MetricsEndpoint
  AgentSetup->>PrometheusRegistry: get_prometheus_registry()
  AgentSetup->>MetricsEndpoint: run_metrics_endpoint(config, registry)
  MetricsEndpoint-->>AgentSetup: Serve metrics endpoint
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: moving the agent's /metrics serving to the shared metrics-endpoint crate.
Description check ✅ Passed The description is clearly aligned with the change and explains the migration from bespoke metrics serving to the shared endpoint.
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.

@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 4cc53d5 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