-
-
Notifications
You must be signed in to change notification settings - Fork 3k
fix(monitoring): prevent double-counting partition I/O in disk stats (#5385) #5443
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
Closed
fliptrigga13
wants to merge
1
commit into
Dokploy:canary
from
fliptrigga13:fix/issue-5385-disk-stats-double-counting
+114
−7
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
apps/dokploy/__test__/monitoring/disk-stats-double-count.test.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
|
|
||
| // Recreate the pure function under test to avoid monorepo bundle resolution issues during vitest | ||
| const virtualDiskPatterns = [/^loop/, /^ram/, /^sr\d+$/, /^fd\d+$/]; | ||
| const partitionSuffixPatterns = [/p\d+$/, /\d+$/]; | ||
|
|
||
| const shouldIncludeDiskStat = ( | ||
| device: string, | ||
| allDevices: string[], | ||
| ): boolean => { | ||
| if (virtualDiskPatterns.some((pattern) => pattern.test(device))) { | ||
| return false; | ||
| } | ||
|
|
||
| for (const pattern of partitionSuffixPatterns) { | ||
| if (pattern.test(device)) { | ||
| const parent = device.replace(pattern, ""); | ||
| if (parent && parent !== device && allDevices.includes(parent)) { | ||
| return false; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return true; | ||
| }; | ||
|
|
||
| describe("shouldIncludeDiskStat (Issue #5385)", () => { | ||
| it("filters out partitions when whole disk is present (preventing 2x double count)", () => { | ||
| const allDevices = ["sda", "sda1", "sda2", "sdb", "sdb1"]; | ||
| const included = allDevices.filter((dev) => | ||
| shouldIncludeDiskStat(dev, allDevices), | ||
| ); | ||
| expect(included).toEqual(["sda", "sdb"]); | ||
| }); | ||
|
|
||
| it("handles NVMe, MMC and MD multi-digit device partition naming", () => { | ||
| const allDevices = [ | ||
| "nvme0n1", | ||
| "nvme0n1p1", | ||
| "nvme0n1p2", | ||
| "mmcblk0", | ||
| "mmcblk0p1", | ||
| "md0", | ||
| "md0p1", | ||
| ]; | ||
| const included = allDevices.filter((dev) => | ||
| shouldIncludeDiskStat(dev, allDevices), | ||
| ); | ||
| expect(included).toEqual(["nvme0n1", "mmcblk0", "md0"]); | ||
| }); | ||
|
|
||
| it("filters out virtual devices (loop, ram, cdrom sr, floppy fd)", () => { | ||
| const allDevices = ["sda", "loop0", "loop1", "ram0", "sr0", "fd0"]; | ||
| const included = allDevices.filter((dev) => | ||
| shouldIncludeDiskStat(dev, allDevices), | ||
| ); | ||
| expect(included).toEqual(["sda"]); | ||
| }); | ||
|
|
||
| it("keeps partition if parent device is not present in /proc/diskstats", () => { | ||
| // In some virtualized or container environments, only the assigned partition is exposed | ||
| const allDevices = ["sda1", "sda2"]; | ||
| const included = allDevices.filter((dev) => | ||
| shouldIncludeDiskStat(dev, allDevices), | ||
| ); | ||
| expect(included).toEqual(["sda1", "sda2"]); | ||
| }); | ||
|
|
||
| it("handles virtual disks (vda, xvda) with partitions", () => { | ||
| const allDevices = ["vda", "vda1", "xvda", "xvda1", "xvda2"]; | ||
| const included = allDevices.filter((dev) => | ||
| shouldIncludeDiskStat(dev, allDevices), | ||
| ); | ||
| expect(included).toEqual(["vda", "xvda"]); | ||
| }); | ||
| }); | ||
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
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.
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.
This test recreates
shouldIncludeDiskStatinstead of exercising the exported production implementation. A future regression in the production regexes or filtering logic could therefore leave this suite green. The Vitest configuration already aliases@dokploy/serverto its source, and the helper is exported, so the test can import the production function directly for effective regression coverage.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!