From 816c0a83b47d2a6086e25af2b5004da239856eb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=91=A3=E8=96=87?= Date: Mon, 22 Jan 2024 11:12:10 +0800 Subject: [PATCH] filesystem: fix mountTimeout not working issue Signed-off-by: DongWei-4 --- collector/filesystem_linux.go | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/collector/filesystem_linux.go b/collector/filesystem_linux.go index 6e7623e203..2251cc4b8f 100644 --- a/collector/filesystem_linux.go +++ b/collector/filesystem_linux.go @@ -122,16 +122,8 @@ func (c *filesystemCollector) processStat(labels filesystemLabels) filesystemSta buf := new(unix.Statfs_t) err := unix.Statfs(rootfsFilePath(labels.mountPoint), buf) - stuckMountsMtx.Lock() close(success) - // If the mount has been marked as stuck, unmark it and log it's recovery. - if _, ok := stuckMounts[labels.mountPoint]; ok { - level.Debug(c.logger).Log("msg", "Mount point has recovered, monitoring will resume", "mountpoint", labels.mountPoint) - delete(stuckMounts, labels.mountPoint) - } - stuckMountsMtx.Unlock() - if err != nil { level.Debug(c.logger).Log("msg", "Error on statfs() system call", "rootfs", rootfsFilePath(labels.mountPoint), "err", err) return filesystemStats{ @@ -161,17 +153,29 @@ func stuckMountWatcher(mountPoint string, success chan struct{}, logger log.Logg select { case <-success: // Success + // If the mount has been marked as stuck, unmark it and log it's recovery. + stuckMountsMtx.Lock() + defer stuckMountsMtx.Unlock() + if _, ok := stuckMounts[mountPoint]; ok { + level.Debug(logger).Log("msg", "Mount point has recovered, monitoring will resume", "mountpoint", mountPoint) + delete(stuckMounts, mountPoint) + } case <-mountCheckTimer.C: // Timed out, mark mount as stuck stuckMountsMtx.Lock() + defer stuckMountsMtx.Unlock() select { case <-success: // Success came in just after the timeout was reached, don't label the mount as stuck + // If the mount has been marked as stuck, unmark it and log it's recovery. + if _, ok := stuckMounts[mountPoint]; ok { + level.Debug(logger).Log("msg", "Mount point has recovered, monitoring will resume", "mountpoint", mountPoint) + delete(stuckMounts, mountPoint) + } default: level.Debug(logger).Log("msg", "Mount point timed out, it is being labeled as stuck and will not be monitored", "mountpoint", mountPoint) stuckMounts[mountPoint] = struct{}{} } - stuckMountsMtx.Unlock() } }