add protection for potentially invalid disk data#2105
Open
add protection for potentially invalid disk data#2105
Conversation
zhihonl
approved these changes
Apr 29, 2026
sky333999
approved these changes
May 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of the issue
The
systemmetricsreceiverdisk scraper aggregatesaggregate_disk_freeandaggregate_disk_usedby summing across all/dev/-prefixed mounts. On Linux,gopsutil'sdisk.UsageWithContextcomputesTotalandFreeasuint64(stat.Blocks) * uint64(stat.Bsize)from the kernel'sstatfssyscall. Certain filesystem states — transient loop mounts, mounts under heavy I/O pressure, or broken FUSE devices — can causestatfsto return garbage values whereFree > Totalor both values are near2^63. When these are summed into the aggregate, the resulting metric is nonsensical and poisons downstreammin/maxrollups.Observed in production on an EC2 host with a nearly-full root XFS volume: 5 out of ~2100 one-minute samples reported
aggregate_disk_free ≈ -9.2e18(Long.MIN_VALUE range after float64 conversion), which can break downstream consumers that don't expect negative or astronomically large byte values.Description of changes
Adds a per-mount plausibility check (
isPlausibleDiskUsage) before accumulating into the aggregate sum. A mount is rejected if:Total == 0(statvfs failure or pseudo-filesystem)Free > Total(physically impossible — the exact signature of the observed bug)TotalorFreeexceeds 1 PiB (1 << 50bytes, ~16x the largest EBS volume)When any mount fails the check, the entire sample is dropped rather than emitting a partial sum. CloudWatch handles missing datapoints correctly; it does not handle wrong datapoints correctly — a partial sum silently understates free space and poisons
min()aggregations.License
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Tests
TestDiskScraperDropsSampleWhenFreeExceedsTotal— reproduces the exact bug signature (tiny total, huge free)TestDiskScraperDropsSampleWhenTotalExceedsCap— mount above 1 PiB capTestDiskScraperDropsSampleWhenTotalIsZero— defense-in-depth (already filtered byDiskUsage())TestIsPlausibleDiskUsage— table-driven test covering 6 cases (normal, full disk, at cap, zero total, free > total, above cap)Totalfield added to test fixturesgo test ./receiver/systemmetricsreceiver/— all disk/plausibility tests passRequirements
make fmtandmake fmt-shmake lint