de43a71929
When the disk (or memory) tier is at cap or the volume returns ENOSPC, ops currently look like random misses with no clear "we are dropping data." Count those events as capacity_pressure_events on /metrics and log tier plus reason so operators can tell capacity pressure from a cold cache, without changing the existing evictions counter. Link: #36
59 lines
1.3 KiB
Go
59 lines
1.3 KiB
Go
//go:build !windows
|
|
|
|
package disk
|
|
|
|
import (
|
|
"io"
|
|
"os"
|
|
"testing"
|
|
|
|
"golang.org/x/sys/unix"
|
|
|
|
"s1d3sw1ped/steamcache2/steamcache/metrics"
|
|
)
|
|
|
|
func TestIsNoSpaceError(t *testing.T) {
|
|
t.Parallel()
|
|
if isNoSpaceError(nil) {
|
|
t.Error("nil must not be ENOSPC")
|
|
}
|
|
if isNoSpaceError(io.EOF) {
|
|
t.Error("EOF must not be ENOSPC")
|
|
}
|
|
if !isNoSpaceError(unix.ENOSPC) {
|
|
t.Error("unix.ENOSPC should match")
|
|
}
|
|
wrapped := &os.PathError{Op: "write", Path: "x", Err: unix.ENOSPC}
|
|
if !isNoSpaceError(wrapped) {
|
|
t.Error("PathError wrapping ENOSPC should match")
|
|
}
|
|
}
|
|
|
|
func TestDiskFS_ENOSPCCapacityPressure(t *testing.T) {
|
|
t.Parallel()
|
|
d, err := New(t.TempDir(), 1024, nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
met := metrics.NewMetrics()
|
|
d.SetMetrics(met)
|
|
|
|
d.recordIfNoSpace(io.EOF)
|
|
if got := met.GetStats().CapacityPressureEvents; got != 0 {
|
|
t.Fatalf("non-ENOSPC counted: %d", got)
|
|
}
|
|
|
|
d.recordIfNoSpace(unix.ENOSPC)
|
|
if got := met.GetStats().CapacityPressureEvents; got != 1 {
|
|
t.Fatalf("unix.ENOSPC: CapacityPressureEvents=%d, want 1", got)
|
|
}
|
|
if got := met.GetStats().Evictions; got != 0 {
|
|
t.Fatalf("ENOSPC must not increment evictions, got %d", got)
|
|
}
|
|
|
|
d.recordIfNoSpace(&os.PathError{Op: "write", Path: "p", Err: unix.ENOSPC})
|
|
if got := met.GetStats().CapacityPressureEvents; got != 2 {
|
|
t.Fatalf("wrapped ENOSPC: CapacityPressureEvents=%d, want 2", got)
|
|
}
|
|
}
|