hub(D53): held apps reach the operator — mirror, Held apps list (host + Hosts page), reminder after the grace
gates / gates (push) Successful in 1m58s
gates / gates (push) Successful in 1m58s
app_held / app_hold_cleared allow-listed and operator-only; handleEvent mirrors them in held_apps; HeldAppsChecker sends ONE app_held_reminder (warning, operator-only, per-app cooldown) after the grace per reason (6 h / 1 d / 3 d), then weekly; recorded before sending; stale rows not reminded; the hub never clears a hold. Test-only alerting.held_app_grace_override. TestD53_* in api/monitor/notify/web, red-proved by six mutations. Commit only.
This commit is contained in:
1 parent
ecd82abab8
commit
7e57e824a2
27 files changed
+935
-2
No files matched your search
@@ -0,0 +1,66 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"gitea.dooplex.hu/admin/felhom-hub/internal/store"
|
||||
)
|
||||
|
||||
// D53 (`08` §10): the „Held apps" list on the host page and on the Hosts page — both branches of each {{if}} rendered
|
||||
// (the seam-wiring rule): a held app shows its app, reason and who may clear it; after the clear, the empty sentence.
|
||||
func TestD53_HeldAppsListOnTheHostPageAndTheHostsPage(t *testing.T) {
|
||||
s, st := newTestServer(t)
|
||||
if err := st.UpsertHost(&store.Host{HostID: "demo-hp-01", CustomerID: "c1", APIKey: "k1"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
now := time.Now()
|
||||
if err := st.UpsertHeldApp("c1", "kimai", "unhealthy_stop", now.Add(-3*24*time.Hour), "stopped by the box for a crash loop", now); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
render := func() (string, string) {
|
||||
rr := httptest.NewRecorder()
|
||||
s.handleHostsList(rr, httptest.NewRequest(http.MethodGet, "/hosts", nil))
|
||||
hd := httptest.NewRecorder()
|
||||
s.handleHostDetail(hd, httptest.NewRequest(http.MethodGet, "/hosts/demo-hp-01", nil), "demo-hp-01")
|
||||
if rr.Code != 200 || hd.Code != 200 {
|
||||
t.Fatalf("status: hosts %d, host %d", rr.Code, hd.Code)
|
||||
}
|
||||
return rr.Body.String(), hd.Body.String()
|
||||
}
|
||||
fleet, host := render()
|
||||
for name, body := range map[string]string{"hosts": fleet, "host": host} {
|
||||
if !strings.Contains(body, "Held apps") || !strings.Contains(body, `data-held-app=`) || !strings.Contains(body, "kimai") ||
|
||||
!strings.Contains(body, "unhealthy_stop") || !strings.Contains(body, "Start (one more try)") {
|
||||
t.Errorf("%s page: the held app is not listed with its reason and who may clear it", name)
|
||||
}
|
||||
}
|
||||
if !strings.Contains(fleet, `href="/hosts/demo-hp-01#held-apps"`) {
|
||||
t.Error("hosts page: the held app does not link to its host")
|
||||
}
|
||||
if !strings.Contains(host, "stopped by the box for a crash loop") {
|
||||
t.Error("host page: the box's sentence is missing")
|
||||
}
|
||||
if _, err := st.ClearHeldApp("c1", "kimai"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
fleet, host = render()
|
||||
if strings.Contains(fleet, `data-held-app=`) || !strings.Contains(fleet, "No app is held on any box.") {
|
||||
t.Error("hosts page: after the clear the list is not empty")
|
||||
}
|
||||
if strings.Contains(host, `data-held-app=`) || !strings.Contains(host, "No app is held on this box.") {
|
||||
t.Error("host page: after the clear the list is not empty")
|
||||
}
|
||||
}
|
||||
|
||||
// A host with no customer shows no held apps — never the whole fleet's.
|
||||
func TestD53_AHostWithNoCustomerShowsNoHeldApps(t *testing.T) {
|
||||
s, st := newTestServer(t)
|
||||
_ = st.UpsertHeldApp("c9", "x", "restore_failed", time.Now(), "y", time.Now())
|
||||
if rows := s.hostHeldAppRows("", time.Now()); len(rows) != 0 {
|
||||
t.Fatalf("a customer-less host lists %d held app(s)", len(rows))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gitea.dooplex.hu/admin/felhom-hub/internal/monitor"
|
||||
"gitea.dooplex.hu/admin/felhom-hub/internal/store"
|
||||
)
|
||||
|
||||
// heldAppRow is one line of the „Held apps" list (D53, `08` §10) on the host page and the Hosts page.
|
||||
type heldAppRow struct {
|
||||
CustomerID string
|
||||
HostID string // the customer's host, for the link on the Hosts page; "" when unknown
|
||||
Stack string
|
||||
Reason string
|
||||
Since time.Time
|
||||
Why string // the box's own sentence
|
||||
WhoClears string
|
||||
Reminded bool
|
||||
Stale bool // the box has not repeated it for heldAppStale — it may be down
|
||||
}
|
||||
|
||||
// heldAppStaleAfter mirrors monitor's heldAppStale: a box repeats app_held daily.
|
||||
const heldAppStaleAfter = 50 * time.Hour
|
||||
|
||||
// heldAppRows reads the held-app mirror, one customer's or every one's ("" = all). A read failure is logged and
|
||||
// shown as an empty list — the page must still render.
|
||||
func (s *Server) heldAppRows(customerID string, hostOf map[string]string, now time.Time) []heldAppRow {
|
||||
held, err := s.store.ListHeldApps(customerID)
|
||||
if err != nil {
|
||||
s.logger.Printf("[WARN] held apps: list for %q: %v", customerID, err)
|
||||
return nil
|
||||
}
|
||||
return toHeldAppRows(held, hostOf, now)
|
||||
}
|
||||
|
||||
// hostHeldAppRows is one host's list. A host with no customer has none — never the fleet's („" lists every one).
|
||||
func (s *Server) hostHeldAppRows(customerID string, now time.Time) []heldAppRow {
|
||||
if customerID == "" {
|
||||
return nil
|
||||
}
|
||||
return s.heldAppRows(customerID, nil, now)
|
||||
}
|
||||
|
||||
func toHeldAppRows(held []store.HeldApp, hostOf map[string]string, now time.Time) []heldAppRow {
|
||||
out := make([]heldAppRow, 0, len(held))
|
||||
for _, h := range held {
|
||||
since := h.Since
|
||||
if since.IsZero() {
|
||||
since = h.FirstSeen
|
||||
}
|
||||
out = append(out, heldAppRow{CustomerID: h.CustomerID, HostID: hostOf[h.CustomerID], Stack: h.Stack, Reason: h.Reason,
|
||||
Since: since, Why: h.Why, WhoClears: monitor.HeldAppWhoClears(h.Reason), Reminded: !h.RemindedAt.IsZero(),
|
||||
Stale: now.Sub(h.LastSeen) > heldAppStaleAfter})
|
||||
}
|
||||
return out
|
||||
}
|
||||
@@ -658,9 +658,19 @@ func (s *Server) handleHostsList(w http.ResponseWriter, r *http.Request) {
|
||||
// non-fatal: still render the host list
|
||||
}
|
||||
|
||||
// D53 (`08` §10): every held app across the fleet, each linked to its customer's host.
|
||||
hostOf := map[string]string{}
|
||||
for _, row := range rows {
|
||||
if row.CustomerID != "" {
|
||||
hostOf[row.CustomerID] = row.HostID
|
||||
}
|
||||
}
|
||||
heldApps := s.heldAppRows("", hostOf, time.Now())
|
||||
|
||||
data := map[string]interface{}{
|
||||
"Hosts": rows,
|
||||
"Unclaimed": unclaimed,
|
||||
"HeldApps": heldApps,
|
||||
"CustomerPicker": picker,
|
||||
"Flash": r.URL.Query().Get("flash"),
|
||||
"CSRFToken": s.getCSRFToken(r),
|
||||
@@ -873,6 +883,7 @@ func (s *Server) hostDetailData(host *store.Host, r *http.Request) map[string]in
|
||||
"DesiredGeneration": host.DesiredGeneration,
|
||||
"Vitals": vitals,
|
||||
"Guests": guests,
|
||||
"HeldApps": s.hostHeldAppRows(host.CustomerID, now), // D53, `08` §10
|
||||
"GuestRunning": guestRunning,
|
||||
"GuestTotal": len(guests),
|
||||
"StorageTargets": storageTargets,
|
||||
|
||||
@@ -146,6 +146,39 @@
|
||||
{{end}}
|
||||
</section>
|
||||
|
||||
<!-- Held apps (D53, `08` §10): apps the box keeps stopped until a person acts. The hub never clears one. -->
|
||||
<section class="card" id="held-apps" style="padding: 0; overflow: hidden;">
|
||||
<h2 style="padding: 1.25rem 1.25rem 0.5rem;">Held apps</h2>
|
||||
{{if .HeldApps}}
|
||||
<table class="data-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>App</th>
|
||||
<th>Reason</th>
|
||||
<th>Since</th>
|
||||
<th>Why</th>
|
||||
<th>Who may clear it</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{range .HeldApps}}
|
||||
<tr data-held-app="{{.Stack}}">
|
||||
<td><code>{{.Stack}}</code></td>
|
||||
<td><span class="severity-badge severity-warning">{{.Reason}}</span>{{if .Stale}} <span class="text-muted">(not confirmed by the box for 2 days)</span>{{end}}</td>
|
||||
<td>{{timeAgo .Since}}</td>
|
||||
<td>{{.Why}}</td>
|
||||
<td>{{.WhoClears}}{{if .Reminded}} <span class="text-muted">(operator reminded)</span>{{end}}</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
</tbody>
|
||||
</table>
|
||||
{{else}}
|
||||
<div class="empty-state" style="border: none;">
|
||||
<p>No app is held on this box.</p>
|
||||
</div>
|
||||
{{end}}
|
||||
</section>
|
||||
|
||||
<!-- Storage Targets -->
|
||||
<section class="card" style="padding: 0; overflow: hidden;">
|
||||
<h2 style="padding: 1.25rem 1.25rem 0.5rem;">Storage Targets</h2>
|
||||
|
||||
@@ -34,6 +34,39 @@
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
<!-- Held apps across the fleet (D53, `08` §10). The hub never clears a hold; each row links to its host. -->
|
||||
<section class="card" id="held-apps" style="margin-bottom: 1.5rem; padding: 0; overflow: hidden;">
|
||||
<h2 style="padding: 1.25rem 1.25rem 0.5rem; margin-top: 0;">Held apps</h2>
|
||||
{{if .HeldApps}}
|
||||
<table class="data-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Customer</th>
|
||||
<th>App</th>
|
||||
<th>Reason</th>
|
||||
<th>Since</th>
|
||||
<th>Who may clear it</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{range .HeldApps}}
|
||||
<tr data-held-app="{{.CustomerID}}/{{.Stack}}">
|
||||
<td>{{if .HostID}}<a href="/hosts/{{.HostID}}#held-apps">{{.CustomerID}}</a>{{else}}{{.CustomerID}}{{end}}</td>
|
||||
<td><code>{{.Stack}}</code></td>
|
||||
<td><span class="severity-badge severity-warning">{{.Reason}}</span>{{if .Stale}} <span class="text-muted">(not confirmed for 2 days)</span>{{end}}</td>
|
||||
<td>{{timeAgo .Since}}</td>
|
||||
<td>{{.WhoClears}}</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
</tbody>
|
||||
</table>
|
||||
{{else}}
|
||||
<div class="empty-state" style="border: none;">
|
||||
<p>No app is held on any box.</p>
|
||||
</div>
|
||||
{{end}}
|
||||
</section>
|
||||
|
||||
{{if .Unclaimed}}
|
||||
<section class="card" style="margin-bottom: 1.5rem; border-color: var(--warn);">
|
||||
<h2 style="margin-top: 0;">Unclaimed appliances <span class="text-muted" style="font-size: 0.8em; font-weight: normal;">(booted from the generic ISO, awaiting a bind)</span></h2>
|
||||
|
||||
Reference in new issue
Block a user