console: operator Protection page across every app
GET /fleet/protection lists the apps with anything caught over the last 7 or 30 UTC days, read through readEdgeDays in the operator's view: a fleet whose days cannot be read is named and left out, a root box's error stands alone. /fleet/protection/data answers the summary, every counted app and the unreadable fleets as JSON. Both are operatorOnly, as Economics, and the rail links the page after Economics. The claim inventory, fixtures, read probes and perf budgets take the two routes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
12 files changed,
+369
−7
internal/console/approved_protection_copy_test.go+2 −0internal/console/claim_invariant_fixtures_test.go+2 −0internal/console/claim_invariant_probes_read_test.go+2 −0internal/console/opshell.go+1 −0internal/console/opshell_test.go+2 −2internal/console/protection.go+5 −5internal/console/protectionview.go+114 −0internal/console/protectionview_test.go+197 −0internal/console/server.go+6 −0internal/console/templates/fleet_protection.html+34 −0internal/console/testdata/claim-routes.txt+2 −0internal/console/testdata/perf-budgets.txt+2 −0
diff --git a/internal/console/approved_protection_copy_test.go b/internal/console/approved_protection_copy_test.go| index feffdb410..f614ffc68 100644 |
| --- a/internal/console/approved_protection_copy_test.go |
| +++ b/internal/console/approved_protection_copy_test.go |
| @@ -27,6 +27,8 @@ var protectionCopyBuilt = map[string]bool{ |
| "PT-C22": true, "PT-C23": true, "PT-C24": true, "PT-C25": true, "PT-C26": true, "PT-C27": true, |
| "PT-C28": true, "PT-C29": true, "PT-C30": true, "PT-C31": true, "PT-C32": true, "PT-C33": true, |
| "PT-C34": true, "PT-C35": true, "PT-C36": true, "PT-C37": true, |
| + // Task 7: the operator page. |
| + "PT-C40": true, "PT-C41": true, "PT-C42": true, "PT-C43": true, |
| } |
| func parseProtectionCopyDeck(t *testing.T) []navCopyRow { |
diff --git a/internal/console/claim_invariant_fixtures_test.go b/internal/console/claim_invariant_fixtures_test.go| index 18080da54..37be416a1 100644 |
| --- a/internal/console/claim_invariant_fixtures_test.go |
| +++ b/internal/console/claim_invariant_fixtures_test.go |
| @@ -905,6 +905,8 @@ var claimFixtures = map[string]claimFixture{ |
| "route GET /fleet/metrics": claimRead("operator box metrics"), |
| "route GET /fleet/people": claimRead("operator people and accounts list; SQLite only"), |
| "route GET /fleet/people/{address}": claimRead("operator person page; SQLite only, writes nothing"), |
| + "route GET /fleet/protection": claimRead("operator protection page: the edge days of every fleet and the root boxes, read from the bucket; writes nothing"), |
| + "route GET /fleet/protection/data": claimRead("the operator protection page as JSON; writes nothing"), |
| "route GET /fleet/store": claimRead("operator entitlement queue page"), |
| "route GET /healthz": claimRead("answers ok and the build"), |
| "route GET /invite/{token}": claimRead("shows an invitation; joining is the POST"), |
diff --git a/internal/console/claim_invariant_probes_read_test.go b/internal/console/claim_invariant_probes_read_test.go| index 78ee3ca7a..9ba677e4f 100644 |
| --- a/internal/console/claim_invariant_probes_read_test.go |
| +++ b/internal/console/claim_invariant_probes_read_test.go |
| @@ -181,6 +181,8 @@ var claimReadProbes = map[string]claimProbe{ |
| "route GET /fleet/metrics": claimPageRead(nil, "/fleet/metrics", "<h1>Metrics</h1>"), |
| "route GET /fleet/people": claimPageRead(nil, "/fleet/people", "<h1>People and accounts</h1>"), |
| "route GET /fleet/people/{address}": claimPageRead(nil, "/fleet/people/paul@keymail.dev", "<h1>paul@keymail.dev</h1>"), |
| + "route GET /fleet/protection": claimPageRead(nil, "/fleet/protection", "<h1>Protection</h1>"), |
| + "route GET /fleet/protection/data": claimPageRead(nil, "/fleet/protection/data", `"unreadable_fleets"`), |
| "route GET /fleet/store": claimPageRead(claimWorldApply, "/fleet/store", "<h1>Storage requests</h1>"), |
| "route GET /healthz": claimPageRead(nil, "/healthz", "ok"), |
| "route GET /static/{hash}/{file...}": claimPageRead(nil, assetURL("rastrillo/tokens.css"), "--rst-"), |
diff --git a/internal/console/opshell.go b/internal/console/opshell.go| index 5e27fe3aa..fc95cb950 100644 |
| --- a/internal/console/opshell.go |
| +++ b/internal/console/opshell.go |
| @@ -35,6 +35,7 @@ var opRail = []opRailItem{ |
| {Key: "metrics", Href: "/fleet/metrics", Label: "Metrics"}, |
| {Key: "store", Href: "/fleet/store", Label: "Storage requests", StoreOnly: true}, |
| {Key: "economics", Href: "/fleet/economics", Label: "Economics"}, |
| + {Key: "protection", Href: "/fleet/protection", Label: "Protection"}, |
| {Key: "architecture", Href: "/fleet/architecture", Label: "Architecture"}, |
| } |
diff --git a/internal/console/opshell_test.go b/internal/console/opshell_test.go| index 5388e4007..b79fb9e65 100644 |
| --- a/internal/console/opshell_test.go |
| +++ b/internal/console/opshell_test.go |
| @@ -201,8 +201,8 @@ func TestRailHidesStorageFromOtherOperators(t *testing.T) { |
| t.Fatalf("/fleet/index = %d", status) |
| } |
| links := opNavLinks(t, body) |
| - if len(links) != 7 { |
| - t.Fatalf("the rail has %d links, want 7: %+v", len(links), links) |
| + if len(links) != 8 { |
| + t.Fatalf("the rail has %d links, want 8: %+v", len(links), links) |
| } |
| if strings.Contains(body, `href="/fleet/store"`) { |
| t.Fatal("an operator not on StoreOperators is shown /fleet/store") |
diff --git a/internal/console/protection.go b/internal/console/protection.go| index c9a62379e..39d9e45de 100644 |
| --- a/internal/console/protection.go |
| +++ b/internal/console/protection.go |
| @@ -44,11 +44,11 @@ type protectionSummary struct { |
| // protectionAppRow is one app's totals on the operator's page. |
| type protectionAppRow struct { |
| - Account string |
| - App string |
| - Checked int64 |
| - Watch int64 |
| - Block int64 |
| + Account string `json:"account"` |
| + App string `json:"app"` |
| + Checked int64 `json:"checked"` |
| + Watch int64 `json:"watch"` |
| + Block int64 `json:"block"` |
| } |
| // protectionDates is the last days UTC dates up to and including now's, |
diff --git a/internal/console/protectionview.go b/internal/console/protectionview.go| index 7b388edc7..1bb884498 100644 |
| --- a/internal/console/protectionview.go |
| +++ b/internal/console/protectionview.go |
| @@ -259,3 +259,117 @@ func buildProtectionChart(days []protectionDay, now time.Time) *protectionChart |
| } |
| return &c |
| } |
| + |
| +// fleetProtectionView is the operator page: Err set means a root box could |
| +// not be read and the page says only that. Otherwise Sum is the platform's |
| +// counts, Rows the apps that had anything caught (largest first), and |
| +// Unread the fleets whose days were left out. |
| +type fleetProtectionView struct { |
| + Range string |
| + Days int |
| + Tabs opTabs |
| + Err string |
| + Sum protectionSummary |
| + Caught int64 |
| + Share string |
| + Rows []fleetProtectionRow |
| + Unread string // fleet names, comma-separated |
| +} |
| + |
| +// fleetProtectionRow is one app's line: its caught count (recorded plus |
| +// blocked) and its share of what was checked for it. |
| +type fleetProtectionRow struct { |
| + Account, App string |
| + Caught int64 |
| + Block int64 |
| + Share string |
| +} |
| + |
| +// readFleetProtection is every app's counts over dates, read under |
| +// instanceStoreTimeout through the operator's view of readEdgeDays: a fleet |
| +// whose days cannot be read is left out and named, a root box's error fails |
| +// the read. |
| +func (s *Server) readFleetProtection(ctx context.Context, dates []string, now time.Time) (protectionSummary, []protectionAppRow, []string, error) { |
| + if s.cfg.Releases == nil { |
| + return protectionSummary{}, nil, nil, errors.New("no bucket") |
| + } |
| + ctx, cancel := context.WithTimeout(ctx, instanceStoreTimeout) |
| + defer cancel() |
| + srcs, unread, err := s.readEdgeDays(ctx, s.usageDayReader(now), dates, "") |
| + if err != nil { |
| + return protectionSummary{}, nil, nil, err |
| + } |
| + sum, rows := sumProtectionAll(srcs, dates) |
| + return sum, rows, unread, nil |
| +} |
| + |
| +// handleFleetProtection renders the operator's Protection page. Access is |
| +// the Economics page's: operatorOnly, so anyone else gets its 404. |
| +func (s *Server) handleFleetProtection(w http.ResponseWriter, r *http.Request) { |
| + addr, raw, ok := s.operatorOnly(w, r) |
| + if !ok { |
| + return |
| + } |
| + now := time.Now() |
| + rng, days := protectionRange(r.URL.Query()) |
| + p := s.opPage(addr, raw, "protection") |
| + v := &fleetProtectionView{Range: rng, Days: days} |
| + v.Tabs = opTabs{Label: p.Title, Items: []opTab{ |
| + {Label: "7 days", Href: "?range=7d", Current: rng == "7d"}, |
| + {Label: "30 days", Href: "?range=30d", Current: rng == "30d"}, |
| + }} |
| + sum, rows, unread, err := s.readFleetProtection(r.Context(), protectionDates(days, now), now) |
| + if err != nil { |
| + log.Printf("console: fleet protection: %v", err) |
| + v.Err = protectionReadErr |
| + } else { |
| + v.Sum = sum |
| + v.Caught = sum.Watch + sum.Block |
| + if sum.Checked > 0 && v.Caught > 0 { |
| + v.Share = protectionShare(v.Caught, sum.Checked) |
| + } |
| + for _, row := range rows { |
| + caught := row.Watch + row.Block |
| + if caught == 0 { |
| + continue |
| + } |
| + share := "" |
| + if row.Checked > 0 { |
| + share = protectionShare(caught, row.Checked) |
| + } |
| + v.Rows = append(v.Rows, fleetProtectionRow{Account: row.Account, App: row.App, Caught: caught, Block: row.Block, Share: share}) |
| + } |
| + v.Unread = strings.Join(unread, ", ") |
| + } |
| + p.FleetProtection = v |
| + s.render(w, http.StatusOK, "fleet_protection", p) |
| +} |
| + |
| +// handleFleetProtectionData is the page's JSON door: the platform's summary, |
| +// a row for every app that had a tally (caught or not), largest caught |
| +// first, and the fleets left out. The same gate; a failed read is a 502. |
| +func (s *Server) handleFleetProtectionData(w http.ResponseWriter, r *http.Request) { |
| + w.Header().Set("Cache-Control", "no-store") |
| + if _, _, ok := s.operatorOnly(w, r); !ok { |
| + return |
| + } |
| + now := time.Now() |
| + _, days := protectionRange(r.URL.Query()) |
| + sum, rows, unread, err := s.readFleetProtection(r.Context(), protectionDates(days, now), now) |
| + if err != nil { |
| + log.Printf("console: fleet protection data: %v", err) |
| + jsonError(w, http.StatusBadGateway, "could not read the protection counts") |
| + return |
| + } |
| + if rows == nil { |
| + rows = []protectionAppRow{} |
| + } |
| + if unread == nil { |
| + unread = []string{} |
| + } |
| + writeJSON(w, http.StatusOK, struct { |
| + Summary protectionSummary `json:"summary"` |
| + Apps []protectionAppRow `json:"apps"` |
| + Unreadable []string `json:"unreadable_fleets"` |
| + }{sum, rows, unread}) |
| +} |
diff --git a/internal/console/protectionview_test.go b/internal/console/protectionview_test.go| index e58d84cba..d58c67d4d 100644 |
| --- a/internal/console/protectionview_test.go |
| +++ b/internal/console/protectionview_test.go |
| @@ -424,3 +424,200 @@ func TestLogsPageCarriesProtectionFilter(t *testing.T) { |
| t.Errorf("without protection=1 the form = %s, want the edge stream and no protection filter", form) |
| } |
| } |
| + |
| +// fpGuard writes one app's guard tally for today into box's day on st, |
| +// through the edge's own writer, claiming account for it. |
| +func fpGuard(t *testing.T, st release.Store, box, host, account, app string, checked, watch, block int64) { |
| + t.Helper() |
| + f := usage.EdgeFlush{ |
| + Rows: map[string]usage.EdgeRow{host: {Account: account, App: app, Requests: checked}}, |
| + Guard: map[string]usage.GuardDelta{usage.GuardKey(host, account, app): { |
| + Host: host, Account: account, App: app, Checked: checked, Watch: watch, Block: block, |
| + Groups: map[string]int64{"probe/php": watch + block}, |
| + }}, |
| + } |
| + if err := usage.UpsertEdgeDay(context.Background(), st, box, time.Now(), f); err != nil { |
| + t.Fatal(err) |
| + } |
| +} |
| + |
| +// fpFixture is an operator console with three apps counted: shop on a root |
| +// box (bab, 100 checked, 6 recorded), blog on fleet f1's box (owned by bdk, |
| +// 50 checked, 1 recorded and 3 blocked), and fake, a row the same fleet's |
| +// box files under account bab, which the fleet's owner cannot vouch for. |
| +func fpFixture(t *testing.T) (*consoleFixture, *http.Client) { |
| + t.Helper() |
| + fx := newConsoleFixture(t) |
| + c := signInOperator(t, fx) |
| + edCreateFleet(t, fx, "f1", "bdk") |
| + fpGuard(t, fx.rel, "box-a", ptHost, "bab", "shop", 100, 6, 0) |
| + fpGuard(t, edFleetStore(fx, "f1"), "pi-1", "blog.example.com", "bdk", "blog", 50, 1, 3) |
| + fpGuard(t, edFleetStore(fx, "f1"), "pi-1", "fake.example.com", "bab", "fake", 30, 9, 0) |
| + return fx, c |
| +} |
| + |
| +func fpPage(t *testing.T, fx *consoleFixture, c *http.Client, query string) string { |
| + t.Helper() |
| + status, _, body := get(t, c, fx.ts.URL+"/fleet/protection"+query) |
| + if status != http.StatusOK { |
| + t.Fatalf("/fleet/protection%s = %d: %s", query, status, body) |
| + } |
| + return navSpace(html.UnescapeString(body)) |
| +} |
| + |
| +// The page and its door are the operator's alone: whoever gets a 404 from |
| +// /fleet/economics gets the same from both. |
| +func TestFleetProtectionOperatorsOnly(t *testing.T) { |
| + fx := newConsoleFixture(t) |
| + for who, c := range map[string]*http.Client{"signed out": newBrowser(t), "not an operator": signInPaul(t, fx)} { |
| + wantStatus, _, want := get(t, c, fx.ts.URL+"/fleet/economics") |
| + if wantStatus != http.StatusNotFound { |
| + t.Fatalf("%s: /fleet/economics = %d, want 404", who, wantStatus) |
| + } |
| + for _, path := range []string{"/fleet/protection", "/fleet/protection?range=30d", "/fleet/protection/data"} { |
| + if st, _, body := get(t, c, fx.ts.URL+path); st != wantStatus || body != want { |
| + t.Errorf("%s: %s = %d %q, want what /fleet/economics gives (%d %q)", who, path, st, body, wantStatus, want) |
| + } |
| + } |
| + } |
| +} |
| + |
| +func TestFleetProtectionListsApps(t *testing.T) { |
| + fx, c := fpFixture(t) |
| + page := fpPage(t, fx, c, "") |
| + ptWant(t, page, |
| + ptCopy(t, "PT-C41", map[string]string{"days": "7", "caught": "10", "apps": "2"}), |
| + ptCopy(t, "PT-C05", map[string]string{"pct": "7%", "checked": "150"})) |
| + // Each heading of PT-C42 is its own column, in the deck's order. |
| + last := -1 |
| + for _, h := range strings.Split(ptCopy(t, "PT-C42", nil), " · ") { |
| + i := strings.Index(page, ">"+h+"</th>") |
| + if i < 0 || i < last { |
| + t.Errorf("column heading %q missing or out of order (at %d, after %d)", h, i, last) |
| + } |
| + last = i |
| + } |
| + // Largest first, each with its account; the foreign row is no row. |
| + shop := strings.Index(page, "<td>bab</td> <td>shop</td> <td>6</td> <td>0</td> <td>6%</td>") |
| + blog := strings.Index(page, "<td>bdk</td> <td>blog</td> <td>4</td> <td>3</td> <td>8%</td>") |
| + if shop < 0 || blog < 0 || shop > blog { |
| + t.Errorf("rows: shop at %d, blog at %d, want shop then blog:\n%s", shop, blog, page) |
| + } |
| + ptRefuse(t, page, "fake", ptCopy(t, "PT-C18", nil), "These fleets") |
| + |
| + page = fpPage(t, fx, c, "?range=30d") |
| + ptWant(t, page, ptCopy(t, "PT-C41", map[string]string{"days": "30", "caught": "10", "apps": "2"}), |
| + ptCopy(t, "PT-C16", nil), ptCopy(t, "PT-C17", nil)) |
| + page = fpPage(t, fx, c, "?range=bogus") |
| + ptWant(t, page, ptCopy(t, "PT-C41", map[string]string{"days": "7", "caught": "10", "apps": "2"})) |
| +} |
| + |
| +// Checked traffic with nothing caught still reads as a clean window, and |
| +// has no rows. Nothing checked anywhere says no headline at all. |
| +func TestFleetProtectionNothingCaught(t *testing.T) { |
| + fx := newConsoleFixture(t) |
| + c := signInOperator(t, fx) |
| + page := fpPage(t, fx, c, "") |
| + ptRefuse(t, page, ptHeadlineLead, "That's", "<td>") |
| + ptWant(t, page, "<th scope=\"col\">Account</th>") |
| + |
| + fpGuard(t, fx.rel, "box-a", ptHost, "bab", "shop", 100, 0, 0) |
| + page = fpPage(t, fx, c, "") |
| + ptWant(t, page, ptCopy(t, "PT-C41", map[string]string{"days": "7", "caught": "0", "apps": "0"})) |
| + ptRefuse(t, page, "That's", "<td>") |
| +} |
| + |
| +func TestFleetProtectionData(t *testing.T) { |
| + fx, c := fpFixture(t) |
| + status, _, body := get(t, c, fx.ts.URL+"/fleet/protection/data") |
| + if status != http.StatusOK { |
| + t.Fatalf("data = %d %s", status, body) |
| + } |
| + var got struct { |
| + Summary protectionSummary `json:"summary"` |
| + Apps []struct { |
| + Account string `json:"account"` |
| + App string `json:"app"` |
| + Checked int64 `json:"checked"` |
| + Watch int64 `json:"watch"` |
| + Block int64 `json:"block"` |
| + } `json:"apps"` |
| + Unreadable []string `json:"unreadable_fleets"` |
| + } |
| + if err := json.Unmarshal([]byte(body), &got); err != nil { |
| + t.Fatalf("%v: %s", err, body) |
| + } |
| + if got.Summary.Checked != 150 || got.Summary.Watch != 7 || got.Summary.Block != 3 || len(got.Summary.Days) != 7 { |
| + t.Errorf("summary = %+v", got.Summary) |
| + } |
| + if len(got.Apps) != 2 || got.Apps[0].App != "shop" || got.Apps[0].Account != "bab" || got.Apps[0].Watch != 6 || |
| + got.Apps[1].App != "blog" || got.Apps[1].Block != 3 || got.Apps[1].Checked != 50 { |
| + t.Errorf("apps = %+v, want shop (6 caught) then blog (4 caught)", got.Apps) |
| + } |
| + if got.Unreadable == nil || len(got.Unreadable) != 0 || !strings.Contains(body, `"unreadable_fleets":[]`) { |
| + t.Errorf("unreadable_fleets = %v in %s, want []", got.Unreadable, body) |
| + } |
| + if st, _, b := get(t, c, fx.ts.URL+"/fleet/protection/data?range=30d"); st != http.StatusOK || !strings.Contains(b, `"to"`) { |
| + t.Errorf("30d data = %d %s", st, b) |
| + } |
| +} |
| + |
| +// A fleet whose days cannot be read is left out and named; the page and the |
| +// rest of its counts stand. |
| +func TestFleetProtectionNamesUnreadableFleet(t *testing.T) { |
| + fx, c := fpFixture(t) |
| + edCreateFleet(t, fx, "f2", "bab") |
| + edCreateFleet(t, fx, "f3", "bdk") |
| + edPut(t, fx.rel, "fleets/f2/"+usage.EdgeDayKey("pi-2", usage.DayOf(time.Now())), "{not json") |
| + edPut(t, fx.rel, "fleets/f3/"+usage.EdgeDayKey("pi-3", usage.DayOf(time.Now())), "{not json") |
| + |
| + page := fpPage(t, fx, c, "") |
| + ptWant(t, page, |
| + ptCopy(t, "PT-C43", map[string]string{"fleets": "f2, f3"}), |
| + ptCopy(t, "PT-C41", map[string]string{"days": "7", "caught": "10", "apps": "2"}), |
| + "<td>shop</td>", "<td>blog</td>") |
| + ptRefuse(t, page, ptCopy(t, "PT-C18", nil)) |
| + |
| + status, _, body := get(t, c, fx.ts.URL+"/fleet/protection/data") |
| + if status != http.StatusOK || !strings.Contains(body, `"unreadable_fleets":["f2","f3"]`) { |
| + t.Errorf("data = %d %s, want 200 naming f2 and f3", status, body) |
| + } |
| +} |
| + |
| +// A root box that cannot be read fails the page as a whole: the error alone, |
| +// no headline, no table and no zeros; the door answers 502. |
| +func TestFleetProtectionRootErrorSaysSo(t *testing.T) { |
| + fx, c := fpFixture(t) |
| + edPut(t, fx.rel, usage.EdgeDayKey("box-b", usage.DayOf(time.Now())), "{not json") |
| + page := fpPage(t, fx, c, "") |
| + ptWant(t, page, ptCopy(t, "PT-C18", nil)) |
| + ptRefuse(t, page, ptHeadlineLead, "That's", "<table", "<td>") |
| + |
| + status, _, body := get(t, c, fx.ts.URL+"/fleet/protection/data") |
| + if status != http.StatusBadGateway || strings.Contains(body, `"checked"`) { |
| + t.Errorf("data on a root error = %d %s, want 502 and no counts", status, body) |
| + } |
| +} |
| + |
| +// The operator rail links the page right after Economics, under PT-C40. |
| +func TestOperatorRailHasProtection(t *testing.T) { |
| + fx, c := fpFixture(t) |
| + _, _, body := get(t, c, fx.ts.URL+"/fleet/index") |
| + links := opNavLinks(t, body) |
| + var keys []string |
| + for _, l := range links { |
| + keys = append(keys, l.Key) |
| + } |
| + for i, k := range keys { |
| + if k == "economics" { |
| + if i+1 >= len(keys) || keys[i+1] != "protection" { |
| + t.Fatalf("rail %v: want protection right after economics", keys) |
| + } |
| + if !strings.Contains(body, `<a id="nav-protection" href="/fleet/protection">`+ptCopy(t, "PT-C40", nil)+`</a>`) { |
| + t.Error("the rail's Protection link is not worded PT-C40") |
| + } |
| + return |
| + } |
| + } |
| + t.Fatalf("rail %v has no economics", keys) |
| +} |
diff --git a/internal/console/server.go b/internal/console/server.go| index 60ef732a2..63f41b4ef 100644 |
| --- a/internal/console/server.go |
| +++ b/internal/console/server.go |
| @@ -1752,6 +1752,10 @@ func NewServer(cfg Config, st *Store) (*Server, error) { |
| s.registerRoute("POST /a/{sqid}/store/apply", s.handleStoreApplyPage) |
| s.registerRoute("GET /fleet/metrics", s.handleFleetMetrics) |
| s.registerRoute("GET /fleet/economics", s.handleEconomics) |
| + // The operator's Protection page (protectionview.go) and its JSON door: |
| + // what the edge guard did across every app. Operators only, as Economics. |
| + s.registerRoute("GET /fleet/protection", s.handleFleetProtection) |
| + s.registerRoute("GET /fleet/protection/data", s.handleFleetProtectionData) |
| // The deployment's map (archpage.go), same operatorOnly gate. BOTH are |
| // registered WITHOUT a method prefix, for the reason spelled out below |
| // the economics doors: a "GET /path" pattern answers a POST with 405 + |
| @@ -2568,6 +2572,8 @@ type page struct { |
| // Protection is the Protection tab (protectionview.go): the window's |
| // counts and how the page draws them, or the read error alone. |
| Protection *protectionView |
| + // FleetProtection is the operator's page of the same name. |
| + FleetProtection *fleetProtectionView |
| // Action confirm interstitial (confirm.go): what is about to happen, |
| // carried fields and all. Nil everywhere except the confirm page. |
diff --git a/internal/console/templates/fleet_protection.html b/internal/console/templates/fleet_protection.html| new file mode 100644 |
| index 000000000..f07e104e9 |
| --- /dev/null |
| +++ b/internal/console/templates/fleet_protection.html |
| @@ -0,0 +1,34 @@ |
| +{{/* /fleet/protection: what the edge guard did across every app, for the |
| + last 7 or 30 whole UTC days. The words are the Protection copy deck's |
| + (PT-C40 to PT-C43, and the per-app tab's for what is shown alike). The |
| + operator shell carries none of the customer console's Analytics |
| + styles, so the page is the shell's own parts: tabs, callouts, a table. */}} |
| +{{define "fleet_protection"}}{{template "op_top" .}} |
| +{{template "op_page_header" (opHeader "Protection" "")}} |
| +{{with .FleetProtection}} |
| +{{template "op_seg_tabs" .Tabs}} |
| +{{/* A failed read stands alone: no headline, no table and no zeros. */}} |
| +{{if .Err}}<div rst-callout rst-tone="negative"><span rst-callout-ic aria-hidden="true">{{icon "triangle-alert"}}</span><div rst-callout-body><p>{{.Err}}</p></div></div> |
| +{{else}} |
| +{{/* Nothing checked across the platform says no headline: a count of |
| + nothing caught would claim requests nobody counted. */}} |
| +{{if .Sum.Checked}}<p><strong>In the last {{.Days}} days, {{count .Caught}} requests across {{len .Rows}} apps looked like attacks.</strong></p> |
| +{{if .Caught}}<p co-note>That's {{.Share}} of the {{count .Sum.Checked}} requests protection checked.</p>{{end}}{{end}} |
| +{{if .Unread}}<div rst-callout rst-tone="negative"><span rst-callout-ic aria-hidden="true">{{icon "triangle-alert"}}</span><div rst-callout-body><p>These fleets' counts could not be read and are left out: {{.Unread}}.</p></div></div>{{end}} |
| +<div rst-card class="co-table-wrap"> |
| +<table co-table> |
| + <tr><th scope="col">Account</th><th scope="col">App</th><th scope="col">Caught</th><th scope="col">Blocked</th><th scope="col">Share</th></tr> |
| + {{range .Rows}} |
| + <tr> |
| + <td>{{.Account}}</td> |
| + <td>{{.App}}</td> |
| + <td>{{count .Caught}}</td> |
| + <td>{{count .Block}}</td> |
| + <td>{{.Share}}</td> |
| + </tr> |
| + {{end}} |
| +</table> |
| +</div> |
| +{{end}} |
| +{{end}} |
| +{{template "op_bottom" .}}{{end}} |
diff --git a/internal/console/testdata/claim-routes.txt b/internal/console/testdata/claim-routes.txt| index f93d2df36..dd0b6c269 100644 |
| --- a/internal/console/testdata/claim-routes.txt |
| +++ b/internal/console/testdata/claim-routes.txt |
| @@ -127,6 +127,8 @@ route GET /fleet/index |
| route GET /fleet/metrics |
| route GET /fleet/people |
| route GET /fleet/people/{address} |
| +route GET /fleet/protection |
| +route GET /fleet/protection/data |
| route GET /fleet/store |
| route GET /healthz |
| route GET /invite/{token} |
diff --git a/internal/console/testdata/perf-budgets.txt b/internal/console/testdata/perf-budgets.txt| index f4640dc46..ca38dcb2d 100644 |
| --- a/internal/console/testdata/perf-budgets.txt |
| +++ b/internal/console/testdata/perf-budgets.txt |
| @@ -35,6 +35,7 @@ |
| GET /auth/callback skip: needs a live OAuth state and makes a token POST to Keymail |
| GET /auth/stepup/callback skip: needs a live OAuth state and makes a token POST to Keymail |
| GET /auth/cli/whoami skip: a bearer-token JSON door, not a screen; timed in production |
| +GET /fleet/protection/data skip: the operator Protection page's JSON door, not a screen; the page makes the same reads (protectionview.go) |
| GET /static/{hash}/{file...} skip: static asset, not a screen; consolePerfSkip leaves it unmeasured |
| /fleet/architecture/refresh skip: POST-only door; a GET answers 404 on its first line by design (archpage.go) |
| /fleet/economics/bill skip: POST-only door; a GET answers 404 on its first line by design (economicspass.go) |
| @@ -79,6 +80,7 @@ GET /a/{sqid}/settings calls 2: the account telemetry settings and the storage e |
| GET /a/{sqid}/trash calls 1: reads each trashed app's deleted.json marker (1 S3 call per trashed app, about 28 ms) |
| GET /fleet calls 12: the dashboard reads status/fleet.json, lists and reads every box report once each, and for a store operator lists and reads the storage entitlements, the same reads Boxes makes, all at once; operator pages carry no cache (12 S3 calls warm and cold, about 140 ms) |
| GET /fleet/boxes calls 12: lists and reads every box report, reads status/fleet.json, and lists and reads the storage entitlements, all at once; operator pages carry no cache (12 S3 calls warm and cold, about 140 ms) |
| +GET /fleet/protection calls 2: the operator Protection page reads the edge days: one box listing at the root and one in each fleet the registry knows (the walk's fixture: two listings and no edge days, about 55 ms); each box adds its today's and yesterday's day, which never settle, and the usage-day cache answers the rest; operator pages carry no cache |
| GET /fleet/store calls 3: lists the storage entitlements and the storage usage days and reads each pending application (3 S3 calls warm and cold, about 80 ms) |
| # Known slow today: fails the two-tier rule (re-measured 2026-10-28 with |