carlos / platform Public

console: day-by-day and groups tables on the operator Protection page

The page now shows the per-app tab's day-by-day and what-they-were-after
views as plain tables in the operator shell. The JSON door's apps list only
apps with something caught, so it matches the page's table.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev e25aa3f0d3a3342215d6da5a0aab25d4c43c651f parent 3d38eac
3 files changed, +84 −10
  • internal/console/protectionview.go +23 −10
  • internal/console/protectionview_test.go +35 −0
  • internal/console/templates/fleet_protection.html +26 −0
diff --git a/internal/console/protectionview.go b/internal/console/protectionview.go
index 1bb884498..62092ff03 100644
--- a/internal/console/protectionview.go
+++ b/internal/console/protectionview.go
@@ -273,7 +273,23 @@ type fleetProtectionView struct {
Caught int64
Share string
Rows []fleetProtectionRow
- Unread string // fleet names, comma-separated
+ // DayRows is every date of the window, oldest first, and Groups what they
+ // were after, largest first, named as the per-app tab names them.
+ DayRows []protectionDay
+ Groups []shareRow
+ Unread string // fleet names, comma-separated
+}
+
+// caughtApps is rows without the apps that had nothing caught, so the page's
+// table and the JSON door list the same apps. Order is kept.
+func caughtApps(rows []protectionAppRow) []protectionAppRow {
+ out := make([]protectionAppRow, 0, len(rows))
+ for _, r := range rows {
+ if r.Watch+r.Block > 0 {
+ out = append(out, r)
+ }
+ }
+ return out
}
// fleetProtectionRow is one app's line: its caught count (recorded plus
@@ -328,11 +344,10 @@ func (s *Server) handleFleetProtection(w http.ResponseWriter, r *http.Request) {
if sum.Checked > 0 && v.Caught > 0 {
v.Share = protectionShare(v.Caught, sum.Checked)
}
- for _, row := range rows {
+ v.DayRows = sum.Days
+ v.Groups = shareRows(protectionGroups(sum.Groups), protectionGroupLabel)
+ for _, row := range caughtApps(rows) {
caught := row.Watch + row.Block
- if caught == 0 {
- continue
- }
share := ""
if row.Checked > 0 {
share = protectionShare(caught, row.Checked)
@@ -346,8 +361,8 @@ func (s *Server) handleFleetProtection(w http.ResponseWriter, r *http.Request) {
}
// 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.
+// a row for every app with anything caught, largest first (the page's
+// table), 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 {
@@ -361,9 +376,7 @@ func (s *Server) handleFleetProtectionData(w http.ResponseWriter, r *http.Reques
jsonError(w, http.StatusBadGateway, "could not read the protection counts")
return
}
- if rows == nil {
- rows = []protectionAppRow{}
- }
+ rows = caughtApps(rows)
if unread == nil {
unread = []string{}
}
diff --git a/internal/console/protectionview_test.go b/internal/console/protectionview_test.go
index d58c67d4d..231d656a0 100644
--- a/internal/console/protectionview_test.go
+++ b/internal/console/protectionview_test.go
@@ -550,6 +550,13 @@ func TestFleetProtectionData(t *testing.T) {
if got.Summary.Checked != 150 || got.Summary.Watch != 7 || got.Summary.Block != 3 || len(got.Summary.Days) != 7 {
t.Errorf("summary = %+v", got.Summary)
}
+ // Only apps with something caught, as the page's table lists them.
+ fpGuard(t, fx.rel, "box-a", "quiet.example.com", "bab", "quiet", 40, 0, 0)
+ _, _, body = get(t, c, fx.ts.URL+"/fleet/protection/data")
+ got.Apps = nil
+ if err := json.Unmarshal([]byte(body), &got); err != nil {
+ t.Fatalf("%v: %s", err, body)
+ }
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)
@@ -621,3 +628,31 @@ func TestOperatorRailHasProtection(t *testing.T) {
}
t.Fatalf("rail %v has no economics", keys)
}
+
+// The operator page carries the per-app tab's day-by-day and groups views as
+// tables: every date of the window oldest first with blocked and recorded,
+// and every group largest first, over both apps' counts.
+func TestFleetProtectionShowsDaysAndGroups(t *testing.T) {
+ fx, c := fpFixture(t)
+ page := fpPage(t, fx, c, "")
+ ptWant(t, page, ptCopy(t, "PT-C11", nil), ptCopy(t, "PT-C14", nil),
+ ">"+ptCopy(t, "PT-C12", nil)+"</th>", ">"+ptCopy(t, "PT-C13", nil)+"</th>")
+
+ // Seven dates, oldest first, today last with both apps' counts: 3
+ // blocked and 7 recorded.
+ dates := protectionDates(7, time.Now())
+ last := -1
+ for _, d := range dates {
+ i := strings.Index(page, "<th scope=\"row\">"+d+"</th>")
+ if i < 0 || i < last {
+ t.Errorf("date %s missing or out of order", d)
+ }
+ last = i
+ }
+ ptWant(t, page, "<th scope=\"row\">"+dates[6]+"</th> <td>3</td> <td>7</td>",
+ "<th scope=\"row\">"+dates[0]+"</th> <td>0</td> <td>0</td>")
+
+ // Both apps tally under probe/php: 6 + 4 caught there, named as the tab
+ // names it.
+ ptWant(t, page, "<th scope=\"row\">"+protectionGroupName("probe/php")+"</th> <td>10</td>")
+}
diff --git a/internal/console/templates/fleet_protection.html b/internal/console/templates/fleet_protection.html
index f07e104e9..dc1248b3d 100644
--- a/internal/console/templates/fleet_protection.html
+++ b/internal/console/templates/fleet_protection.html
@@ -29,6 +29,32 @@
{{end}}
</table>
</div>
+{{if .Caught}}
+<div rst-box-head><h2 id="pt-days">Day by day</h2></div>
+<div rst-card class="co-table-wrap">
+<table co-table aria-labelledby="pt-days">
+ <tr><th scope="col"></th><th scope="col">blocked</th><th scope="col">recorded</th></tr>
+ {{range .DayRows}}
+ <tr>
+ <th scope="row">{{.Date}}</th>
+ <td>{{count .Block}}</td>
+ <td>{{count .Watch}}</td>
+ </tr>
+ {{end}}
+</table>
+</div>
+<div rst-box-head><h2 id="pt-groups">What they were after</h2></div>
+<div rst-card class="co-table-wrap">
+<table co-table aria-labelledby="pt-groups">
+ {{range .Groups}}
+ <tr>
+ <th scope="row">{{.Label}}</th>
+ <td>{{count .Value}}</td>
+ </tr>
+ {{end}}
+</table>
+</div>
+{{end}}
{{end}}
{{end}}
{{template "op_bottom" .}}{{end}}