Skip to content

fix(disk): stop dropping filesystems whose mount point has unusual ch… - #1063

Open
karlitschek wants to merge 1 commit into
masterfrom
fix/disk-info-mount-point-parsing
Open

fix(disk): stop dropping filesystems whose mount point has unusual ch…#1063
karlitschek wants to merge 1 commit into
masterfrom
fix/disk-info-mount-point-parsing

Conversation

@karlitschek

Copy link
Copy Markdown
Member

…aracters

getDiskInfo() matched the mount point against a character class — [\w/-.] on Linux, [\w/-] on FreeBSD, which did not even allow a dot. A mount point containing anything outside that set failed the whole line, and because the pattern is applied per line with preg_match_all, failing the line removed the entire filesystem from the report. No warning and no log entry: it simply was not there.

A space is enough. So is a non-ASCII character, since \w does not cover one without the unicode flag, and so are brackets. On the new fixture the old Linux pattern matches 1 of 5 filesystems.

df -P exists precisely so that output is machine readable: one record per line, no wrapping, and the mount point last. The mount point is therefore everything after the capacity column, which is what the pattern now says instead of trying to predict which characters can appear in a path.

Two smaller changes in the same expression:

Separators are now \s+ rather than \s*. The columns are whitespace separated, so allowing zero whitespace only worked by backtracking.

Used and Capacity are now matched as \S+ rather than requiring digits and a literal percent sign. Nothing reads either of them — used is recomputed from Blocks minus Available — and df prints "-" in them for filesystems that do not report usage, which was another way for a row to disappear. Blocks and Available still require digits, because those are the values actually used.

Verified by running the new tests against the unfixed collectors: Linux reports 1 filesystem where 5 are expected, FreeBSD 1 where 4 are expected, and both pass after the change. The existing 7-disk expectation is untouched, so the new pattern is a superset of the old one on output that already parsed. FreeBSD's getDiskInfo() had no coverage at all and gains its first.

🤖 AI (if applicable)

  • The content of this PR was partly or fully generated using AI

…aracters

getDiskInfo() matched the mount point against a character class —
[\w\/\-\.] on Linux, [\w\/-] on FreeBSD, which did not even allow a dot. A
mount point containing anything outside that set failed the whole line, and
because the pattern is applied per line with preg_match_all, failing the line
removed the entire filesystem from the report. No warning and no log entry: it
simply was not there.

A space is enough. So is a non-ASCII character, since \w does not cover one
without the unicode flag, and so are brackets. On the new fixture the old
Linux pattern matches 1 of 5 filesystems.

`df -P` exists precisely so that output is machine readable: one record per
line, no wrapping, and the mount point last. The mount point is therefore
everything after the capacity column, which is what the pattern now says
instead of trying to predict which characters can appear in a path.

Two smaller changes in the same expression:

Separators are now \s+ rather than \s*. The columns are whitespace separated,
so allowing zero whitespace only worked by backtracking.

Used and Capacity are now matched as \S+ rather than requiring digits and a
literal percent sign. Nothing reads either of them — used is recomputed from
Blocks minus Available — and `df` prints "-" in them for filesystems that do
not report usage, which was another way for a row to disappear. Blocks and
Available still require digits, because those are the values actually used.

Verified by running the new tests against the unfixed collectors: Linux
reports 1 filesystem where 5 are expected, FreeBSD 1 where 4 are expected, and
both pass after the change. The existing 7-disk expectation is untouched, so
the new pattern is a superset of the old one on output that already parsed.
FreeBSD's getDiskInfo() had no coverage at all and gains its first.

Signed-off-by: Frank Karlitschek <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
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