From f67412eecc1fb193302786202dd33b8c253a5b63 Mon Sep 17 00:00:00 2001 From: Alvin Nguyen <12720404+alvinnguyen0@users.noreply.github.com> Date: Tue, 1 Sep 2026 17:06:10 -0700 Subject: [PATCH] fix filesystem collectors --- cmd/do-agent/config_filesystem.go | 4 +- cmd/do-agent/config_filesystem_test.go | 52 ++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/cmd/do-agent/config_filesystem.go b/cmd/do-agent/config_filesystem.go index 00d0d485..5dd7ae3d 100644 --- a/cmd/do-agent/config_filesystem.go +++ b/cmd/do-agent/config_filesystem.go @@ -8,14 +8,14 @@ import ( const ( ignoredMountPointFlag = "--collector.filesystem.ignored-mount-points" ignoredFSTypesFlag = "--collector.filesystem.ignored-fs-types" - ignoredMountPoints = `^/(rootfs/)?(boot|sys|proc|dev|host|etc|tmp|usr/(home|ports|src)|var/(audit|crash|log|mail|tmp)|var/(lib|run)/docker/[^$]+|run/docker/[^$]+)($$|/)` + ignoredMountPoints = `^/(rootfs/)?(boot|sys|proc|dev|host|etc|tmp|usr/(home|ports|src)|var/(audit|crash|log|mail|tmp)|var/(lib|run)/(docker|containerd)/[^$]+|run/(docker|containerd)/[^$]+)($$|/)` ) var ( ignoredFSTypes = strings.Join([]string{ "aufs", "autofs", "binfmt_misc", "cd9660", "cifs", "cgroup", "debugfs", "devpts", "devtmpfs", "ecryptfs", "efivarfs", "fuse", - "hugetlbfs", "mqueue", "nfs", "overlayfs", "proc", "pstore", + "hugetlbfs", "mqueue", "nfs", "overlay", "proc", "pstore", "rpc_pipefs", "securityfs", "smb", "sysfs", "tmpfs", "tracefs", "squashfs", "nsfs", }, `|`) diff --git a/cmd/do-agent/config_filesystem_test.go b/cmd/do-agent/config_filesystem_test.go index fc6903e0..a214cfe4 100644 --- a/cmd/do-agent/config_filesystem_test.go +++ b/cmd/do-agent/config_filesystem_test.go @@ -1,6 +1,7 @@ package main import ( + "regexp" "testing" "github.com/stretchr/testify/assert" @@ -21,3 +22,54 @@ func TestRegisterFilesystemFlagsRegistersMountPointFlag(t *testing.T) { assert.NotEmpty(t, additionalParams) assert.Contains(t, additionalParams, ignoredMountPoints) } + +func TestIgnoredMountPointsMatching(t *testing.T) { + re := regexp.MustCompile(ignoredMountPoints) + + tests := []struct { + mountPoint string + ignored bool + }{ + {"/", false}, + {"/scratch", false}, + {"/mnt/doscratch", false}, + {"/boot", true}, + {"/proc", true}, + {"/sys", true}, + {"/dev", true}, + {"/host", true}, + {"/var/lib/docker/overlay2/abc123", true}, + {"/run/docker/netns/default", true}, + {"/run/containerd/io.containerd.runtime.v2.task/k8s.io/abc123/rootfs", true}, + {"/var/lib/containerd/io.containerd.snapshotter.v1.overlayfs/snapshots/42/fs", true}, + } + + for _, tt := range tests { + got := re.MatchString(tt.mountPoint) + assert.Equal(t, tt.ignored, got, "mount point %q: got ignored=%t, want ignored=%t", tt.mountPoint, got, tt.ignored) + } +} + +func TestIgnoredFSTypesMatching(t *testing.T) { + re := regexp.MustCompile(ignoredFSTypes) + + tests := []struct { + fsType string + ignored bool + }{ + {"ext4", false}, + {"xfs", false}, + {"btrfs", false}, + {"overlay", true}, + {"overlayfs", true}, + {"tmpfs", true}, + {"sysfs", true}, + {"proc", true}, + {"nsfs", true}, + } + + for _, tt := range tests { + got := re.MatchString(tt.fsType) + assert.Equal(t, tt.ignored, got, "fs type %q: got ignored=%t, want ignored=%t", tt.fsType, got, tt.ignored) + } +}