Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/do-agent/config_filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}, `|`)
Expand Down
52 changes: 52 additions & 0 deletions cmd/do-agent/config_filesystem_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"regexp"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -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)
}
}
Loading