From 36a0824f1fb7682396d08642c2fca4262812e506 Mon Sep 17 00:00:00 2001 From: Natalia Marukovich Date: Thu, 26 Feb 2026 09:25:07 +0100 Subject: [PATCH 1/4] PMM-14832 make mount path configurable --- collector/filesystem_linux.go | 12 ++++++++++-- collector/filesystem_linux_test.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/collector/filesystem_linux.go b/collector/filesystem_linux.go index 59e909e252..fb40a9cf9b 100644 --- a/collector/filesystem_linux.go +++ b/collector/filesystem_linux.go @@ -43,6 +43,9 @@ var mountTimeout = kingpin.Flag("collector.filesystem.mount-timeout", var statWorkerCount = kingpin.Flag("collector.filesystem.stat-workers", "how many stat calls to process simultaneously"). Hidden().Default("4").Int() +var mountInfoPath = kingpin.Flag("collector.filesystem.mount-info-path", + "Override path to mounts file. If set, disables the default /proc/1/mounts fallback logic."). + Default("").String() var stuckMounts = make(map[string]struct{}) var stuckMountsMtx = &sync.Mutex{} @@ -178,8 +181,13 @@ func stuckMountWatcher(mountPoint string, success chan struct{}, logger log.Logg } func mountPointDetails(logger log.Logger) ([]filesystemLabels, error) { - file, err := os.Open(procFilePath("1/mounts")) - if errors.Is(err, os.ErrNotExist) { + path := procFilePath("1/mounts") + if *mountInfoPath != "" { + path = *mountInfoPath + } + + file, err := os.Open(path) + if errors.Is(err, os.ErrNotExist) && *mountInfoPath == "" { // Fallback to `/proc/mounts` if `/proc/1/mounts` is missing due hidepid. level.Debug(logger).Log("msg", "Reading root mounts failed, falling back to system mounts", "err", err) file, err = os.Open(procFilePath("mounts")) diff --git a/collector/filesystem_linux_test.go b/collector/filesystem_linux_test.go index 325ffc87b2..94aaeef565 100644 --- a/collector/filesystem_linux_test.go +++ b/collector/filesystem_linux_test.go @@ -142,3 +142,32 @@ func TestPathRootfs(t *testing.T) { } } } + +func TestMountInfoPathOverride(t *testing.T) { + // --path.procfs points to fixtures with 25+ mount points, + // but --collector.filesystem.mount-info-path overrides to a file with only 1 mount. + if _, err := kingpin.CommandLine.Parse([]string{ + "--path.procfs", "./fixtures/proc", + "--collector.filesystem.mount-info-path", "./fixtures_hidepid/proc/mounts", + }); err != nil { + t.Fatal(err) + } + + expected := map[string]string{ + "/": "", + } + + filesystems, err := mountPointDetails(log.NewNopLogger()) + if err != nil { + t.Fatal(err) + } + + if len(filesystems) != len(expected) { + t.Errorf("expected %d mounts, got %d", len(expected), len(filesystems)) + } + for _, fs := range filesystems { + if _, ok := expected[fs.mountPoint]; !ok { + t.Errorf("Got unexpected %s", fs.mountPoint) + } + } +} From e3877c100a9bcc3839169cc91d436be7fb7d8cd3 Mon Sep 17 00:00:00 2001 From: Alex Demidoff Date: Fri, 27 Mar 2026 12:52:32 +0300 Subject: [PATCH 2/4] chore: update the test --- collector/filesystem_linux_test.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/collector/filesystem_linux_test.go b/collector/filesystem_linux_test.go index 94aaeef565..2b7fcb7c1d 100644 --- a/collector/filesystem_linux_test.go +++ b/collector/filesystem_linux_test.go @@ -144,12 +144,23 @@ func TestPathRootfs(t *testing.T) { } func TestMountInfoPathOverride(t *testing.T) { + // Save and restore flag values so changes don't leak into other tests. + priorMountInfoPath := *mountInfoPath + priorProcPath := *procPath + t.Cleanup(func() { + _, _ = kingpin.CommandLine.Parse([]string{ + "--path.procfs", priorProcPath, + "--collector.filesystem.mount-info-path", priorMountInfoPath, + }) + }) + // --path.procfs points to fixtures with 25+ mount points, // but --collector.filesystem.mount-info-path overrides to a file with only 1 mount. - if _, err := kingpin.CommandLine.Parse([]string{ + _, err := kingpin.CommandLine.Parse([]string{ "--path.procfs", "./fixtures/proc", "--collector.filesystem.mount-info-path", "./fixtures_hidepid/proc/mounts", - }); err != nil { + }) + if err != nil { t.Fatal(err) } From 8b08bd6ee510283e078b8639395ff997c2b7d2f0 Mon Sep 17 00:00:00 2001 From: Alex Demidoff Date: Fri, 27 Mar 2026 14:44:05 +0300 Subject: [PATCH 3/4] PMM-14832 Rename the parameter --- collector/filesystem_linux.go | 9 ++++----- collector/filesystem_linux_test.go | 10 +++++----- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/collector/filesystem_linux.go b/collector/filesystem_linux.go index fb40a9cf9b..eb0fa651c3 100644 --- a/collector/filesystem_linux.go +++ b/collector/filesystem_linux.go @@ -18,7 +18,6 @@ package collector import ( "bufio" - "errors" "fmt" "io" "os" @@ -43,7 +42,7 @@ var mountTimeout = kingpin.Flag("collector.filesystem.mount-timeout", var statWorkerCount = kingpin.Flag("collector.filesystem.stat-workers", "how many stat calls to process simultaneously"). Hidden().Default("4").Int() -var mountInfoPath = kingpin.Flag("collector.filesystem.mount-info-path", +var procMountsPath = kingpin.Flag("collector.filesystem.proc-mounts-path", "Override path to mounts file. If set, disables the default /proc/1/mounts fallback logic."). Default("").String() var stuckMounts = make(map[string]struct{}) @@ -182,12 +181,12 @@ func stuckMountWatcher(mountPoint string, success chan struct{}, logger log.Logg func mountPointDetails(logger log.Logger) ([]filesystemLabels, error) { path := procFilePath("1/mounts") - if *mountInfoPath != "" { - path = *mountInfoPath + if *procMountsPath != "" { + path = *procMountsPath } file, err := os.Open(path) - if errors.Is(err, os.ErrNotExist) && *mountInfoPath == "" { + if err != nil && *procMountsPath == "" { // Fallback to `/proc/mounts` if `/proc/1/mounts` is missing due hidepid. level.Debug(logger).Log("msg", "Reading root mounts failed, falling back to system mounts", "err", err) file, err = os.Open(procFilePath("mounts")) diff --git a/collector/filesystem_linux_test.go b/collector/filesystem_linux_test.go index 2b7fcb7c1d..756456cde9 100644 --- a/collector/filesystem_linux_test.go +++ b/collector/filesystem_linux_test.go @@ -143,22 +143,22 @@ func TestPathRootfs(t *testing.T) { } } -func TestMountInfoPathOverride(t *testing.T) { +func TestProcMountsPathOverride(t *testing.T) { // Save and restore flag values so changes don't leak into other tests. - priorMountInfoPath := *mountInfoPath + priorProcMountsPath := *procMountsPath priorProcPath := *procPath t.Cleanup(func() { _, _ = kingpin.CommandLine.Parse([]string{ "--path.procfs", priorProcPath, - "--collector.filesystem.mount-info-path", priorMountInfoPath, + "--collector.filesystem.proc-mounts-path", priorProcMountsPath, }) }) // --path.procfs points to fixtures with 25+ mount points, - // but --collector.filesystem.mount-info-path overrides to a file with only 1 mount. + // but --collector.filesystem.proc-mounts-path overrides to a file with only 1 mount. _, err := kingpin.CommandLine.Parse([]string{ "--path.procfs", "./fixtures/proc", - "--collector.filesystem.mount-info-path", "./fixtures_hidepid/proc/mounts", + "--collector.filesystem.proc-mounts-path", "./fixtures_hidepid/proc/mounts", }) if err != nil { t.Fatal(err) From c6bae39dacab283c363efdcedb4f3026a1c8888e Mon Sep 17 00:00:00 2001 From: Alex Demidoff Date: Fri, 27 Mar 2026 14:49:39 +0300 Subject: [PATCH 4/4] PMM-14832 Update the param description --- collector/filesystem_linux.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/collector/filesystem_linux.go b/collector/filesystem_linux.go index eb0fa651c3..86f0f1016b 100644 --- a/collector/filesystem_linux.go +++ b/collector/filesystem_linux.go @@ -43,7 +43,7 @@ var statWorkerCount = kingpin.Flag("collector.filesystem.stat-workers", "how many stat calls to process simultaneously"). Hidden().Default("4").Int() var procMountsPath = kingpin.Flag("collector.filesystem.proc-mounts-path", - "Override path to mounts file. If set, disables the default /proc/1/mounts fallback logic."). + "Override absolute path to mounts file. If set, disables the default /proc/1/mounts fallback logic."). Default("").String() var stuckMounts = make(map[string]struct{}) var stuckMountsMtx = &sync.Mutex{}