Skip to content

Measure idle disk I/O as a per-tick delta over whole disks found by structure (#937) - #955

Merged
scttfrdmn merged 2 commits into
mainfrom
fix/937
Oct 17, 2026
Merged

scttfrdmn merged 2 commits into
mainfrom
fix/937

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Fixes #937. Stacked on #936 (fix/919), so merge that first. The base is fix/919 and the diff shows only #937.

What was wrong

The idle disk check compared the since-boot I/O total with a "100KB/min" threshold. Its name filter also dropped every NVMe disk and counted sda1/vda1 as extra disks. So on Nitro the disk signal was always 0, and on xvd/sd/vd hosts it was always over the threshold, which meant idle-stop could never fire there.

What changed

  • Whole disks are chosen by structure (pkg/agent/diskstats.go, untagged so it is tested on every platform). A device counts if it is in /sys/block, which lists only whole devices since partitions sit under their disk, and has a /sys/block/<dev>/device link. That link is absent on loop, ram, zram, dm-* and md*. The idle check and the Prometheus disk metric both use this.
  • The disk signal is a delta between samples: diskIOBytes() (bytes, measured, why) with a diskSampled bool, written like networkBytes in Count physical NICs by structure so idle-stop can fire on enp*s* hosts (#919) #936. The first sample, an unreadable counter and a counter that went backwards are all unknown. Unknown is treated as active (the conservative direction), shown as unknown in status, and warned about once.
  • Windows: DiskBytesPersec in the raw class is a cumulative counter, so the new delta logic handles it. A missing _Total instance now returns unknown, where before [int64]$null gave a measured 0. The darwin stub returns unknown.
  • Status: a new Disk I/O: line prints unknown (<why>; assuming active) rather than the placeholder. The JSON gains disk_bytes_per_min, disk_measured and disk_unknown.
  • Audit fix: cpuUsage now treats counters that went backwards (deltaTotal<0, deltaIdle<0, or deltaIdle>deltaTotal) as unknown. Before, they produced readings of 50%, 150% or -200%, and the negative one reads as idle.
  • I removed three tests in monitoring_test.go. They re-implemented the old filter inline and asserted what it did, including "nvme0n1 skipped", so they certified the bug (rule 5).

Tests and the revert check (rule 1)

Fixtures cover a /proc/diskstats and a kernel-shaped /sys/block (symlinks into /sys/devices, partitions as subdirectories, a device link only on hardware disks) for nvme0n1+p1+p128, nvme0n1+nvme1n1, xvda+xvda1, sda+sda1 and vda+vda1, plus noise from loop0/loop1/dm-0/md0/zram0. There are also tests for the first sample, the delta, a zero counter, a backwards counter and unknown with a single warning.

Before each check I confirmed that every revert compiles (go vet clean), then watched the test fail:

revert failing test
old prefix+length name filter CountsWholeDisksByStructure: nvme0n1, nvme0n1+nvme1n1, sda, vda
return the cumulative total, not the delta IsADeltaAfterAFirstSample, BackwardsCounterIsUnknown
no first-sample bool IsADeltaAfterAFirstSample
prev != 0 as the first-sample test (the #919 shape) ZeroCounterIsNotAPermanentFirstSample
no backwards guard BackwardsCounterIsUnknown
warn on every tick UnknownIsAssumedActiveAndWarnedOnce
unknown reported as 0 UnknownIsAssumedActiveAndWarnedOnce
assume-active value at the threshold DiskAssumedActiveIsOverTheIdleThreshold
no CPU backwards guard CPUUsage_BackwardsCountersAreUnknown (all 3 cases)
status always prints the value StatusTable_UnmeasuredDiskIsNotPrintedAsAValue
status wiring always claims measured StatusReport_OneShotDiskIsUnknownWithAReason

make check passes except for the known Docker-only TestGenerateWrapper_ChownFixesCrossUIDStickyUnlink_Docker, because no Docker daemon is running. make check-nested passes: all 9 nested modules are clean.

Caveats

  • I have not observed any of this on an instance. The /sys/block layout in the fixtures comes from how the kernel lays out sysfs, not from a capture. The Windows change is not exercised by any test.
  • With native NVMe multipath on a multi-controller subsystem, the hidden nvme0c0n1 path devices could appear and be counted next to the head node. EBS and instance-store controllers are single-controller, so this should not happen on EC2, but I have not verified it.
  • The Prometheus spawn_disk_io_bytes_total device label changes, for example to nvme0n1 or nvme0n1,nvme1n1, so existing series change label. This is noted in the CHANGELOG.

Filed from the idle-signal audit

…tructure (#937)

The idle check compared the since-boot disk I/O total with a per-minute
threshold, and its name filter dropped every NVMe disk (nvme0n1 is "longer
than 4 and ends in a digit") while counting sda1/vda1 as extra disks. On
Nitro the disk signal was therefore always 0; on xvd/sd/vd hosts it was
always over 100 KB, so idle-stop could never fire.

- Choose whole disks by structure: /sys/block lists whole devices only,
  and of those, the ones with a /sys/block/<dev>/device link are backed by
  hardware (loop, ram, zram, dm-*, md* are not). Shared by the idle check
  and the Prometheus disk metric.
- diskIOBytes returns (delta, measured, why) with a diskSampled bool, in
  the networkBytes style from #919: first sample, unreadable counters and
  backwards counters are unknown, which means assume active, and an
  unreadable counter is warned about once.
- Windows: a missing _Total perf instance is unknown, not a measured 0.
  The darwin stub reports unknown.
- spored status gains a Disk I/O line that prints "unknown (why)" when
  nothing was measured, plus disk_bytes_per_min / disk_measured /
  disk_unknown in the JSON.
- Audit: cpuUsage now treats counters that go backwards as unknown (it
  could produce a negative usage, which reads as idle).
- Removed three monitoring_test.go tests that re-implemented the old
  filter inline and asserted its behaviour, including skipping nvme0n1.

Filed from the audit: #952 (metrics scrape shares sample state), #953
(presence-only PTY/last checks), #954 (GPU unknown reads as 0).

(#937)
@codecov

codecov Bot commented Oct 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 72.85714% with 19 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/agent/agent.go 70.37% 8 Missing ⚠️
pkg/agent/diskstats.go 85.71% 2 Missing and 2 partials ⚠️
pkg/agent/metrics.go 0.00% 4 Missing ⚠️
pkg/agent/sys_linux.go 0.00% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 82bdc31 into main Oct 17, 2026
8 checks passed
@scttfrdmn
scttfrdmn deleted the fix/937 branch October 17, 2026 01:18
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.

Idle disk I/O check is cumulative-since-boot and its device filter drops every NVMe disk: always 0 on Nitro, always 'active' on xvd/sd/vd

1 participant