Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Avoid per-directory allocations while filtering disk mounts

pulse-triage[bot]9ccfb98ee1f9
diff --git a/pkg/fsfilters/filters.go b/pkg/fsfilters/filters.go
index 842c0cf628..8a9d966d29 100644
--- a/pkg/fsfilters/filters.go
+++ b/pkg/fsfilters/filters.go
@@ -167,7 +167,10 @@ func ShouldSkipFilesystem(fsType, mountpoint string, totalBytes, usedBytes uint6
// These identify directories, not arbitrary string prefixes. A local
// /snapshots or /runtime volume is not a child of /snap or /run.
directory := strings.TrimSuffix(prefix, "/")
- if mountpoint == directory || strings.HasPrefix(mountpoint, directory+"/") {
+ // Inspect the boundary instead of allocating a slash-suffixed prefix
+ // for each directory on every disk poll.
+ if strings.HasPrefix(mountpoint, directory) &&
+ (len(mountpoint) == len(directory) || mountpoint[len(directory)] == '/') {
reasons = append(reasons, "special-mountpoint")
break
}
diff --git a/pkg/fsfilters/mount_allocation_test.go b/pkg/fsfilters/mount_allocation_test.go
new file mode 100644
index 0000000000..e4956e32ff
--- /dev/null
+++ b/pkg/fsfilters/mount_allocation_test.go
@@ -0,0 +1,33 @@
+package fsfilters
+
+import (
+ "strings"
+ "testing"
+)
+
+func TestEligibleFilesystemFilteringDoesNotAllocate(t *testing.T) {
+ paths := []string{"", "/", "/data", "C:\\", " /runtime "}
+ for _, prefix := range specialMountPrefixes {
+ directory := strings.TrimSuffix(prefix, "/")
+ // Exercise short and long mismatches, including the macOS prefixes
+ // whose slash-suffixed strings cannot fit a Go stack concat buffer.
+ for _, suffix := range []string{"s", "-data", ".backup"} {
+ paths = append(paths, directory+suffix, directory+suffix+"/child/mount")
+ }
+ }
+ for _, path := range paths {
+ t.Run(path, func(t *testing.T) {
+ var skip bool
+ var reasons []string
+ allocs := testing.AllocsPerRun(1000, func() {
+ skip, reasons = ShouldSkipFilesystem("ext4", path, 1000, 1000)
+ })
+ if skip || len(reasons) != 0 {
+ t.Fatalf("independent local volume was hidden: skip=%t, reasons=%v", skip, reasons)
+ }
+ if allocs != 0 {
+ t.Fatalf("eligible filesystem filtering allocated %g objects per call, want zero", allocs)
+ }
+ })
+ }
+}