Skip to content

Commit

Permalink
fix issue where rootfs path strips to the empty string
Browse files Browse the repository at this point in the history
Change-type: patch
Connects-to: #1463
Signed-off-by: dt-rush <[email protected]>
  • Loading branch information
dt-rush committed Sep 9, 2019
1 parent 93c12e0 commit 5c8d293
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* [BUGFIX] Fix netdev nil reference on Darwin #1414
* [BUGFIX] Strip path.rootfs from mountpoint labels #1421
* [FEATURE] Add new thermal_zone collector #1425
* [BUGFIX] Fix empty string in path.rootfs #1464

## 0.18.1 / 2019-06-04

Expand Down
1 change: 1 addition & 0 deletions collector/filesystem_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ func TestPathRootfs(t *testing.T) {

expected := map[string]string{
// should modify these mountpoints (removes /host, see fixture proc file)
"/": "",
"/media/volume1": "",
"/media/volume2": "",
// should not modify these mountpoints
Expand Down
1 change: 1 addition & 0 deletions collector/fixtures_bindmount/proc/mounts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/dev/nvme1n0 /host ext4 rw,seclabel,relatime,data=ordered 0 0
/dev/nvme1n1 /host/media/volume1 ext4 rw,seclabel,relatime,data=ordered 0 0
/dev/nvme1n2 /host/media/volume2 ext4 rw,seclabel,relatime,data=ordered 0 0
tmpfs /dev/shm tmpfs rw,nosuid,nodev 0 0
Expand Down
6 changes: 5 additions & 1 deletion collector/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,9 @@ func rootfsStripPrefix(path string) string {
if *rootfsPath == "/" {
return path
}
return strings.TrimPrefix(path, *rootfsPath)
stripped := strings.TrimPrefix(path, *rootfsPath)
if stripped == "" {
return "/"
}
return stripped
}

0 comments on commit 5c8d293

Please sign in to comment.