diff options
author | dt-rush <nickp@balena.io> | 2019-09-09 11:39:25 -0400 |
---|---|---|
committer | Ben Kochie <superq@gmail.com> | 2019-09-09 17:39:24 +0200 |
commit | 93fbb93a46ae300ae0f53b6ae6fde613bc7c51de (patch) | |
tree | f586f150165d5af8f0b89200f255e7f266cc2ade /collector | |
parent | ab8cf1f718fabb090a4cd4dedb469779c9b3b589 (diff) | |
download | prometheus_node_collector-93fbb93a46ae300ae0f53b6ae6fde613bc7c51de.tar.bz2 prometheus_node_collector-93fbb93a46ae300ae0f53b6ae6fde613bc7c51de.tar.xz prometheus_node_collector-93fbb93a46ae300ae0f53b6ae6fde613bc7c51de.zip |
fix issue where rootfs path strips to the empty string (#1464)
Change-type: patch
Connects-to: #1463
Signed-off-by: dt-rush <nickp@balena.io>
Diffstat (limited to 'collector')
-rw-r--r-- | collector/filesystem_linux_test.go | 1 | ||||
-rw-r--r-- | collector/fixtures_bindmount/proc/mounts | 1 | ||||
-rw-r--r-- | collector/paths.go | 6 |
3 files changed, 7 insertions, 1 deletions
diff --git a/collector/filesystem_linux_test.go b/collector/filesystem_linux_test.go index 267ad06..6271c19 100644 --- a/collector/filesystem_linux_test.go +++ b/collector/filesystem_linux_test.go | |||
@@ -120,6 +120,7 @@ func TestPathRootfs(t *testing.T) { | |||
120 | 120 | ||
121 | expected := map[string]string{ | 121 | expected := map[string]string{ |
122 | // should modify these mountpoints (removes /host, see fixture proc file) | 122 | // should modify these mountpoints (removes /host, see fixture proc file) |
123 | "/": "", | ||
123 | "/media/volume1": "", | 124 | "/media/volume1": "", |
124 | "/media/volume2": "", | 125 | "/media/volume2": "", |
125 | // should not modify these mountpoints | 126 | // should not modify these mountpoints |
diff --git a/collector/fixtures_bindmount/proc/mounts b/collector/fixtures_bindmount/proc/mounts index 2ef6401..32f9567 100644 --- a/collector/fixtures_bindmount/proc/mounts +++ b/collector/fixtures_bindmount/proc/mounts | |||
@@ -1,3 +1,4 @@ | |||
1 | /dev/nvme1n0 /host ext4 rw,seclabel,relatime,data=ordered 0 0 | ||
1 | /dev/nvme1n1 /host/media/volume1 ext4 rw,seclabel,relatime,data=ordered 0 0 | 2 | /dev/nvme1n1 /host/media/volume1 ext4 rw,seclabel,relatime,data=ordered 0 0 |
2 | /dev/nvme1n2 /host/media/volume2 ext4 rw,seclabel,relatime,data=ordered 0 0 | 3 | /dev/nvme1n2 /host/media/volume2 ext4 rw,seclabel,relatime,data=ordered 0 0 |
3 | tmpfs /dev/shm tmpfs rw,nosuid,nodev 0 0 | 4 | tmpfs /dev/shm tmpfs rw,nosuid,nodev 0 0 |
diff --git a/collector/paths.go b/collector/paths.go index 6150600..5f5a7b4 100644 --- a/collector/paths.go +++ b/collector/paths.go | |||
@@ -44,5 +44,9 @@ func rootfsStripPrefix(path string) string { | |||
44 | if *rootfsPath == "/" { | 44 | if *rootfsPath == "/" { |
45 | return path | 45 | return path |
46 | } | 46 | } |
47 | return strings.TrimPrefix(path, *rootfsPath) | 47 | stripped := strings.TrimPrefix(path, *rootfsPath) |
48 | if stripped == "" { | ||
49 | return "/" | ||
50 | } | ||
51 | return stripped | ||
48 | } | 52 | } |