fix: issue #131, disk metric not shown when using LVM#143
fix: issue #131, disk metric not shown when using LVM#143adosaiguas wants to merge 1 commit intobluewave-labs:developfrom
Conversation
WalkthroughEnhanced disk metrics collection in the internal/metric package with improved error aggregation for partial data collection, device-mapper device resolution via sysfs lookup, and test-friendly sysfsRoot override mechanism. Added comprehensive tests for device mapper name resolution and key candidate generation. No exported API changes. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
internal/metric/disk.go(5 hunks)internal/metric/disk_test.go(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
internal/metric/disk.go (2)
internal/metric/metric.go (3)
CustomErr(40-43)Metric(7-9)DiskData(66-80)internal/metric/metric_math.go (1)
RoundFloatPtr(11-14)
🔇 Additional comments (10)
internal/metric/disk_test.go (2)
11-34: LGTM! Good test coverage for DM name resolution.The test properly simulates sysfs structure and validates the core LVM support functionality. The test creates a realistic directory hierarchy and verifies correct resolution from mapper name to dm device.
41-45: No changes needed. Tests in the same package run sequentially by default, and this test doesn't callt.Parallel(). Thet.Cleanup()approach correctly preserves and restores the package-levelsysfsRootvariable, which is safe for sequential execution.internal/metric/disk.go (8)
4-4: LGTM! Import additions align with new functionality.The
osandsortimports are needed for the new sysfs file reading and error aggregation features.Also applies to: 7-7
13-14: LGTM! Good testability pattern.The
sysfsRootvariable allows tests to inject temporary sysfs structures while maintaining the standard/syspath in production.
94-141: Excellent improvement! Partial data collection enhances resilience.The refactored
collectPartitionMetricsnow accumulates errors and returns partial results when available, rather than failing completely if one metric is unavailable. This is especially valuable for LVM devices where IO or usage stats might not always be accessible through the same paths.The progressive construction of
DiskData(lines 117-134) ensures that users see whatever metrics are available, improving the overall user experience.
143-166: LGTM! Well-implemented error aggregation.The
mergeDiskErrorsfunction properly deduplicates metrics, filters empty messages, and ensures deterministic output through sorting. This provides clean, consolidated error reporting when multiple metrics fail.
229-234: Core LVM fix! Device-mapper resolution via sysfs.This enhancement resolves
/dev/mapper/*devices to their correspondingdm-Nidentifiers by querying sysfs, which is essential for matching LVM devices against the keys returned bydisk.IOCounters(). This directly addresses issue #131.
251-277: LGTM! Robust sysfs-based device mapper resolution.The implementation correctly:
- Validates input (line 252)
- Uses glob patterns to find all dm devices (line 256)
- Handles read errors gracefully by continuing (line 265)
- Uses
TrimSpaceto normalize names from sysfs files (line 267)- Extracts the dm-N identifier through proper path manipulation (lines 272-273)
The function is resilient to missing devices and read errors, making it suitable for production use.
338-341: Good refactor: Using empty struct for set membership.Using
struct{}{}instead oftruefor map-based sets is idiomatic Go and more memory-efficient, as empty structs consume zero bytes.
348-350: LGTM! Defensive programming prevents nil metrics.The nil check ensures that only valid
DiskDataentries are appended to the metrics slice, which aligns with the refactoredcollectPartitionMetricsthat may return nil when no stats are available (lines 109-114).
|
@coderabbitai generate docstrings |
✅ Actions performedInitiated docstring generation; will generate only if new commits exist. |
|
Note Docstrings generation - SUCCESS |
Docstrings generation was requested by @adosaiguas. * #143 (comment) The following files were modified: * `internal/metric/disk.go`
Fixes issue #131
If an LVM device is detected (
/dev/mapper), we handle this other use case.Added some unit tests.