fix(readiness): name only the filesystems over their limit

This commit is contained in:
sam committed 2026-10-24 11:41:48 +11:00
1 parent fb7dcbe6cb
commit 09b0ad37f1
1 file changed
+12 -15
+12 -15
View File
@@ -225,31 +225,32 @@ func (p *DiskProbe) Check(ctx context.Context) health.Result {
if statfs == nil {
statfs = syscall.Statfs
}
var details []string
degraded := false
// A degraded result names only the failing filesystems: a healthy one
// beside it is noise to the operator reading why.
var details, problems []string
for _, target := range reduceTargets(targets) {
var stat syscall.Statfs_t
if err := statfs(target.Path, &stat); err != nil {
if target.Optional && errors.Is(err, os.ErrNotExist) {
continue
}
degraded = true
details = append(details, fmt.Sprintf("%s (%s): statfs failed: %v", target.Name, target.Path, err))
problems = append(problems, fmt.Sprintf("%s %s: statfs failed: %v", target.Name, target.Path, err))
continue
}
if stat.Blocks == 0 {
degraded = true
details = append(details, fmt.Sprintf("%s (%s): cannot size filesystem", target.Name, target.Path))
problems = append(problems, fmt.Sprintf("%s %s: cannot size filesystem", target.Name, target.Path))
continue
}
used := stat.Blocks - stat.Bavail
pct := float64(used) / float64(stat.Blocks)
status := "ok"
if pct >= p.Threshold {
status = "degraded"
degraded = true
problems = append(problems, fmt.Sprintf("%s %s is %.0f%% full (limit %.0f%%)", target.Name, target.Path, pct*100, p.Threshold*100))
continue
}
details = append(details, fmt.Sprintf("%s (%s): %.0f%% used (limit %.0f%%), %s", target.Name, target.Path, pct*100, p.Threshold*100, status))
details = append(details, fmt.Sprintf("%s %.0f%%", target.Name, pct*100))
}
if len(problems) > 0 {
return health.Result{Status: health.StatusDegraded, Detail: strings.Join(problems, "; ")}
}
if len(details) == 0 {
for _, target := range targets {
@@ -259,11 +260,7 @@ func (p *DiskProbe) Check(ctx context.Context) health.Result {
}
return health.Result{Status: health.StatusOK, Detail: "no optional disk targets present"}
}
result := health.Result{Status: health.StatusOK, Detail: strings.Join(details, "; ")}
if degraded {
result.Status = health.StatusDegraded
}
return result
return health.Result{Status: health.StatusOK, Detail: strings.Join(details, ", ")}
}
// --- model ---