operator-pages: branch review fixes: delivery panics recovered, retirement failures reported, incomplete box reads shown, summary-only box status
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
11 files changed,
+309
−44
.amadan/test-weights.tsv+2 −0internal/console/jobs_test.go+110 −1internal/console/lifetimes_retire.go+20 −12internal/console/mailpush.go+10 −0internal/console/opboxes.go+24 −6internal/console/opdashboard.go+29 −15internal/console/opdashboard_test.go+98 −4internal/console/server.go+2 −1internal/console/templates/ops_boxes.html+1 −0internal/console/templates/ops_dashboard.html+5 −4internal/console/view.go+8 −1
diff --git a/.amadan/test-weights.tsv b/.amadan/test-weights.tsv| index e9f8fe49e..6db1edb71 100644 |
| --- a/.amadan/test-weights.tsv |
| +++ b/.amadan/test-weights.tsv |
| @@ -35,11 +35,13 @@ github.com/carlosframework/platform TestResolveModeOffersLoginAndContinues 2.01 |
| github.com/carlosframework/platform TestResolveModeUnconfiguredPromptsForURL 2.01 |
| github.com/carlosframework/platform TestWaitForDomainVerifiedSucceeds 2.00 |
| github.com/carlosframework/platform TestDBForwardPullInterruptedLeavesNothing 1.99 |
| +github.com/carlosframework/platform/internal/console TestIncompleteBoxReportsAreNeverAllClear 1.92 |
| github.com/carlosframework/platform TestDBForwardMixedVersions 1.91 |
| github.com/carlosframework/platform TestDBForwardPullSavesNothingForABadAnswer 1.81 |
| github.com/carlosframework/platform TestPlan13NoDirectPlacementEngineComparison 1.70 |
| github.com/carlosframework/platform TestE2EDBThroughConsole 1.49 |
| github.com/carlosframework/platform TestWatchRolloutListFailuresTimeOutNamingTheList 1.20 |
| +github.com/carlosframework/platform/internal/console TestFailedRetirementStepFailsTheRecoveryRun 1.19 |
| github.com/carlosframework/platform/internal/console TestDashboardRemoteReadsAreTheDeclaredOnes 1.11 |
| github.com/carlosframework/platform TestAuthLoginDenied 1.00 |
| github.com/carlosframework/platform/internal/console TestDashboardReadFailuresDegrade 0.94 |
diff --git a/internal/console/jobs_test.go b/internal/console/jobs_test.go| index 64c39e291..3f34ca0bb 100644 |
| --- a/internal/console/jobs_test.go |
| +++ b/internal/console/jobs_test.go |
| @@ -6,6 +6,7 @@ import ( |
| "go/ast" |
| "go/parser" |
| "go/token" |
| + "net/http" |
| "os" |
| "path/filepath" |
| "slices" |
| @@ -13,10 +14,12 @@ import ( |
| "strconv" |
| "strings" |
| "sync" |
| + "sync/atomic" |
| "testing" |
| "time" |
| "unicode/utf8" |
| + "github.com/carlosframework/platform/internal/provision" |
| "github.com/carlosframework/platform/internal/release" |
| ) |
| @@ -54,7 +57,8 @@ var jobPassFuncs = map[string][]string{ |
| "MaterializeApps"}, |
| "StartLifetimeRecoveryPass": {"recoverLifetimes", "recoverOrphanLocked", "recoverAllocationLocked", "recoverRetirementLocked", |
| "recoverMigrationLocked", "settleAllocation", "allocSlotLocked", "allocCleanLocked", "allocRecordLocked", "allocPrevOwnerCleanLocked", |
| - "orphanStepsLocked", "settleRetirement", "deleteUnderRetiredSlot", "terminateFenced", "retireRecordWithLifetimeLocked"}, |
| + "orphanStepsLocked", "settleRetirement", "deleteUnderRetiredSlot", "terminateFenced", "retireRecordWithLifetimeLocked", |
| + "retirementStepsLocked", "retireSlotStep"}, |
| "StartIncarnationMigrationPass": {"migratePreLifetimeRecords", "migrationStepsLocked", "migrationFinishLocked", "settleMigration"}, |
| "StartRelay": {"relayReconcile", "relayListRecords", "relayPublishAggregate"}, |
| "StartMailEventPush": {"mailPushPass", "deliverAppMailEvents", "deliverAppMailEventsHeld"}, |
| @@ -189,6 +193,111 @@ func TestPanickingPassIsRecordedAndTheJobRunsAgain(t *testing.T) { |
| } |
| } |
| +// TestAPanickingMailDeliveryFailsTheRunNotTheConsole: the mail push sends |
| +// each app's rows on a goroutine of its own, beyond the recover in |
| +// jobs.Run. A panic there (injected through the push's target seam) is |
| +// recovered in the delivery child: the console survives, the run is Failed |
| +// with the panic, the row stays due, and the next pass delivers it and is |
| +// OK. |
| +func TestAPanickingMailDeliveryFailsTheRunNotTheConsole(t *testing.T) { |
| + var mu sync.Mutex |
| + hits := 0 |
| + fx, _ := pushFixture(t, func(w http.ResponseWriter, r *http.Request) { |
| + mu.Lock() |
| + hits++ |
| + mu.Unlock() |
| + w.WriteHeader(http.StatusNoContent) |
| + }) |
| + ctx := context.Background() |
| + fx.srv.recordAndEnforceMail(ctx, sentBy("jb-book", bounceTo("ann@example.com", "m-ann", time.Now())), "sns-1") |
| + target := fx.srv.mailPushTarget |
| + fx.srv.mailPushTarget = func(string, string, string) string { panic("boom in a delivery") } |
| + pass := func(ctx context.Context) error { return fx.srv.mailPushPass(ctx, time.Now) } |
| + |
| + if err := fx.srv.jobs.Run(ctx, "StartMailEventPush", pass); err != nil { |
| + t.Fatalf("Run returned %v; the panic is a delivery child's, recorded on the run, not the pass's error", err) |
| + } |
| + st, _ := jobStatusOf(fx.srv, "StartMailEventPush") |
| + if st.State != JobFailed || !strings.Contains(st.Err, "jb-book: panic: boom in a delivery") || st.LastRan.IsZero() { |
| + t.Fatalf("after a panicking delivery: %+v, want Failed with the panic", st) |
| + } |
| + if ps, _ := fx.st.MailEventPushStatusFor(ctx, release.OpsAccount, "jb-book", time.Time{}); ps.Pending != 1 || ps.Delivered != 0 { |
| + t.Fatalf("after the panic the push status = %+v, want the row still pending", ps) |
| + } |
| + |
| + fx.srv.mailPushTarget = target |
| + if err := fx.srv.jobs.Run(ctx, "StartMailEventPush", pass); err != nil { |
| + t.Fatal(err) |
| + } |
| + if st, _ := jobStatusOf(fx.srv, "StartMailEventPush"); st.State != JobOK { |
| + t.Fatalf("the pass after the panic = %+v, want OK", st) |
| + } |
| + mu.Lock() |
| + defer mu.Unlock() |
| + if ps, _ := fx.st.MailEventPushStatusFor(ctx, release.OpsAccount, "jb-book", time.Time{}); hits != 1 || ps.Delivered != 1 { |
| + t.Fatalf("the next pass sent %d and the status is %+v, want the row delivered once", hits, ps) |
| + } |
| +} |
| + |
| +// TestFailedRetirementStepFailsTheRecoveryRun: a pending retirement whose |
| +// recovery cannot write its tombstone, or cannot read its record to |
| +// classify it, stays pending as before, and the Lifetime recovery run it |
| +// happened in is Failed, not OK. Once the bucket answers, the next run |
| +// settles it and is OK. Through the real recovery iteration (jobs.Run) over |
| +// the real S3 client, with the failures injected at the fake. |
| +func TestFailedRetirementStepFailsTheRecoveryRun(t *testing.T) { |
| + clock := useLifetimesClock(t) |
| + fx, lat := newPerfFixture(t) |
| + // The walk's seeds put plans on; their caps are not this test's subject. |
| + fx.srv.cfg.PlanCatalog = nil |
| + now := time.Now() |
| + if _, err := fx.st.CreateAppIn(OpsAccountID, ltApp, "paul@keymail.dev", now); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := fx.st.AddMember(OpsAccountID, "alice@keymail.dev", RoleMember, now); err != nil { |
| + t.Fatal(err) |
| + } |
| + enableInstances(t, fx, ltApp, provision.Manifest{Schema: 1, App: ltApp, Domain: "shop.example.com", Channel: "stable"}) |
| + member := cliToken(t, fx, "alice@keymail.dev", "code-retire-job-member") |
| + turnLifetimesOn(t, fx.srv, clock) |
| + l := ltOn{lifetimesFx: lifetimesFx{fx: fx, clock: clock, member: member}} |
| + l.mustCreate(t, ltOne) |
| + |
| + var failing atomic.Value |
| + failing.Store("") |
| + recordS3(lat, func(q s3Req) bool { return q.Key == recKey(ltApp, ltOne) && q.Method == failing.Load().(string) }) |
| + failing.Store(http.MethodPut) |
| + if err := retireOn(t, fx.srv, ltOne, retireAny); !errors.Is(err, errLifetimePending) { |
| + t.Fatalf("retire with the tombstone write refused = %v, want pending", err) |
| + } |
| + op := lastRetirement(t, fx.st, ltOne).OpID |
| + |
| + for _, c := range []struct{ method, want string }{ |
| + {http.MethodPut, "write the tombstone"}, |
| + {http.MethodGet, "observe bab/" + ltApp + "/" + ltOne}, |
| + } { |
| + failing.Store(c.method) |
| + recoverOn(t, fx.srv) |
| + if r := lastRetirement(t, fx.st, ltOne); r.OpID != op || r.State != lifetimePending { |
| + t.Fatalf("%s refused: retirement = %+v, want %s still pending", c.method, r, op) |
| + } |
| + st, _ := jobStatusOf(fx.srv, "StartLifetimeRecoveryPass") |
| + if st.State != JobFailed || !strings.Contains(st.Err, "retirement "+op) || !strings.Contains(st.Err, c.want) { |
| + t.Fatalf("%s refused: the recovery run = %+v, want Failed naming %q", c.method, st, c.want) |
| + } |
| + } |
| + |
| + failing.Store("") |
| + recoverOn(t, fx.srv) |
| + if st, _ := jobStatusOf(fx.srv, "StartLifetimeRecoveryPass"); st.State != JobOK { |
| + t.Fatalf("the run with the bucket answering = %+v, want OK", st) |
| + } |
| + if r := lastRetirement(t, fx.st, ltOne); r.State != lifetimeCommitted { |
| + t.Fatalf("retirement = %+v, want committed", r) |
| + } |
| + requireRetired(t, fx.rel, ltApp, ltOne, 1) |
| +} |
| + |
| // TestSwallowedFailureInASharedHelperFailsTheRun: a failure logged and |
| // stepped over deep in a helper that request handlers share |
| // (MaterializeApps, reached by the lifetimes watch) fails the run it happens |
diff --git a/internal/console/lifetimes_retire.go b/internal/console/lifetimes_retire.go| index 153b0e753..e6f5637a2 100644 |
| --- a/internal/console/lifetimes_retire.go |
| +++ b/internal/console/lifetimes_retire.go |
| @@ -236,12 +236,24 @@ func (s *Server) retirementStepsLocked(ctx context.Context, r Retirement) error |
| logf := func(format string, args ...any) { |
| log.Printf("console: lifetimes: retirement %s (%s) of %s: "+format, append([]any{r.OpID, r.Kind, r.Host}, args...)...) |
| } |
| + // pending is a failed read or write: logged as before, and the failure |
| + // of the run it is in (jobs.go), so a recovery pass that leaves the |
| + // retirement pending is not OK. The next pass retries it. |
| + pending := func(step string, err error) error { |
| + if step == "" { |
| + logf("%v (pending)", err) |
| + jobFailed(ctx, fmt.Errorf("lifetimes: retirement %s of %s: %w", r.OpID, r.Host, err)) |
| + } else { |
| + logf("%s: %v (pending)", step, err) |
| + jobFailed(ctx, fmt.Errorf("lifetimes: retirement %s of %s: %s: %w", r.OpID, r.Host, step, err)) |
| + } |
| + return errLifetimePending |
| + } |
| ctx = provision.WithLifetimes(ctx, s.judge) |
| for round := 0; round < retireRounds; round++ { |
| obs, err := s.classifyLocked(ctx, r.Account, r.App, r.Host) |
| if err != nil { |
| - logf("%v (pending)", err) |
| - return errLifetimePending |
| + return pending("", err) |
| } |
| slot := obs.Slot |
| owned := slotOwnedBy(slot, r.Account, r.App) |
| @@ -254,8 +266,7 @@ func (s *Server) retirementStepsLocked(ctx context.Context, r Retirement) error |
| case retired: |
| if obs.Present { |
| if err := s.deleteUnderRetiredSlot(ctx, r, true); err != nil { |
| - logf("remove the body under the retired slot: %v (pending)", err) |
| - return errLifetimePending |
| + return pending("remove the body under the retired slot", err) |
| } |
| } |
| return s.settleRetirement(ctx, r, lifetimeCommitted, nil) |
| @@ -282,12 +293,10 @@ func (s *Server) retirementStepsLocked(ctx context.Context, r Retirement) error |
| } |
| case obs.Verdict == provision.LifetimeCorrupt: |
| if err := s.quarantineCopy(ctx, r.Account, r.App, r.Host, obs.Raw, obs.ETag); err != nil { |
| - logf("quarantine the corrupt body: %v (pending)", err) |
| - return errLifetimePending |
| + return pending("quarantine the corrupt body", err) |
| } |
| if err := s.store.ConvertRetirementKind(r.OpID, retireCleanup, obs.ETag); err != nil { |
| - logf("convert to a cleanup: %v (pending)", err) |
| - return errLifetimePending |
| + return pending("convert to a cleanup", err) |
| } |
| r.Kind, r.RecordETag = retireCleanup, obs.ETag |
| case rec.Retired && rec.Incarnation == r.Incarnation: |
| @@ -309,13 +318,11 @@ func (s *Server) retirementStepsLocked(ctx context.Context, r Retirement) error |
| // N1: the exact bytes captured become their tombstone. |
| tomb, err := provision.TombstoneBody(obs.Raw) |
| if err != nil { |
| - logf("the tombstone of %s: %v (pending)", key, err) |
| - return errLifetimePending |
| + return pending("the tombstone of "+key, err) |
| } |
| _, _, err = provision.WriteRecord(provision.WithRecordSequence(ctx), s.cfg.Releases, key, obs.Raw, tomb, obs.ETag) |
| if err != nil && !errors.Is(err, release.ErrCASConflict) { |
| - logf("write the tombstone: %v (pending)", err) |
| - return errLifetimePending |
| + return pending("write the tombstone", err) |
| } |
| // Landed or lost: on from what is there now. |
| default: |
| @@ -344,6 +351,7 @@ func (s *Server) retireSlotStep(ctx context.Context, r Retirement, logf func(str |
| return true, s.settleRetirement(ctx, r, lifetimeVoid, nil) |
| case slotUnreadable: |
| logf("retire the slot: %v (pending)", err) |
| + jobFailed(ctx, fmt.Errorf("lifetimes: retirement %s of %s: retire the slot: %w", r.OpID, r.Host, err)) |
| return true, errLifetimePending |
| } |
| return false, nil |
diff --git a/internal/console/mailpush.go b/internal/console/mailpush.go| index 04bd7a3cc..4c809cd49 100644 |
| --- a/internal/console/mailpush.go |
| +++ b/internal/console/mailpush.go |
| @@ -63,6 +63,7 @@ import ( |
| "io" |
| "log" |
| "net/http" |
| + "runtime/debug" |
| "strconv" |
| "strings" |
| "sync" |
| @@ -749,6 +750,15 @@ func (s *Server) mailPushPass(ctx context.Context, clock func() time.Time) error |
| sem <- struct{}{} |
| go func() { |
| defer func() { <-sem; wg.Done() }() |
| + // jobs.Run recovers the pass's own goroutine only: a panic here |
| + // would end the console. It fails the run instead; the app's |
| + // rows stay due for the next pass. |
| + defer func() { |
| + if p := recover(); p != nil { |
| + log.Printf("console: mail push: %s/%s: panic: %v\n%s", h.Account, h.App, p, debug.Stack()) |
| + jobFailed(ctx, fmt.Errorf("mail push: %s/%s: panic: %v", h.Account, h.App, p)) |
| + } |
| + }() |
| s.deliverAppMailEvents(ctx, h, rows, key, clock) |
| }() |
| } |
diff --git a/internal/console/opboxes.go b/internal/console/opboxes.go| index d7f643a02..93817c3bf 100644 |
| --- a/internal/console/opboxes.go |
| +++ b/internal/console/opboxes.go |
| @@ -31,9 +31,22 @@ func (s *Server) opFleetJSON(ctx context.Context, p *page) (*status.Fleet, error |
| return FleetView(ctx, s.cfg.Releases) |
| } |
| -// opHostRows is every box report, listed and read once (HostRows). |
| -func (s *Server) opHostRows(ctx context.Context, p *page) ([]HostRow, error) { |
| - return HostRows(ctx, s.cfg.Releases, s.now()) |
| +// opHostRows is every box report, listed and read once, as HostRows' |
| +// rows. complete is false when a listed report could not be read, was |
| +// corrupt or oversized, or the listing was capped |
| +// (status.LoadBoxesComplete, which costs no more requests than |
| +// status.LoadBoxes): the rows are then the reports that were read, and the |
| +// pages say some are missing rather than treat the rest as the whole fleet. |
| +// A deployment with no bucket has no reports and is complete. |
| +func (s *Server) opHostRows(ctx context.Context, p *page) (rows []HostRow, complete bool, err error) { |
| + if s.cfg.Releases == nil { |
| + return nil, true, nil |
| + } |
| + boxes, complete, err := status.LoadBoxesComplete(ctx, s.cfg.Releases) |
| + if err != nil { |
| + return nil, false, err |
| + } |
| + return hostRowsFrom(boxes, s.now()), complete, nil |
| } |
| // opStorePending is the number of pending storage applications, read once |
| @@ -72,12 +85,17 @@ func (s *Server) handleBoxes(w http.ResponseWriter, r *http.Request) { |
| // answer: a bucket that won't list the boxes costs the operator the |
| // per-host block, not the whole page, so this degrades with a log line |
| // rather than turning a readable page into a 500. It says so (OPS-154) |
| - // where the Hosts table would be. |
| - hosts, err := s.opHostRows(ctx, &p) |
| - if err != nil { |
| + // where the Hosts table would be. A report that could not be read says |
| + // so too, above the rows that were. |
| + hosts, complete, err := s.opHostRows(ctx, &p) |
| + switch { |
| + case err != nil: |
| log.Printf("console: fleet hosts: %v", err) |
| hosts = nil |
| p.HostsUnread = opHostsUnread |
| + case !complete: |
| + log.Printf("console: fleet hosts: some box reports could not be read") |
| + p.HostsUnread = opHostsUnread |
| } |
| // Region labels (spec §5 rows 10, 11): box regions from the cached name |
| // map, each app's stored region from SQLite and one registry listing. |
diff --git a/internal/console/opdashboard.go b/internal/console/opdashboard.go| index 50c875460..11d998c14 100644 |
| --- a/internal/console/opdashboard.go |
| +++ b/internal/console/opdashboard.go |
| @@ -56,6 +56,9 @@ type attentionInput struct { |
| AlertsKnown bool |
| StorePending *int |
| Jobs []JobStatus |
| + // HostsIncomplete is a listing read with some reports missing from |
| + // it (opHostRows): the same item as HostsErr. |
| + HostsIncomplete bool |
| } |
| // attnCode is an item whose format holds one %s, the code: the text before |
| @@ -69,8 +72,8 @@ func attnCode(format, code, href, link string, rest ...any) attentionItem { |
| } |
| // attentionItems is the callout's list and tone: one item per Silent row of |
| -// Boxes, box reports that could not be read, an old summary, a summary |
| -// that could not be read, each down |
| +// Boxes, box reports that could not be listed or read, an old summary, a |
| +// summary that could not be read, each down |
| // service, each firing alert (once the projection is known), the storage |
| // queue when it is waiting, and each job whose last run failed. The tone is |
| // negative when a service is down, warning for anything else, positive for |
| @@ -82,7 +85,7 @@ func attentionItems(in attentionInput) (items []attentionItem, tone string) { |
| items = append(items, attnCode("Box %s has stopped reporting.", b.Label, "/fleet/boxes#box-"+b.Label, boxes)) |
| } |
| } |
| - if in.HostsErr != nil { |
| + if in.HostsErr != nil || in.HostsIncomplete { |
| items = append(items, attentionItem{Lead: opHostsUnread, Href: "/fleet/boxes", Link: boxes}) |
| } |
| down := false |
| @@ -233,10 +236,11 @@ func dashSummaryStale(f *status.Fleet, now time.Time) bool { |
| // dashBoxes is the Boxes table: one row per HostRow, in label order, joined |
| // by label with fleet.json's box for its load word, plus a row for any box |
| -// fleet.json lists that no report was read for (Silent, no meter, no last |
| -// report). Every row is Stale when fleet.json itself is old (stale is then |
| -// true); otherwise a stale HostRow is Silent, a busy or critical load is |
| -// Busy, and the rest are Healthy. Staleness is judged against now. |
| +// fleet.json lists that no report was read for (no meter, no last report). |
| +// Every row is Stale when fleet.json itself is old (stale is then true); |
| +// otherwise a stale HostRow, or for a fleet.json-only box FleetBox.Stale, |
| +// is Silent, a busy or critical load is Busy, and the rest are Healthy. |
| +// Staleness is judged against now. |
| func dashBoxes(f *status.Fleet, hosts []HostRow, now time.Time) (rows []dashBox, stale bool) { |
| stale = dashSummaryStale(f, now) |
| byLabel := map[string]*status.FleetBox{} |
| @@ -268,9 +272,14 @@ func dashBoxes(f *status.Fleet, hosts []HostRow, now time.Time) (rows []dashBox, |
| } |
| if f != nil { |
| for _, fb := range f.Boxes { |
| - if !seen[fb.Label] { |
| - rows = append(rows, dashBox{Label: fb.Label, Region: fb.Region, Status: opPill{Label: dashWordSilent, Tone: "negative"}}) |
| + if seen[fb.Label] { |
| + continue |
| } |
| + row := dashBox{Label: fb.Label, Region: fb.Region, Status: dashLoadPill(fb.Load)} |
| + if fb.Stale { |
| + row.Status = opPill{Label: dashWordSilent, Tone: "negative"} |
| + } |
| + rows = append(rows, row) |
| } |
| } |
| return dashFinish(rows, stale), stale |
| @@ -301,8 +310,9 @@ type dashView struct { |
| Activity []FeedRow |
| Boxes []dashBox |
| HasFleet bool |
| - // HostsUnread is OPS-154 when the box reports could not be read, |
| - // shown in place of the Boxes rows; "" otherwise. |
| + // HostsUnread is OPS-154 when the box reports could not be listed, |
| + // shown in place of the Boxes rows, or when some could not be read, |
| + // shown above the rows that were; "" otherwise. |
| HostsUnread string |
| Jobs []opJobRow |
| } |
| @@ -334,8 +344,8 @@ func (d *dashView) Icon() string { |
| // handleDashboard serves the dashboard at /fleet, for signed-in operators |
| // only, behind operatorOnly's 404-to-everyone gate. A failed SQLite read |
| // leaves its section empty and a failed bucket read is a callout item (and, |
| -// for the box reports, OPS-154 in place of the Boxes rows); neither is a |
| -// 500. |
| +// for the box reports, OPS-154 in place of the Boxes rows, or above the |
| +// rows read when some reports could not be); neither is a 500. |
| func (s *Server) handleDashboard(w http.ResponseWriter, r *http.Request) { |
| addr, raw, ok := s.operatorOnly(w, r) |
| if !ok { |
| @@ -373,12 +383,16 @@ func (s *Server) handleDashboard(w http.ResponseWriter, r *http.Request) { |
| f = nil |
| } |
| d.HasFleet = f != nil |
| - hosts, hostsErr := s.opHostRows(ctx, &p) |
| + hosts, complete, hostsErr := s.opHostRows(ctx, &p) |
| if hostsErr != nil { |
| log.Printf("console: dashboard fleet hosts: %v", hostsErr) |
| d.HostsUnread = opHostsUnread |
| } else { |
| d.Boxes, _ = dashBoxes(f, hosts, now) |
| + if !complete { |
| + log.Printf("console: dashboard fleet hosts: some box reports could not be read") |
| + d.HostsUnread = opHostsUnread |
| + } |
| } |
| for i := range d.Boxes { |
| if _, name := s.boxRegion(d.Boxes[i].Label); name != "" { |
| @@ -392,7 +406,7 @@ func (s *Server) handleDashboard(w http.ResponseWriter, r *http.Request) { |
| alerts, known := s.alertsNow.Firing() |
| jobs := s.jobs.Snapshot() |
| d.Attention, d.Tone = attentionItems(attentionInput{ |
| - Fleet: f, FleetErr: fleetErr, Boxes: d.Boxes, HostsErr: hostsErr, Now: now, |
| + Fleet: f, FleetErr: fleetErr, Boxes: d.Boxes, HostsErr: hostsErr, HostsIncomplete: hostsErr == nil && !complete, Now: now, |
| Alerts: alerts, AlertsKnown: known, StorePending: pending, Jobs: jobs, |
| }) |
| d.Jobs = opJobRows(jobs) |
diff --git a/internal/console/opdashboard_test.go b/internal/console/opdashboard_test.go| index f32d41fe5..4d1152053 100644 |
| --- a/internal/console/opdashboard_test.go |
| +++ b/internal/console/opdashboard_test.go |
| @@ -506,7 +506,9 @@ func TestAttentionAndBoxesAgreeAcrossTheFifteenMinuteLine(t *testing.T) { |
| } |
| } |
| -// TestDashboardBoxStatuses: not acceptance, over dashBoxes. |
| +// TestDashboardBoxStatuses: not acceptance, over dashBoxes. A box only |
| +// fleet.json lists (box-5 to box-7) takes its status from FleetBox.Stale, |
| +// then its load word, with no meter and no last report. |
| func TestDashboardBoxStatuses(t *testing.T) { |
| now := time.Date(2026, 10, 26, 12, 0, 0, 0, time.UTC) |
| word := func(s string) *string { return &s } |
| @@ -517,6 +519,8 @@ func TestDashboardBoxStatuses(t *testing.T) { |
| {Label: "box-3", Region: "eu-west-1", Load: word("critical")}, |
| {Label: "box-4", Region: "", Load: word("comfortable")}, |
| {Label: "box-5", Region: "eu-west-1", Load: word("comfortable")}, |
| + {Label: "box-6", Region: "eu-west-1", Load: word("busy")}, |
| + {Label: "box-7", Region: "eu-west-1", Load: word("busy"), Stale: true}, |
| }} |
| hosts := []HostRow{ |
| {Label: "box-1", Region: "eu-west-1", LastSeen: now, Metrics: mem}, |
| @@ -536,7 +540,9 @@ func TestDashboardBoxStatuses(t *testing.T) { |
| {"box-2", "Busy", "warning", "eu-west-1", true}, |
| {"box-3", "Busy", "negative", "eu-west-1", false}, |
| {"box-4", "Silent", "negative", "unknown", false}, |
| - {"box-5", "Silent", "negative", "eu-west-1", false}, |
| + {"box-5", "Healthy", "positive", "eu-west-1", false}, |
| + {"box-6", "Busy", "warning", "eu-west-1", false}, |
| + {"box-7", "Silent", "negative", "eu-west-1", false}, |
| } |
| if len(rows) != len(want) { |
| t.Fatalf("rows = %+v", rows) |
| @@ -550,8 +556,22 @@ func TestDashboardBoxStatuses(t *testing.T) { |
| if rows[0].Meter.Percent != 75 || rows[0].Meter.Text != "75%" { |
| t.Errorf("box-1's meter = %+v, want 75 and 75%%", rows[0].Meter) |
| } |
| - if !rows[4].LastSeen.IsZero() { |
| - t.Errorf("a box only fleet.json lists has a last report: %v", rows[4].LastSeen) |
| + for _, r := range rows[4:] { |
| + if !r.LastSeen.IsZero() { |
| + t.Errorf("%s, which only fleet.json lists, has a last report: %v", r.Label, r.LastSeen) |
| + } |
| + } |
| + // The callout follows the rows: only the silent ones have stopped |
| + // reporting, box-6 being busy is not an item. |
| + items, _ := attentionItems(attentionInput{Fleet: f, Boxes: rows, Now: now}) |
| + var stopped []string |
| + for _, it := range items { |
| + if it.Lead == "Box " && it.Tail == " has stopped reporting." { |
| + stopped = append(stopped, it.Code) |
| + } |
| + } |
| + if !slices.Equal(stopped, []string{"box-4", "box-7"}) { |
| + t.Errorf("stopped-reporting items for %v, want box-4 and box-7: %+v", stopped, items) |
| } |
| old := *f |
| @@ -701,6 +721,80 @@ func TestDashboardReadFailuresDegrade(t *testing.T) { |
| } |
| } |
| +// TestIncompleteBoxReportsAreNeverAllClear: a listed box report that cannot |
| +// be read (a refused GET) or parsed (corrupt JSON), for a box fleet.json |
| +// does not list yet, must not vanish into an all-clear. The dashboard and |
| +// Boxes keep the rows they read and say OPS-154 above them, and the |
| +// callout carries its item. Failures injected at the S3 fake. (The |
| +// fixture's one other item is its waiting storage request, so the |
| +// all-clear rule itself is pinned over attentionItems first.) |
| +func TestIncompleteBoxReportsAreNeverAllClear(t *testing.T) { |
| + const newKey, badKey = "status/boxes/box-new.json", "status/boxes/box-bad.json" |
| + want := `Could not read the box reports. <a href="/fleet/boxes">Boxes</a>` |
| + if items, tone := attentionItems(attentionInput{HostsIncomplete: true, Now: time.Now()}); len(items) != 1 || items[0].Lead != opHostsUnread || tone != "warning" { |
| + t.Fatalf("an incomplete read alone gives %+v (%s), want the OPS-154 item and warning", items, tone) |
| + } |
| + for _, tc := range []struct { |
| + name string |
| + setup func(t *testing.T, fx *consoleFixture) |
| + fail func(q s3Req) bool |
| + }{ |
| + {"refused GET", func(t *testing.T, fx *consoleFixture) { |
| + if err := status.WriteBox(context.Background(), fx.rel, status.Box{GeneratedAt: time.Now(), Label: "box-new", Region: "eu-west-1"}); err != nil { |
| + t.Fatal(err) |
| + } |
| + }, func(q s3Req) bool { return q.Method == http.MethodGet && q.Key == newKey }}, |
| + {"corrupt JSON", func(t *testing.T, fx *consoleFixture) { |
| + if _, err := fx.rel.Put(context.Background(), badKey, []byte("{not json"), ""); err != nil { |
| + t.Fatal(err) |
| + } |
| + }, nil}, |
| + } { |
| + t.Run(tc.name, func(t *testing.T) { |
| + fx, lat := newPerfFixture(t) |
| + c := signInOperator(t, fx) |
| + if body := dashGet(t, fx, c); slices.Contains(dashItems(t, body), want) { |
| + t.Fatalf("the fixture's dashboard has the OPS-154 item to begin with:\n%s", dashCallout(t, body)) |
| + } |
| + tc.setup(t, fx) |
| + rec := recordS3(lat, tc.fail) |
| + |
| + body := dashGet(t, fx, c) |
| + if rec.touching(newKey)+rec.touching(badKey) == 0 { |
| + t.Fatalf("the view never read the new report: %+v", rec.all()) |
| + } |
| + callout := dashCallout(t, body) |
| + if strings.Contains(callout, "Everything is running.") { |
| + t.Errorf("the callout is all-clear with a box report unread:\n%s", callout) |
| + } |
| + if !slices.Contains(dashItems(t, body), want) { |
| + t.Errorf("no callout item %q:\n%s", want, callout) |
| + } |
| + boxes := dashSection(t, body, "Boxes") |
| + if !strings.Contains(boxes, `<p rst-empty-body>Could not read the box reports.</p>`) { |
| + t.Errorf("the Boxes section does not say a report is missing:\n%s", boxes) |
| + } |
| + if !strings.Contains(boxes, ">box-a</a>") || !strings.Contains(boxes, ">box-b</a>") { |
| + t.Errorf("the Boxes section dropped the rows it read:\n%s", boxes) |
| + } |
| + if strings.Contains(boxes, "No box has published a reading yet.") { |
| + t.Errorf("the Boxes section says no box has reported:\n%s", boxes) |
| + } |
| + |
| + code, _, page := get(t, c, fx.ts.URL+"/fleet/boxes") |
| + if code != http.StatusOK { |
| + t.Fatalf("/fleet/boxes = %d", code) |
| + } |
| + if !strings.Contains(page, "<h2>Hosts</h2></div>\n<div rst-empty>\n <p rst-empty-body>Could not read the box reports.</p>") { |
| + t.Errorf("Hosts does not say a report is missing:\n%s", page) |
| + } |
| + if !strings.Contains(page, "<th>Host</th>") || !strings.Contains(page, "<td>box-a</td>") { |
| + t.Errorf("Hosts dropped the rows it read:\n%s", page) |
| + } |
| + }) |
| + } |
| +} |
| + |
| // TestDashboardBoxesKeepTheMockupColumns: Box, Status, Region, Load as a |
| // meter, Last report, per box. |
| func TestDashboardBoxesKeepTheMockupColumns(t *testing.T) { |
diff --git a/internal/console/server.go b/internal/console/server.go| index 16235aa01..24d434f9b 100644 |
| --- a/internal/console/server.go |
| +++ b/internal/console/server.go |
| @@ -2274,7 +2274,8 @@ type page struct { |
| // to show", never a reason to fail the page. |
| Hosts []HostRow |
| // HostsUnread is OPS-154 on Boxes when the box reports could not be |
| - // read, shown where the Hosts table would be; "" otherwise. |
| + // listed, shown where the Hosts table would be, or when some could not |
| + // be read, shown above the rows that were; "" otherwise. |
| HostsUnread string |
| // BoxRegions maps a box label to its region label for the fleet pages; |
| // a box absent from it keeps its own STATUS_BOX_REGION word. |
diff --git a/internal/console/templates/ops_boxes.html b/internal/console/templates/ops_boxes.html| index 6e6cedac5..9fe5484fc 100644 |
| --- a/internal/console/templates/ops_boxes.html |
| +++ b/internal/console/templates/ops_boxes.html |
| @@ -84,6 +84,7 @@ |
| {{if .Hosts}} |
| <div rst-box-head><h2>Hosts</h2></div> |
| +{{if .HostsUnread}}{{template "op_empty" (opEmpty "" .HostsUnread)}}{{end}} |
| <div rst-card class="co-table-wrap"> |
| <table co-table> |
| <tr> |
diff --git a/internal/console/templates/ops_dashboard.html b/internal/console/templates/ops_dashboard.html| index 9f5a212ef..47fc0441e 100644 |
| --- a/internal/console/templates/ops_dashboard.html |
| +++ b/internal/console/templates/ops_dashboard.html |
| @@ -68,14 +68,15 @@ |
| {{/* The dashboard's Boxes section (data *dashView): one row per box, its |
| status, region, memory in use as a meter, and when it last reported; |
| - OPS-154 instead when the box reports could not be read. */}} |
| + OPS-154 instead when the box reports could not be listed, and above |
| + the rows read when some could not be read. */}} |
| {{define "ops_dashboard_boxes"}}<div rst-box-head><h2>Boxes</h2><a rst-btn="ghost" href="/fleet/boxes">All boxes</a></div> |
| -{{if .HostsUnread}}{{template "op_empty" (opEmpty "" .HostsUnread)}} |
| -{{else if .Boxes}} |
| +{{if .HostsUnread}}{{template "op_empty" (opEmpty "" .HostsUnread)}}{{end}} |
| +{{if .Boxes}} |
| <div rst-card co-cols="boxes"> |
| <div rst-lrow="head"><span>Box</span><span>Status</span><span>Region</span><span>Load</span><span>Last report</span></div> |
| {{- range .Boxes}} |
| <div rst-lrow><a class="rst-nm" href="/fleet/boxes#box-{{.Label}}">{{.Label}}</a><span>{{template "op_status" .Status}}</span>{{if eq .Region .Unknown}}<span class="rst-cell-mut">{{.Region}}</span>{{else}}<span>{{.Region}}</span>{{end}}{{with .Meter}}{{template "op_meter" .}}{{else}}<span class="rst-cell-mut">{{.Unknown}}</span>{{end}}{{if .LastSeen.IsZero}}<span class="rst-cell-mut">{{.Unknown}}</span>{{else}}<span class="rst-cell-mut" title="{{fmtTime .LastSeen}}">{{ago .LastSeen}}</span>{{end}}</div> |
| {{- end}} |
| </div> |
| -{{else}}{{template "op_empty" (opEmpty "" "No box has published a reading yet.")}}{{end}}{{end}} |
| +{{else if not .HostsUnread}}{{template "op_empty" (opEmpty "" "No box has published a reading yet.")}}{{end}}{{end}} |
diff --git a/internal/console/view.go b/internal/console/view.go| index 28fd45545..fe19c5adc 100644 |
| --- a/internal/console/view.go |
| +++ b/internal/console/view.go |
| @@ -981,6 +981,13 @@ func HostRows(ctx context.Context, s release.Store, now time.Time) ([]HostRow, e |
| if err != nil { |
| return nil, err |
| } |
| + return hostRowsFrom(boxes, now), nil |
| +} |
| + |
| +// hostRowsFrom is HostRows' table from boxes already read: a stale box's |
| +// metrics dropped and its dark time set, sorted by label. The operator |
| +// pages' reader (opHostRows) builds its rows here too. |
| +func hostRowsFrom(boxes []status.Box, now time.Time) []HostRow { |
| rows := make([]HostRow, 0, len(boxes)) |
| for _, b := range boxes { |
| row := HostRow{ |
| @@ -998,7 +1005,7 @@ func HostRows(ctx context.Context, s release.Store, now time.Time) ([]HostRow, e |
| rows = append(rows, row) |
| } |
| sort.Slice(rows, func(i, j int) bool { return rows[i].Label < rows[j].Label }) |
| - return rows, nil |
| + return rows |
| } |
| // humanAge renders how long a box has been dark at the resolution an operator |