console: Console speed table on /fleet/metrics
Per-route requests, over-budget count, p50, p95 and S3 requests from the perf recorder's groups, slowest first, plus the S3 requests no page request caused. CPF-1 to CPF-11 join the copy gate's built list.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
6 files changed,
+177
−4
.amadan/test-weights.tsv+1 −0approved_console_perf_copy_test.go+5 −3internal/console/perfspeed.go+42 −0internal/console/perfspeed_test.go+95 −0internal/console/server.go+12 −1internal/console/templates/metrics.html+22 −0
CI failed — run details
diff --git a/.amadan/test-weights.tsv b/.amadan/test-weights.tsv| index 6005af5ae..9ca62fa63 100644 |
| --- a/.amadan/test-weights.tsv |
| +++ b/.amadan/test-weights.tsv |
| @@ -100,6 +100,7 @@ github.com/carlosframework/platform/internal/console TestClaimPurgeStoreInventor |
| github.com/carlosframework/platform/internal/console TestDBReadResultAfterTheDeadlineIsNotRelayed 1.4 |
| github.com/carlosframework/platform/internal/console TestAssetsStatusIsIncompleteWhenARecordIsSkipped 1.4 |
| github.com/carlosframework/platform/internal/console TestAPIShipRefusesReassetingAReship 1.3 |
| +github.com/carlosframework/platform/internal/console TestOverBudgetPageIsLogged 1.3 |
| github.com/carlosframework/platform/internal/console TestJ4HostDoorRoutesOnlyMoveKinds 1.2 |
| github.com/carlosframework/platform/internal/console TestJ4MoveDoorInspectsThenDeclares 1.2 |
| github.com/carlosframework/platform/internal/console TestJ4MoveDoorStaleSubmission 1.2 |
diff --git a/approved_console_perf_copy_test.go b/approved_console_perf_copy_test.go| index 85f28aa89..58b958a28 100644 |
| --- a/approved_console_perf_copy_test.go |
| +++ b/approved_console_perf_copy_test.go |
| @@ -39,9 +39,11 @@ var consolePerfCopyIDs = func() []string { |
| // The task that writes a row's text adds its entry here in the same commit, |
| // once the row is approved. An entry is "CPF-n", checked in the row's first |
| // file, or "CPF-n@<path>", checked in that file. The record's file cell is |
| -// metadata and is never edited for this. Empty until the task that renders |
| -// the table. |
| -var consolePerfCopyBuilt = []string{} |
| +// metadata and is never edited for this. |
| +var consolePerfCopyBuilt = []string{ |
| + "CPF-1", "CPF-2", "CPF-3", "CPF-4", "CPF-5", "CPF-6", |
| + "CPF-7", "CPF-8", "CPF-9", "CPF-10", "CPF-11", |
| +} |
| // consolePerfBuiltRows is entryBuiltRows (approved_asset_cache_copy_test.go) |
| // for consolePerfCopyBuilt: the same entry resolution, so the two gates cannot |
diff --git a/internal/console/perfspeed.go b/internal/console/perfspeed.go| new file mode 100644 |
| index 000000000..ac62b7d4a |
| --- /dev/null |
| +++ b/internal/console/perfspeed.go |
| @@ -0,0 +1,42 @@ |
| +package console |
| + |
| +import ( |
| + "fmt" |
| + "math" |
| + |
| + "github.com/carlosframework/platform/internal/perf" |
| +) |
| + |
| +// consoleSpeedRow is one line of the Console speed table on /fleet/metrics: |
| +// one route's requests, how many were over the first-byte budget, and its |
| +// p50 and p95. S3 is the S3 requests the route's requests made. |
| +type consoleSpeedRow struct { |
| + Screen, Method string |
| + Requests, Over int |
| + S3 int |
| + P50, P95 string |
| +} |
| + |
| +// consoleSpeedRows turns the recorder's groups into table rows. The order is |
| +// the groups' own (slowest p95 first), and every group is listed, POSTs |
| +// included. |
| +func consoleSpeedRows(groups []perf.Group) []consoleSpeedRow { |
| + rows := make([]consoleSpeedRow, 0, len(groups)) |
| + for _, g := range groups { |
| + rows = append(rows, consoleSpeedRow{ |
| + Screen: g.Screen, |
| + Method: g.Method, |
| + Requests: g.Requests, |
| + Over: g.Over, |
| + S3: g.Calls["s3"], |
| + P50: consoleSpeedMillis(g.P50), |
| + P95: consoleSpeedMillis(g.P95), |
| + }) |
| + } |
| + return rows |
| +} |
| + |
| +// consoleSpeedMillis is a time in milliseconds, rounded to a whole number. |
| +func consoleSpeedMillis(ms float64) string { |
| + return fmt.Sprintf("%d ms", int64(math.Round(ms))) |
| +} |
diff --git a/internal/console/perfspeed_test.go b/internal/console/perfspeed_test.go| new file mode 100644 |
| index 000000000..dfa196511 |
| --- /dev/null |
| +++ b/internal/console/perfspeed_test.go |
| @@ -0,0 +1,95 @@ |
| +package console |
| + |
| +import ( |
| + "net/http" |
| + "net/url" |
| + "strings" |
| + "testing" |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/perf" |
| +) |
| + |
| +func TestConsoleSpeedRowsFormat(t *testing.T) { |
| + rows := consoleSpeedRows([]perf.Group{ |
| + {Screen: "GET /a", Method: "GET", P50: 12.4, P95: 151.6, Requests: 3, Over: 1, Calls: map[string]int{"s3": 7}}, |
| + {Screen: "POST /b", Method: "POST", P50: 0.4, P95: 2, Requests: 1}, |
| + }) |
| + if len(rows) != 2 { |
| + t.Fatalf("rows = %+v, want 2", rows) |
| + } |
| + want := consoleSpeedRow{Screen: "GET /a", Method: "GET", Requests: 3, Over: 1, S3: 7, P50: "12 ms", P95: "152 ms"} |
| + if rows[0] != want { |
| + t.Errorf("row 0 = %+v, want %+v", rows[0], want) |
| + } |
| + if rows[1].Screen != "POST /b" || rows[1].S3 != 0 || rows[1].P50 != "0 ms" || rows[1].P95 != "2 ms" { |
| + t.Errorf("row 1 = %+v, want order kept, no s3 calls, 0 ms / 2 ms", rows[1]) |
| + } |
| +} |
| + |
| +// operatorBrowser is a browser signed in as an operator through a session |
| +// minted straight in the store, so nothing is recorded in the perf recorder |
| +// before the page under test. |
| +func operatorBrowser(t *testing.T, fx *consoleFixture) *http.Client { |
| + t.Helper() |
| + raw, err := fx.st.CreateSession("paul@keymail.dev", "tok-"+t.Name(), time.Now()) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := fx.st.SetOperator("paul@keymail.dev", true); err != nil { |
| + t.Fatal(err) |
| + } |
| + c := newBrowser(t) |
| + u, _ := url.Parse(fx.ts.URL) |
| + c.Jar.SetCookies(u, []*http.Cookie{{Name: sessionCookie, Value: raw, Path: "/"}}) |
| + return c |
| +} |
| + |
| +func TestFleetMetricsShowsConsoleSpeed(t *testing.T) { |
| + fx := newConsoleFixture(t) |
| + c := signInPaul(t, fx) |
| + if err := fx.st.SetOperator("paul@keymail.dev", true); err != nil { |
| + t.Fatal(err) |
| + } |
| + if status, _, _ := get(t, c, fx.u("/apps/kass")); status != 200 { |
| + t.Fatalf("app page = %d, want 200", status) |
| + } |
| + status, _, body := get(t, c, fx.ts.URL+"/fleet/metrics") |
| + if status != 200 { |
| + t.Fatalf("/fleet/metrics = %d: %s", status, body) |
| + } |
| + for _, want := range []string{"Console speed", "Over 150 ms", "GET /a/{sqid}/apps/{app}"} { |
| + if !strings.Contains(body, want) { |
| + t.Errorf("/fleet/metrics missing %q in:\n%s", want, body) |
| + } |
| + } |
| + if strings.Contains(body, "No requests measured since the console started.") { |
| + t.Errorf("/fleet/metrics shows the empty state with requests measured") |
| + } |
| + if strings.Contains(body, `/apps/kass"`) { |
| + t.Errorf("/fleet/metrics carries a path, not a route pattern") |
| + } |
| +} |
| + |
| +func TestFleetMetricsConsoleSpeedEmptyState(t *testing.T) { |
| + fx := newConsoleFixture(t) |
| + c := operatorBrowser(t, fx) |
| + if g := fx.srv.PerfGroups(); len(g) != 0 { |
| + t.Fatalf("setup recorded %+v before the metrics page; the empty state needs an empty recorder", g) |
| + } |
| + status, _, body := get(t, c, fx.ts.URL+"/fleet/metrics") |
| + if status != 200 { |
| + t.Fatalf("/fleet/metrics = %d: %s", status, body) |
| + } |
| + if !strings.Contains(body, "No requests measured since the console started.") { |
| + t.Errorf("first /fleet/metrics lacks the empty state:\n%s", body) |
| + } |
| + // The metrics GET is measured once it has rendered, so the next view has a row. |
| + _, _, again := get(t, c, fx.ts.URL+"/fleet/metrics") |
| + if strings.Contains(again, "No requests measured since the console started.") { |
| + t.Errorf("second /fleet/metrics still shows the empty state") |
| + } |
| + if !strings.Contains(again, "GET /fleet/metrics") { |
| + t.Errorf("second /fleet/metrics lacks its own route row:\n%s", again) |
| + } |
| +} |
diff --git a/internal/console/server.go b/internal/console/server.go| index 9d1d2bf0d..dd12d3b8f 100644 |
| --- a/internal/console/server.go |
| +++ b/internal/console/server.go |
| @@ -2008,6 +2008,11 @@ type page struct { |
| Metrics []BoxMetricsView |
| MetricAlerts []AlertRow |
| + // The Console speed table on /fleet/metrics (perfspeed.go), and the S3 |
| + // requests made outside any page request since the console started. |
| + ConsoleSpeed []consoleSpeedRow |
| + ConsoleS3Background int64 |
| + |
| // /fleet/architecture (archgraph.go): the deployment's map. Arch is nil |
| // on every other page, and the template's {{with .Arch}} is what keeps |
| // this page's blocks off them. |
| @@ -3229,7 +3234,13 @@ func (s *Server) handleFleetMetrics(w http.ResponseWriter, r *http.Request) { |
| s.renderMessage(w, r, http.StatusInternalServerError, "Unavailable", "Metrics could not be read.") |
| return |
| } |
| - s.render(w, http.StatusOK, "metrics", page{Title: "Fleet metrics", Address: addr, CSRF: raw, Metrics: boxes, MetricAlerts: alerts}) |
| + // The Console speed table reads the recorder before this request is in |
| + // it: a request is recorded once it has rendered. |
| + s.render(w, http.StatusOK, "metrics", page{ |
| + Title: "Fleet metrics", Address: addr, CSRF: raw, Metrics: boxes, MetricAlerts: alerts, |
| + ConsoleSpeed: consoleSpeedRows(s.PerfGroups()), |
| + ConsoleS3Background: s.PerfBackground()["s3"], |
| + }) |
| } |
| // handleEconomics serves the operator unit-economics dashboard (Task 13) — |
diff --git a/internal/console/templates/metrics.html b/internal/console/templates/metrics.html| index b11fcbec6..d03deb523 100644 |
| --- a/internal/console/templates/metrics.html |
| +++ b/internal/console/templates/metrics.html |
| @@ -59,4 +59,26 @@ |
| {{else}} |
| <p>No boxes have published metrics yet.</p> |
| {{end}} |
| +<section aria-labelledby="console-speed"> |
| +<h2 id="console-speed">Console speed</h2> |
| +<p class="small">How long the console took to send the first byte of each page over its last 2,048 requests. Pages should answer within 150 ms.</p> |
| +{{if .ConsoleSpeed}} |
| +<div class="tablewrap"> |
| +<table> |
| + <tr><th>Route</th><th>Requests</th><th>Over 150 ms</th><th>p50</th><th>p95</th><th>S3 requests</th></tr> |
| + {{range .ConsoleSpeed}} |
| + <tr> |
| + <td>{{.Screen}}</td> |
| + <td>{{.Requests}}</td> |
| + <td>{{.Over}}</td> |
| + <td>{{.P50}}</td> |
| + <td>{{.P95}}</td> |
| + <td>{{.S3}}</td> |
| + </tr> |
| + {{end}} |
| +</table> |
| +</div> |
| +{{else}}<p>No requests measured since the console started.</p>{{end}} |
| +<p class="small">The console has made {{.ConsoleS3Background}} S3 requests that no page request caused since it started.</p> |
| +</section> |
| {{template "bottom" .}}{{end}} |