Skip to content

refactor(api): move metrics initialization into api crate#3860

Merged
poroh merged 1 commit into
NVIDIA:mainfrom
poroh:api-bootstrap/02-metrics
Jul 22, 2026
Merged

refactor(api): move metrics initialization into api crate#3860
poroh merged 1 commit into
NVIDIA:mainfrom
poroh:api-bootstrap/02-metrics

Conversation

@poroh

@poroh poroh commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Reduce the scope and growth of carbide-api-core by moving process initialization into the carbide-api composition crate. This PR moves metrics initialization, metrics endpoint startup, and process task ownership without intended functional or configuration changes.

This is the second change in a planned series:

  1. Move logging initialization and the top-level run entry point - refactor(api): move logging initialization into api crate #3851.
  2. Move metrics initialization, the metrics endpoint, and process task ownership - this PR.
  3. Move dynamic settings, database, Vault, credentials, certificates, KMS, and secret-import setup.
  4. Move IPMI, Redfish, RMS, InfiniBand, NMX-C, DPF, and component-manager client setup.

The existing metric views and gauge regression coverage are preserved. Metrics-bootstrap dependencies that are no longer used by api-core move with the implementation.

Related issues

#3851

Type of Change

  • Add - New feature or capability
  • Change - Changes in existing functionality
  • Fix - Bug fixes
  • Remove - Removed features or deprecated functionality
  • Internal - Internal changes (refactoring, tests, docs, etc.)

Breaking Changes

  • This PR contains breaking changes

Testing

  • Unit tests added/updated
  • Integration tests added/updated
  • Manual testing performed
  • No testing required (docs, internal refactor, etc.)

Additional Notes

This PR is stacked on #3851 and should merge after it.

@copy-pr-bot

copy-pr-bot Bot commented Jul 22, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

API metrics ownership moves into crates/api, where Prometheus/OpenTelemetry setup and the metrics endpoint are initialized. api-core consumes caller-provided telemetry and task orchestration through CoreRunInputs, while obsolete metrics dependencies and setup code are removed.

Changes

API metrics lifecycle

Layer / File(s) Summary
Metrics provider and endpoint setup
crates/api/Cargo.toml, crates/api/src/lib.rs, crates/api/src/metrics.rs, crates/api-core/src/bootstrap.rs, crates/api-core/src/logging/setup.rs, crates/api-core/Cargo.toml
The API crate adds Prometheus-backed OpenTelemetry metrics, histogram views, span-count gauges, and validation coverage; obsolete metrics setup and dependencies are removed from api-core, and ApiMetricsEmitter is re-exported.
Core runtime telemetry and task injection
crates/api-core/src/run.rs
CoreRunInputs accepts a meter and borrowed JoinSet; run_core passes them through runtime initialization and no longer owns metrics creation or final task waiting.
Application task lifecycle wiring
crates/api/src/run.rs
run initializes metrics, starts the optional metrics endpoint, passes shared runtime state to run_core, and waits for spawned tasks through join_all.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant api_run as api::run::run
  participant metrics as api::metrics::setup_metrics
  participant endpoint as start_metrics_endpoint
  participant core as api_core::run_core
  participant tasks as Tokio JoinSet
  api_run->>metrics: initialize Prometheus/OpenTelemetry metrics
  metrics-->>api_run: return registry and meter
  api_run->>endpoint: spawn optional metrics server
  api_run->>core: provide meter and shared JoinSet
  core-->>api_run: return after API startup
  api_run->>tasks: wait with join_all
Loading

Possibly related PRs

  • NVIDIA/infra-controller#3851: Both changes modify logging setup in crates/api-core, including removal of metrics and tracing-related wiring.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title accurately summarizes the main refactor: moving metrics initialization into the api crate.
Description check ✅ Passed The description matches the changeset and describes the metrics refactor, endpoint startup, and task ownership move.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Move metrics provider and endpoint setup into the top-level
carbide-api composition crate. Transfer JoinSet ownership with it so
process tasks are awaited outside api-core while core service
initialization remains unchanged.

Preserve the existing metric views and regression coverage, and remove
metrics-bootstrap dependencies that api-core no longer uses.

Signed-off-by: Dmitry Porokh <dporokh@nvidia.com>
@poroh
poroh force-pushed the api-bootstrap/02-metrics branch from 38411bd to 06a66c3 Compare July 22, 2026 19:37
@poroh
poroh marked this pull request as ready for review July 22, 2026 19:37
@poroh
poroh requested a review from a team as a code owner July 22, 2026 19:37
@poroh
poroh enabled auto-merge (squash) July 22, 2026 19:58
@poroh
poroh merged commit d5db112 into NVIDIA:main Jul 22, 2026
63 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