Skip to content

fix(diskstats): drop sector metrics on darwin - #3885

Open
lbarrosby wants to merge 1 commit into
prometheus:masterfrom
lbarrosby:diskstats-darwin-sectors
Open

lbarrosby wants to merge 1 commit into
prometheus:masterfrom
lbarrosby:diskstats-darwin-sectors

Conversation

@lbarrosby

Copy link
Copy Markdown

Fixes #3850

On Darwin, node_disk_read_sectors_total and node_disk_written_sectors_total were computed as NumRead / BlockSize and NumWrite / BlockSize. NumRead/NumWrite are operation counts and BlockSize is in bytes, so the result is not a sector count in any unit (3 reads on a 4096-byte block size gives 0.00073).

The collector already exposes node_disk_read_bytes_total and node_disk_written_bytes_total from the IOKit byte counters, so this removes the two sector families, the same way the Linux collector moved to bytes in #787.

I also split the metric emission out of Update (updateFromStats) so it can be driven with synthetic iostat.DriveStats, and added diskstats_darwin_test.go, which is the first test for this collector. It compares the full output, so the sector families coming back would fail it.

If you would rather keep the metric names, the alternative is exporting BytesRead / 512 and BytesWritten / 512 under the existing names. Happy to switch to that.

Suggested changelog entry:
[CHANGE] diskstats: Remove node_disk_read_sectors_total and node_disk_written_sectors_total on Darwin, use the bytes counters instead

Testing, on macOS 26 (arm64):

  • go test ./collector/ -count=1
  • golangci-lint run ./collector/...: no findings in the changed files
  • built the binary and ran it with --collector.disable-defaults --collector.diskstats: the bytes, operations, time, error and retry series are unchanged and no *_sectors_total series is exported

I used an AI assistant while working on this; I reviewed the change and tested it on my machine.

node_disk_read_sectors_total and node_disk_written_sectors_total were
computed as NumRead/BlockSize and NumWrite/BlockSize, i.e. operation
counts divided by a size in bytes, which is not a sector count in any
unit. The collector already exports node_disk_read_bytes_total and
node_disk_written_bytes_total from the byte counters, so remove the two
families, as the Linux collector did in prometheus#787.

Split the metric emission out of Update so it can be exercised with
synthetic iostat.DriveStats, and add the first test for the Darwin
diskstats collector.

Fixes prometheus#3850

Signed-off-by: Lucas Barros <lucasbarros.kam@gmail.com>
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.

Darwin diskstats reports operation counts divided by block size as sectors

1 participant