Skip to content

[Backport release-mainnet-1.2.0-rc] fix(process-metrics): build on non-Linux platforms#4439

Merged
sveitser merged 1 commit into
release-mainnet-1.2.0-rcfrom
backport-4435-to-release-mainnet-1.2.0-rc
Jun 5, 2026
Merged

[Backport release-mainnet-1.2.0-rc] fix(process-metrics): build on non-Linux platforms#4439
sveitser merged 1 commit into
release-mainnet-1.2.0-rcfrom
backport-4435-to-release-mainnet-1.2.0-rc

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot commented Jun 5, 2026

Description

Backport of #4435 to release-mainnet-1.2.0-rc.

* fix(process-metrics): build on non-Linux platforms

- Gate procfs dependency to cfg(target_os = "linux") so its build script
  no longer fails on macOS
- Split into a portable ProcessMetrics (memory, cpu_count, uptime via
  sysinfo) and a Linux-only LinuxMetrics extension (/proc, cgroup, PSI)
- Keep the only platform cfg in lib.rs; non-Linux gets an inline no-op ext

* fix(process-metrics): report node_cpu_count via available_parallelism

- System::new().cpus() is empty until an explicit CPU refresh, so the
  gauge reported 0; use std::thread::available_parallelism instead
- Extract cpu_count and process_memory as pure functions with regression
  tests asserting non-zero CPU and memory readings

(cherry picked from commit 809b0a1)
@sveitser sveitser enabled auto-merge (squash) June 5, 2026 12:37
@sveitser sveitser closed this Jun 5, 2026
auto-merge was automatically disabled June 5, 2026 12:37

Pull request was closed

@sveitser sveitser reopened this Jun 5, 2026
@claude
Copy link
Copy Markdown
Contributor

claude Bot commented Jun 5, 2026

Claude finished @sveitser's task in 1m 44s —— View job


Code Review: Backport fix(process-metrics) build on non-Linux platforms

  • Read repository guidelines
  • Read existing review comments
  • Analyze PR diff against base branch
  • Review changed files in detail
  • Post review findings

Summary

This is a clean backport of #4435 to release-mainnet-1.2.0-rc. The change refactors the process-metrics crate to compile on non-Linux platforms by splitting the single-file implementation into three modules:

File Purpose
lib.rs Module root with cfg-gated ext module — Linux gets linux.rs, others get an inline no-op stub
portable.rs Cross-platform metrics (RSS, virtual memory, uptime, CPU count) via sysinfo
linux.rs Linux-only metrics (/proc, cgroup v2, PSI pressure) via procfs

procfs is moved to a cfg(target_os = "linux")-only dependency in Cargo.toml, which is the core fix.

Findings

The refactor is well-structured and the backport is clean. The public API (ProcessMetrics::new() / ProcessMetrics::run()) is unchanged, making this a safe backport for a release branch. A few observations:

Bug fix: cpu_count now actually works

The original code called sysinfo::System::new().cpus().len(), but System::new() without refresh_cpu_all() returns 0 CPUs — so node_cpu_count was always 0. The new std::thread::available_parallelism() approach in portable.rs:69-73 correctly reports the available CPU count. The test at portable.rs:90 documents this by asserting System::new().cpus().len() == 0.

Clean cfg architecture

The #[path = "linux.rs"] + #[cfg(target_os = "linux")] pattern in lib.rs:11-13 paired with the inline stub at lib.rs:17-34 keeps all platform cfg in one place. The stub's interface (new, init, sample) mirrors the real LinuxMetrics exactly, so portable.rs compiles identically on all platforms.

State ownership refactor

LinuxMetrics now owns env: Option<Env> and prev: Previous as fields (linux.rs:139-140) rather than passing them through the call chain. This is cleaner and makes the init()/sample() split natural — init() detects sources once, sample() early-returns if env is None.

Graceful degradation on non-Linux

On non-Linux, the stub LinuxMetrics emits a single info-level log during init() and sample() is a no-op. The portable metrics (RSS, virtual memory, uptime, CPU count) are still collected. This is the right behavior — operators get what the platform can provide, with clear logging about what's absent.

Verdict

LGTM. The refactor is clean, the API is unchanged, tests are preserved and enhanced (new cpu_count_is_at_least_one and process_memory_reports_current_process tests in portable.rs), and the cfg architecture is well-contained. No issues found.

@sveitser sveitser enabled auto-merge (squash) June 5, 2026 14:25
@sveitser sveitser merged commit ada9582 into release-mainnet-1.2.0-rc Jun 5, 2026
212 of 217 checks passed
@sveitser sveitser deleted the backport-4435-to-release-mainnet-1.2.0-rc branch June 5, 2026 15:48
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.

1 participant