From cb2c0c7e263a02221559b530f913876dea6e9bbe Mon Sep 17 00:00:00 2001 From: iwankgb Date: Fri, 4 Oct 2024 21:58:56 +0200 Subject: [PATCH] Merge pull request #3522 from clwluvw/hidden-device sysfs: trim spaces in device hidden check (cherry picked from commit 96c346ed6af33ecc856f82dfd9ef6b0fd6b66949) Backports https://github.com/google/cadvisor/pull/3522 from cadvisor v0.51.0. This is needed to fix container_fs_ metrics on systems with multipath devices. Without it, errors like: Failed to get disk map: open /sys/block/nvme0c0n1/dev will be logged, and cadvisor will emit nonsensical metrics with the label device="" for filesystem I/O. See https://github.com/google/cadvisor/issues/3693 for full explanation. Signed-off-by: Craig Ringer --- utils/sysfs/sysfs.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/utils/sysfs/sysfs.go b/utils/sysfs/sysfs.go index dbf7e000e4..f2aedfc757 100644 --- a/utils/sysfs/sysfs.go +++ b/utils/sysfs/sysfs.go @@ -254,10 +254,8 @@ func (fs *realSysFs) IsBlockDeviceHidden(name string) (bool, error) { if err != nil { return false, fmt.Errorf("failed to read %s: %w", devHiddenPath, err) } - if string(hidden) == "1" { - return true, nil - } - return false, nil + + return strings.TrimSpace(string(hidden)) == "1", nil } func (fs *realSysFs) GetBlockDeviceScheduler(name string) (string, error) {