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.

Define recovery list pagination bounds once in the recovery model

rcourtmandec1c94c27d6
diff --git a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
index 7a4985cb1a..06947835ec 100644
--- a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
+++ b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
@@ -2281,9 +2281,12 @@ Recovery list pagination-meta normalization in
`internal/api/recovery_handlers.go` (the clamped effective `limit` echoed in
`meta`, `totalPages` computed from that effective page size) is an
API-contracts and storage-recovery transport concern that lives under the
-shared `internal/api/` extension boundary. No agent lifecycle surface consumes
-the `/api/recovery/points` or `/api/recovery/rollups` list meta; lifecycle
-code MUST NOT treat that pagination meta as an agent enrollment, admission, or
+shared `internal/api/` extension boundary. The clamp bounds are the exported
+`DefaultListPageLimit` / `MaxListPageLimit` constants in
+`internal/recovery/model`, which are likewise recovery-transport vocabulary
+and not lifecycle surface. No agent lifecycle surface consumes the
+`/api/recovery/points` or `/api/recovery/rollups` list meta; lifecycle code
+MUST NOT treat that pagination meta as an agent enrollment, admission, or
report-ingestion contract.
The node connection test handlers under `internal/api/configapi/` record a
diff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.md
index e723ad1cff..b0a77aa12b 100644
--- a/docs/release-control/v6/internal/subsystems/api-contracts.md
+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md
@@ -3949,13 +3949,17 @@ the authoritative analysis outcome.
rewired.
34. Keep recovery list pagination meta honest on the shared `/api/recovery/*`
surface. `/api/recovery/points` and `/api/recovery/rollups` clamp the
- requested page size to the canonical bounds (default 100, max 500) before
- serving, in both the mock paginators and the store paths, so
- `internal/api/recovery_handlers.go` must normalize `page` and `limit` once
- at parse time and compute the response `meta` block (`page`, `limit`,
- `totalPages`) from those normalized values. The meta must echo the
- effective limit, never the raw query value, so a client iterating
- `totalPages` is never told fewer pages than the server actually serves.
+ requested page size to the canonical shared bounds
+ `recovery.DefaultListPageLimit` (100) and `recovery.MaxListPageLimit`
+ (500), defined once in `internal/recovery/model` and re-exported through
+ `internal/recovery`, before serving, in both the mock paginators and the
+ store paths, so `internal/api/recovery_handlers.go` must normalize `page`
+ and `limit` once at parse time and compute the response `meta` block
+ (`page`, `limit`, `totalPages`) from those normalized values. The meta
+ must echo the effective limit, never the raw query value, so a client
+ iterating `totalPages` is never told fewer pages than the server actually
+ serves. Handler and store clamps must derive from those exported
+ constants rather than re-hardcoding the numbers.
`internal/api/recovery_handlers_test.go` pins the above-max and
non-positive limit meta normalization in the same slice as any handler
change.
diff --git a/docs/release-control/v6/internal/subsystems/storage-recovery.md b/docs/release-control/v6/internal/subsystems/storage-recovery.md
index 0ec2541223..9cee12a832 100644
--- a/docs/release-control/v6/internal/subsystems/storage-recovery.md
+++ b/docs/release-control/v6/internal/subsystems/storage-recovery.md
@@ -1850,12 +1850,16 @@ than inferring it from an agent-source count in a runtime payload.
The `/api/recovery/points` and `/api/recovery/rollups` list transports in
`internal/api/recovery_handlers.go` clamp the requested page size to the
canonical bounds (default 100, max 500) and report their pagination meta
-(`page`, `limit`, `totalPages`) from those normalized values. The store-side
-clamps in `internal/recovery/store` (`normalizeLimit` / `normalizePage`) MUST
-stay aligned with those handler-side bounds: a storage-side change to the
-serving page size that does not move the shared handler bounds re-opens the
-`totalPages` misreport that silently truncates rollup iteration for clients
-walking the reported page count.
+(`page`, `limit`, `totalPages`) from those normalized values. Those bounds
+are defined once, as `DefaultListPageLimit` / `MaxListPageLimit` in
+`internal/recovery/model` (re-exported through `internal/recovery`), and the
+store-side clamps in `internal/recovery/store` (`normalizeLimit` /
+`normalizePage`) MUST derive from those exported constants rather than
+re-hardcoding the numbers: a storage-side page-size clamp that drifts from
+the shared bounds re-opens the `totalPages` misreport that silently
+truncates rollup iteration for clients walking the reported page count.
+`internal/recovery/store/store_test.go` pins the store clamps to the shared
+constants.
The node connection test tally persists as a bounded, day-bucketed JSON file in
the config directory, pruned to a 31-day retention window so it cannot grow
diff --git a/internal/api/recovery_handlers.go b/internal/api/recovery_handlers.go
index 68519ba6eb..7a74016cb1 100644
--- a/internal/api/recovery_handlers.go
+++ b/internal/api/recovery_handlers.go
@@ -579,13 +579,13 @@ func getDisplayItemType(d *recovery.RecoveryPointDisplay) string {
return recovery.NormalizeRecoveryItemType(d.SubjectType)
}
-// Recovery list pagination bounds. These mirror the store-side clamps in
-// internal/recovery/store (normalizeLimit/normalizePage); the handler meta must
-// be computed from the same normalized values the serving paths use, or
-// totalPages misreports the real page count.
+// Recovery list pagination bounds. Single source in internal/recovery/model,
+// shared with the store-side clamps (internal/recovery/store normalizeLimit /
+// normalizePage); the handler meta must be computed from the same normalized
+// values the serving paths use, or totalPages misreports the real page count.
const (
- recoveryDefaultPageLimit = 100
- recoveryMaxPageLimit = 500
+ recoveryDefaultPageLimit = recovery.DefaultListPageLimit
+ recoveryMaxPageLimit = recovery.MaxListPageLimit
)
func normalizeRecoveryPage(page int) int {
diff --git a/internal/api/recovery_handlers_test.go b/internal/api/recovery_handlers_test.go
index 746205625b..fe8c6d66f1 100644
--- a/internal/api/recovery_handlers_test.go
+++ b/internal/api/recovery_handlers_test.go
@@ -238,6 +238,21 @@ func TestNormalizeRecoveryLimit(t *testing.T) {
if got := (1200 + limit - 1) / limit; got != 3 {
t.Fatalf("totalPages for total=1200 at requested limit=1000 = %d, want 3", got)
}
+
+ // The handler bounds must be the shared recovery-model constants, not
+ // re-hardcoded numbers that can drift from the store-side clamps.
+ if recoveryDefaultPageLimit != recovery.DefaultListPageLimit {
+ t.Fatalf(
+ "recoveryDefaultPageLimit = %d, want shared recovery.DefaultListPageLimit %d",
+ recoveryDefaultPageLimit, recovery.DefaultListPageLimit,
+ )
+ }
+ if recoveryMaxPageLimit != recovery.MaxListPageLimit {
+ t.Fatalf(
+ "recoveryMaxPageLimit = %d, want shared recovery.MaxListPageLimit %d",
+ recoveryMaxPageLimit, recovery.MaxListPageLimit,
+ )
+ }
}
func assertRecoveryMetaUsesNormalizedLimit(t *testing.T, body []byte, wantLimit int) {
diff --git a/internal/recovery/model/types.go b/internal/recovery/model/types.go
index d49c15bf0a..27970b9611 100644
--- a/internal/recovery/model/types.go
+++ b/internal/recovery/model/types.go
@@ -200,6 +200,16 @@ type ListPointsOptions struct {
Limit int
}
+// List pagination bounds shared by every recovery list serving path. The API
+// handlers (internal/api/recovery_handlers.go) and the persistent store
+// (internal/recovery/store) must clamp ListPointsOptions.Limit to these same
+// bounds, because the handlers echo pagination meta (limit, totalPages)
+// computed from them and clients walk the reported page count.
+const (
+ DefaultListPageLimit = 100
+ MaxListPageLimit = 500
+)
+
// PointsSeriesBucket is a per-day aggregation of recovery points within a time window.
// Day is formatted as YYYY-MM-DD in the requested (client) timezone.
type PointsSeriesBucket struct {
diff --git a/internal/recovery/store/store.go b/internal/recovery/store/store.go
index 30e8645a54..dc30de59fd 100644
--- a/internal/recovery/store/store.go
+++ b/internal/recovery/store/store.go
@@ -24,8 +24,8 @@ const (
privateDirPerm = 0o700
privateFilePerm = 0o600
- defaultLimit = 100
- maxLimit = 500
+ defaultLimit = recovery.DefaultListPageLimit
+ maxLimit = recovery.MaxListPageLimit
defaultRetention = 90 * 24 * time.Hour
)
diff --git a/internal/recovery/store/store_test.go b/internal/recovery/store/store_test.go
index 290c8596f5..b5820be7a0 100644
--- a/internal/recovery/store/store_test.go
+++ b/internal/recovery/store/store_test.go
@@ -12,6 +12,32 @@ import (
"github.com/rcourtman/pulse-go-rewrite/internal/unifiedresources"
)
+func TestNormalizeLimitAndPageUseSharedListBounds(t *testing.T) {
+ t.Parallel()
+
+ if got := normalizeLimit(0); got != recovery.DefaultListPageLimit {
+ t.Fatalf("normalizeLimit(0) = %d, want shared default %d", got, recovery.DefaultListPageLimit)
+ }
+ if got := normalizeLimit(-1); got != recovery.DefaultListPageLimit {
+ t.Fatalf("normalizeLimit(-1) = %d, want shared default %d", got, recovery.DefaultListPageLimit)
+ }
+ if got := normalizeLimit(recovery.MaxListPageLimit + 1); got != recovery.MaxListPageLimit {
+ t.Fatalf(
+ "normalizeLimit(%d) = %d, want shared max %d",
+ recovery.MaxListPageLimit+1, got, recovery.MaxListPageLimit,
+ )
+ }
+ if got := normalizeLimit(250); got != 250 {
+ t.Fatalf("normalizeLimit(250) = %d, want 250", got)
+ }
+ if got := normalizePage(0); got != 1 {
+ t.Fatalf("normalizePage(0) = %d, want 1", got)
+ }
+ if got := normalizePage(3); got != 3 {
+ t.Fatalf("normalizePage(3) = %d, want 3", got)
+ }
+}
+
func TestStore_UpsertAndList(t *testing.T) {
t.Parallel()
diff --git a/internal/recovery/types.go b/internal/recovery/types.go
index af40bb7fb0..de689647c5 100644
--- a/internal/recovery/types.go
+++ b/internal/recovery/types.go
@@ -53,6 +53,11 @@ type ListPointsOptions = model.ListPointsOptions
type PointsSeriesBucket = model.PointsSeriesBucket
type PointsFacets = model.PointsFacets
+const (
+ DefaultListPageLimit = model.DefaultListPageLimit
+ MaxListPageLimit = model.MaxListPageLimit
+)
+
type VerifyIntent = model.VerifyIntent
const (