Files
Pulse/internal/monitoring/backup_guard.go
pulse-triage[bot] 404a859356 Retain observed PBS files across timeout and throttle responses
Treat typed HTTP 408 and 429 as unread evidence, not access rejection or absence. Keep snapshot and point clocks unchanged, preserve scope boundaries and do not add retries. Namespace discovery accepts legacy absence only from actual HTTP 404, never a quoted response-body code.

Change-source: pulse-maintainer
2026-10-29 04:50:23 +00:00

37 lines
1.2 KiB
Go

package monitoring
import (
"net/http"
"strings"
"github.com/rcourtman/pulse-go-rewrite/pkg/pbs"
)
// shouldPreservePBSBackupsWithTerminal preserves stale PBS backups only when all
// datastore fetches failed and at least one failure was non-terminal.
func shouldPreservePBSBackupsWithTerminal(datastoreCount, datastoreFetches, datastoreTerminalFailure int) bool {
if datastoreCount > 0 && datastoreFetches == 0 && datastoreTerminalFailure < datastoreCount {
return true
}
return false
}
// shouldReuseCachedPBSBackups keeps cached data for transient fetch errors and
// avoids reuse for terminal API 4xx errors. A response-level timeout or rate
// limit is not a rejected scope or an accepted empty inventory. Retaining it
// neither retries a request nor renews the cached artifact's evidence.
func shouldReuseCachedPBSBackups(err error) bool {
if err == nil {
return false
}
if status, ok := pbs.HTTPStatus(err); ok {
return status == http.StatusRequestTimeout || status == http.StatusTooManyRequests ||
status < 400 || status >= 500
}
// Retain compatibility with untyped errors from older callers.
if strings.Contains(strings.ToLower(err.Error()), "api error 4") {
return false
}
return true
}