From 5c8d29332659607266b22e1b9176fcd50072fd05 Mon Sep 17 00:00:00 2001 From: dt-rush Date: Thu, 29 Aug 2019 11:54:09 -0400 Subject: [PATCH] fix issue where rootfs path strips to the empty string Change-type: patch Connects-to: #1463 Signed-off-by: dt-rush --- CHANGELOG.md | 1 + collector/filesystem_linux_test.go | 1 + collector/fixtures_bindmount/proc/mounts | 1 + collector/paths.go | 6 +++++- 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ecffe9ab8b..df77c17b4b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/collector/filesystem_linux_test.go b/collector/filesystem_linux_test.go index 267ad062b9..6271c19130 100644 --- a/collector/filesystem_linux_test.go +++ b/collector/filesystem_linux_test.go @@ -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 diff --git a/collector/fixtures_bindmount/proc/mounts b/collector/fixtures_bindmount/proc/mounts index 2ef64015d5..32f9567e98 100644 --- a/collector/fixtures_bindmount/proc/mounts +++ b/collector/fixtures_bindmount/proc/mounts @@ -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 diff --git a/collector/paths.go b/collector/paths.go index 61506008b8..5f5a7b44b3 100644 --- a/collector/paths.go +++ b/collector/paths.go @@ -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 }