console: the Console speed table's Route cell names the method beside the pattern
Groups split by pattern and method, but the cell showed the pattern only, so a GET and a HEAD of one GET route, or two methods of a method-less route, read the same. The method now goes in front of a pattern that has none and after one registered for another method; a pattern that already starts with it is shown as it is. No new heading, so no new copy.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 files changed,
+70
−3
internal/console/perfspeed.go+21 −1internal/console/perfspeed_test.go+48 −1internal/console/templates/metrics.html+1 −1
diff --git a/internal/console/perfspeed.go b/internal/console/perfspeed.go| index ac62b7d4a..21c72bad8 100644 |
| --- a/internal/console/perfspeed.go |
| +++ b/internal/console/perfspeed.go |
| @@ -3,15 +3,18 @@ package console |
| import ( |
| "fmt" |
| "math" |
| + "strings" |
| "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. |
| +// p50 and p95. S3 is the S3 requests the route's requests made. Route is |
| +// what the table's Route cell shows: the pattern with the method. |
| type consoleSpeedRow struct { |
| Screen, Method string |
| + Route string |
| Requests, Over int |
| S3 int |
| P50, P95 string |
| @@ -26,6 +29,7 @@ func consoleSpeedRows(groups []perf.Group) []consoleSpeedRow { |
| rows = append(rows, consoleSpeedRow{ |
| Screen: g.Screen, |
| Method: g.Method, |
| + Route: consoleSpeedRoute(g.Screen, g.Method), |
| Requests: g.Requests, |
| Over: g.Over, |
| S3: g.Calls["s3"], |
| @@ -40,3 +44,19 @@ func consoleSpeedRows(groups []perf.Group) []consoleSpeedRow { |
| func consoleSpeedMillis(ms float64) string { |
| return fmt.Sprintf("%d ms", int64(math.Round(ms))) |
| } |
| + |
| +// consoleSpeedRoute names a group by its pattern and the requests' method, |
| +// which together are what tell groups apart: a GET pattern also serves |
| +// HEAD, and a method-less pattern serves every method. A pattern that |
| +// starts with the requests' own method is shown as it is; one with no |
| +// method gets the method in front; one registered for another method (a |
| +// HEAD served by a GET pattern) gets the method after it. |
| +func consoleSpeedRoute(screen, method string) string { |
| + if pm, _, ok := strings.Cut(screen, " "); ok && pm != "" && strings.ToUpper(pm) == pm && !strings.ContainsAny(pm, "/.") { |
| + if pm == method { |
| + return screen |
| + } |
| + return screen + " (" + method + ")" |
| + } |
| + return method + " " + screen |
| +} |
diff --git a/internal/console/perfspeed_test.go b/internal/console/perfspeed_test.go| index dfa196511..2f9e22ac0 100644 |
| --- a/internal/console/perfspeed_test.go |
| +++ b/internal/console/perfspeed_test.go |
| @@ -18,7 +18,7 @@ func TestConsoleSpeedRowsFormat(t *testing.T) { |
| 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"} |
| + want := consoleSpeedRow{Screen: "GET /a", Method: "GET", Route: "GET /a", 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) |
| } |
| @@ -27,6 +27,53 @@ func TestConsoleSpeedRowsFormat(t *testing.T) { |
| } |
| } |
| +// The Route cell carries the method beside the pattern, once: GET and |
| +// HEAD on one GET pattern, and a method-less pattern's methods, are |
| +// different rows and must read differently. |
| +func TestConsoleSpeedRouteShowsTheMethod(t *testing.T) { |
| + for _, c := range []struct{ screen, method, want string }{ |
| + {"GET /a/{sqid}/apps/{app}", "GET", "GET /a/{sqid}/apps/{app}"}, |
| + {"GET /a/{sqid}/apps/{app}", "HEAD", "GET /a/{sqid}/apps/{app} (HEAD)"}, |
| + {"POST /a/{sqid}/apps/{app}/promote", "POST", "POST /a/{sqid}/apps/{app}/promote"}, |
| + {"/fleet/architecture", "GET", "GET /fleet/architecture"}, |
| + {"/fleet/architecture", "POST", "POST /fleet/architecture"}, |
| + {"unmatched", "OTHER", "OTHER unmatched"}, |
| + {"GET example.com/x", "GET", "GET example.com/x"}, |
| + {"example.com/x", "GET", "GET example.com/x"}, |
| + } { |
| + if got := consoleSpeedRoute(c.screen, c.method); got != c.want { |
| + t.Errorf("consoleSpeedRoute(%q, %q) = %q, want %q", c.screen, c.method, got, c.want) |
| + } |
| + } |
| +} |
| + |
| +// On the page: a GET and a HEAD of one GET route are two rows that read |
| +// differently, and a method-less route's row names its method. |
| +func TestFleetMetricsSpeedRowsNameTheMethod(t *testing.T) { |
| + fx := newConsoleFixture(t) |
| + c := operatorBrowser(t, fx) |
| + for _, m := range []string{http.MethodGet, http.MethodHead} { |
| + req, _ := http.NewRequest(m, fx.ts.URL+"/fleet/architecture", nil) |
| + resp, err := c.Do(req) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + resp.Body.Close() |
| + } |
| + 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{"<td>GET /fleet/architecture</td>", "<td>HEAD /fleet/architecture</td>"} { |
| + if !strings.Contains(body, want) { |
| + t.Errorf("/fleet/metrics lacks %q", want) |
| + } |
| + } |
| + if strings.Contains(body, "GET GET ") { |
| + t.Errorf("/fleet/metrics doubles a method prefix") |
| + } |
| +} |
| + |
| // 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. |
diff --git a/internal/console/templates/metrics.html b/internal/console/templates/metrics.html| index d03deb523..3ca1b8b2d 100644 |
| --- a/internal/console/templates/metrics.html |
| +++ b/internal/console/templates/metrics.html |
| @@ -68,7 +68,7 @@ |
| <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>{{.Route}}</td> |
| <td>{{.Requests}}</td> |
| <td>{{.Over}}</td> |
| <td>{{.P50}}</td> |