Repository navigation
build(deps): bump sysinfo to 0.40.1 and handle its fallible constructors #1035
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -230,11 +230,20 @@ pub fn mount_for_path(path: &Path) -> Option<(PathBuf, u64)> { | |
| /// `/proc/diskstats` and `/sys/block/*/queue/rotational`, neither of which this | ||
| /// module uses. | ||
| fn listed_mounts() -> Vec<(PathBuf, u64)> { | ||
| let disks = sysinfo::Disks::new_with_refreshed_list_specifics( | ||
| mounts_of(sysinfo::Disks::new_with_refreshed_list_specifics( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optional: the |
||
| sysinfo::DiskRefreshKind::nothing().with_storage(), | ||
| ); | ||
| )) | ||
| } | ||
|
|
||
| /// Flatten a disk listing into mount points, or an empty list when the | ||
| /// platform could not enumerate disks at all. An empty list leaves | ||
| /// `mount_for_path` with nothing to match, so callers get "unknown" and never | ||
| /// block the operation. | ||
| fn mounts_of<E>(disks: Result<sysinfo::Disks, E>) -> Vec<(PathBuf, u64)> { | ||
| let Ok(disks) = disks else { | ||
| return Vec::new(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Non-blocking (confidence 70, architectural/consistency): this Suggested fix: add a one-time |
||
| }; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor, non-blocking: a total disk-enumeration failure here is dropped with no diagnostic at all, which is asymmetric with |
||
| disks | ||
| .list() | ||
| .iter() | ||
| .map(|disk| (disk.mount_point().to_path_buf(), disk.available_space())) | ||
| .collect() | ||
|
|
@@ -892,6 +901,21 @@ mod tests { | |
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn a_failed_disk_enumeration_reports_unknown_space_and_never_blocks() { | ||
| // sysinfo 0.40 made listing disks fallible. The failure must surface as | ||
| // "no mounts", which `select_mount` cannot match and `classify_space` | ||
| // reports as unknown, rather than as a panic or an invented figure. | ||
| let mounts = mounts_of::<&str>(Err("the platform could not list disks")); | ||
| assert!(mounts.is_empty(), "{mounts:?}"); | ||
| let selected = select_mount(Path::new("/var/cache/rocm"), &mounts); | ||
| assert_eq!(selected, None); | ||
| assert!(matches!( | ||
| classify_space(u64::MAX, selected.map(|(_, available)| available)), | ||
| SpaceCheck::Unknown | ||
| )); | ||
| } | ||
|
|
||
| #[test] | ||
| fn insufficient_space_refuses_and_sufficient_space_allows() { | ||
| // The refusal path itself, driven by a synthetic figure rather than | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,9 @@ use rocm_dash_core::metrics::SystemMetrics; | |
| use sysinfo::{MemoryRefreshKind, RefreshKind, System}; | ||
|
|
||
| pub struct HostCollector { | ||
| sys: System, | ||
| // `None` when sysinfo could not initialise on this platform; `tick` then | ||
| // reports empty metrics instead of failing the whole dashboard. | ||
| sys: Option<System>, | ||
| } | ||
|
|
||
| impl Default for HostCollector { | ||
|
|
@@ -22,30 +24,39 @@ impl HostCollector { | |
| let refresh = RefreshKind::nothing() | ||
| .with_cpu(sysinfo::CpuRefreshKind::everything()) | ||
| .with_memory(MemoryRefreshKind::everything()); | ||
| let mut sys = System::new_with_specifics(refresh); | ||
| // First refresh primes CPU deltas; the very first read is meaningless. | ||
| sys.refresh_cpu_all(); | ||
| sys.refresh_memory(); | ||
| Self { sys } | ||
| Self::from_system(System::new_with_specifics(refresh)) | ||
| } | ||
|
|
||
| fn from_system<E: std::fmt::Display>(sys: Result<System, E>) -> Self { | ||
| match sys { | ||
| Ok(mut sys) => { | ||
| // First refresh primes CPU deltas; the very first read is meaningless. | ||
| sys.refresh_cpu_all(); | ||
| sys.refresh_memory(); | ||
| Self { sys: Some(sys) } | ||
| } | ||
| Err(error) => { | ||
| tracing::warn!(%error, "host metrics unavailable: sysinfo failed to initialise"); | ||
| Self { sys: None } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| pub fn tick(&mut self) -> SystemMetrics { | ||
| self.sys.refresh_cpu_all(); | ||
| self.sys.refresh_memory(); | ||
| let Some(sys) = self.sys.as_mut() else { | ||
| return SystemMetrics::default(); | ||
| }; | ||
| sys.refresh_cpu_all(); | ||
| sys.refresh_memory(); | ||
|
|
||
| let cpu_overall_pct = self.sys.global_cpu_usage(); | ||
| let cpu_per_core_pct: Vec<f32> = self | ||
| .sys | ||
| .cpus() | ||
| .iter() | ||
| .map(sysinfo::Cpu::cpu_usage) | ||
| .collect(); | ||
| let cpu_overall_pct = sys.global_cpu_usage(); | ||
| let cpu_per_core_pct: Vec<f32> = sys.cpus().iter().map(sysinfo::Cpu::usage).collect(); | ||
|
|
||
| // sysinfo reports memory in bytes. | ||
| let memory_used_mb = self.sys.used_memory() / 1024 / 1024; | ||
| let memory_total_mb = self.sys.total_memory() / 1024 / 1024; | ||
| let swap_used_mb = self.sys.used_swap() / 1024 / 1024; | ||
| let swap_total_mb = self.sys.total_swap() / 1024 / 1024; | ||
| let memory_used_mb = sys.used_memory() / 1024 / 1024; | ||
| let memory_total_mb = sys.total_memory() / 1024 / 1024; | ||
| let swap_used_mb = sys.used_swap() / 1024 / 1024; | ||
| let swap_total_mb = sys.total_swap() / 1024 / 1024; | ||
|
|
||
| SystemMetrics { | ||
| cpu_overall_pct, | ||
|
|
@@ -74,4 +85,15 @@ mod tests { | |
| assert!(!m.cpu_per_core_pct.is_empty(), "expected at least one CPU"); | ||
| assert!(m.memory_total_mb > 0, "expected nonzero total memory"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn a_collector_whose_sysinfo_failed_to_initialise_reports_empty_metrics() { | ||
| // sysinfo 0.40 made `System` construction fallible. The dashboard must | ||
| // keep ticking, with nothing to show for the host, rather than panic. | ||
| let mut c = HostCollector::from_system::<&str>(Err("unsupported platform")); | ||
| let m = c.tick(); | ||
| assert!(m.cpu_per_core_pct.is_empty(), "{m:?}"); | ||
| assert_eq!(m.memory_total_mb, 0, "{m:?}"); | ||
| assert_eq!(m.swap_total_mb, 0, "{m:?}"); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Decision for the author (non-blocking-improvement): this test only spot-checks 3 of |
||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
default-features = falsealso drops sysinfo'smultithread(rayon) default, so CPU refresh becomes single-threaded. Fine for this use; just confirming it is intended.