hub v0.161.0: passphrase keys only until the box uses its own (box-config route; R-1159, D19); ep0 namespaces without a prune job alarmed, tenantsync v1.3.0 creates the job (R-1165)
gates / gates (push) Successful in 7m47s

This commit is contained in:
admin committed 2026-10-19 15:55:45 +02:00
1 parent 224fe41e06
commit b6a911c3f9
16 files changed
+802 -35

No files matched your search

+3 -2
View File
@@ -82,9 +82,10 @@ func TestOffsiteBox_OversubMath(t *testing.T) {
}
// captureEvents records (eventType, severity, customerID) per emit.
type capturedBox struct{ typ, sev, cust []string }
type capturedBox struct{ typ, sev, cust, msg []string }
func (c *capturedBox) fn(cust, et, sev, _, _, _ string) {
func (c *capturedBox) fn(cust, et, sev, msg, _, _ string) {
c.msg = append(c.msg, msg)
c.cust = append(c.cust, cust)
c.typ = append(c.typ, et)
c.sev = append(c.sev, sev)
+36
View File
@@ -6,6 +6,8 @@ import (
"errors"
"fmt"
"log"
"sort"
"strings"
"sync"
"time"
@@ -55,6 +57,11 @@ type PBSDRBoxChecker struct {
reachAlerted bool // an unreachable event has been emitted for the CURRENT outage
reachFirstFail time.Time // start of the current outage → the honest blind_for duration
lastOK time.Time // last successful read; zero = never (born blind — do NOT fabricate one)
// PRUNE COVERAGE (v0.161.0, R-1165) — a THIRD signal: household namespaces on ep0 that no prune job covers keep
// every whole-guest copy for ever (box tokens are write-only; pruning is server-side). Alarmed when the set
// changes to a non-empty one (a hub restart alarms once, the F2 rule); an empty set re-arms silently.
unprunedAlerted string // the sorted, comma-joined set last alarmed; "" = none outstanding
}
// pbsdrBoxScope is the customer-less cooldown/display key for PBS-DR box events.
@@ -191,6 +198,35 @@ func (c *PBSDRBoxChecker) Check() {
c.emitFill(snap, snap.FillBand)
}
c.fillBand = snap.FillBand
c.checkPruneCoverage(usage)
}
// checkPruneCoverage raises pbsdr_namespace_without_prune_job (R-1165). An unread list (an endpoint before
// tenantsync v1.3.0, or a job list it could not read) changes nothing — never "all covered".
func (c *PBSDRBoxChecker) checkPruneCoverage(usage tenantsync.BoxUsage) {
if !usage.UnprunedChecked {
return
}
ns := append([]string(nil), usage.Unpruned...)
sort.Strings(ns)
key := strings.Join(ns, ",")
if key == c.unprunedAlerted {
return
}
c.unprunedAlerted = key
if key == "" {
c.logger.Printf("[INFO] PBS-DR box: every household namespace has a prune job again")
return
}
details, _ := json.Marshal(map[string]any{"scope": pbsdrBoxScope, "namespaces": ns})
msg := fmt.Sprintf("PBS DR datastore: %d household namespace(s) have no prune job, so their whole-guest copies are never pruned: %s. "+
"Add one per namespace (keep-weekly 2, 03:30 — the shape tenantsync v1.3.0 creates), after reading what it would remove.",
len(ns), key)
c.logger.Printf("[WARN] PBS-DR box: namespaces without a prune job: %s", key)
if c.onEvent != nil {
c.onEvent(pbsdrBoxScope, "pbsdr_namespace_without_prune_job", "warning", msg, string(details), "hub")
}
}
// Snapshot returns the cached aggregate + whether one exists (mutex copy-out). The web layer's only
+58
View File
@@ -3,6 +3,7 @@ package monitor
import (
"context"
"fmt"
"strings"
"sync"
"testing"
"time"
@@ -158,3 +159,60 @@ func TestPBSDRBox_DegradedKeepsLast(t *testing.T) {
t.Fatalf("a failed poll must not emit, got %d", count(ev.typ, "pbsdr_box_fill"))
}
}
// R-1165: household namespaces with no prune job. A non-empty set alarms once (operator scope); the same set again is
// silent; a changed set alarms again; an empty set re-arms silently; an UNREAD list (old endpoint, unreadable jobs)
// changes nothing — it never reads as „all covered".
//
// COMPANION RED-PROOF (observed 2026-10-19): with checkPruneCoverage's call removed from Check this fails with
//
// pbsdr_box_test.go: two unpruned namespaces → want 1 pbsdr_namespace_without_prune_job, got 0
//
// Restored.
func TestPBSDRBox_R1165_NamespaceWithoutPruneJob(t *testing.T) {
f := &fakeUsage{}
ev := &capturedBox{}
var cur time.Time
c := NewPBSDRBoxChecker(f, 80, 90, 0, ev.fn, quietLog())
c.now = func() time.Time { return cur }
cur = time.Now().UTC()
step := func(checked bool, ns ...string) {
cur = cur.Add(16 * time.Minute)
u := usageBytes(1000, 100)
u.UnprunedChecked, u.Unpruned = checked, ns
f.set(u, nil)
c.Check()
}
const typ = "pbsdr_namespace_without_prune_job"
step(false) // an endpoint before v1.3.0: nothing to say
if count(ev.typ, typ) != 0 {
t.Fatalf("an unread list must not alarm, got %v", ev.typ)
}
step(true, "tester-1", "Tester-2")
if count(ev.typ, typ) != 1 {
t.Fatalf("two unpruned namespaces → want 1 %s, got %d", typ, count(ev.typ, typ))
}
i := len(ev.typ) - 1
if ev.sev[i] != "warning" || ev.cust[i] != "pbsdr-box" || !strings.Contains(ev.msg[i], "Tester-2,tester-1") {
t.Errorf("the alarm must be an operator-scope warning naming both: sev=%s scope=%s msg=%q", ev.sev[i], ev.cust[i], ev.msg[i])
}
step(true, "Tester-2", "tester-1") // the same set, another order
step(false) // an unreadable list in between: no change, no re-arm
step(true, "tester-1", "Tester-2")
if count(ev.typ, typ) != 1 {
t.Fatalf("the same set must not re-alarm, got %d", count(ev.typ, typ))
}
step(true, "tester-1", "Tester-2", "house-3") // a new household without a job
if count(ev.typ, typ) != 2 {
t.Fatalf("a changed set must alarm again, got %d", count(ev.typ, typ))
}
step(true) // every namespace covered: silent re-arm
if count(ev.typ, typ) != 2 {
t.Fatalf("all covered must be silent, got %d", count(ev.typ, typ))
}
step(true, "house-3")
if count(ev.typ, typ) != 3 {
t.Fatalf("after a re-arm a gap must alarm again, got %d", count(ev.typ, typ))
}
}