Public: anyone can read this; the crew can change it.

The fleet graph page's Server-Timing names its phases: session, each read, render #3536

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/3500-the-fleet-graph-page-s-server-timing-nam → main 1 commit fork

  • Merged. scout/3500-the-fleet-graph-page-s-server-timing-nam was merged into main as f5a8e5d.

Review

Sign in to review this change.
2 files changed +66 −2
src/web/pages/fleet-graph.ts +9 −2
@@ -14,6 +14,7 @@ import {
1414 readFleetGraph,
1515 type FleetGraph,
1616 } from "../../actions/fleet-graph.ts";
17 import { notePhase, takeSessionTime, timePhase } from "../../core/route_timing.ts";
1718 import type { Ctx } from "../../http/context.ts";
1819 import { signInFirst } from "../chrome.ts";
1920 import {
@@ -32,15 +33,19 @@ function selection(ctx: Ctx) {
3233
3334 /** GET /fleet/graph */
3435 export function fleetGraphPage(ctx: Ctx): Response {
36 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
3537 const user = ctx.auth.user;
3638 if (!user) return signInFirst(ctx);
3739 const asked = selection(ctx);
3840 const graph = asked.ok
39 ? readFleetGraph(ctx.app, user, asked.value)
41 ? timePhase(ctx.request, "graph", () =>
42 readFleetGraph(ctx.app, user, asked.value),
43 )
4044 : undefined;
45 const rendering = performance.now();
4146 const q = graph === undefined ? "" : selectionQuery(graph);
4247 const names = ctx.url.searchParams.getAll("repo").join(" ");
43 return page(
48 const response = page(
4449 {
4550 ctx,
4651 title: "Fleet graph",
@@ -88,6 +93,8 @@ export function fleetGraphPage(ctx: Ctx): Response {
8893 },
8994 graph === undefined ? 422 : 200,
9095 );
96 notePhase(ctx.request, "render", performance.now() - rendering);
97 return response;
9198 }
9299
93100 /** GET /fleet/graph/live — the section alone, for the redraw. */
test/fleet-graph-timing.test.ts added +57
@@ -0,0 +1,57 @@
1 /** `/fleet/graph` names session, graph and render in Server-Timing (#3500). */
2 import { afterAll, beforeAll, expect, test } from "bun:test";
3 import { mkdtempSync, rmSync } from "node:fs";
4 import { tmpdir } from "node:os";
5 import { join } from "node:path";
6 import { createRepo } from "../src/actions/repos.ts";
7 import { createApp, type App } from "../src/app.ts";
8 import { createUser } from "../src/core/users.ts";
9 import { serve, type Servers } from "../src/http/server.ts";
10 import { proveAll } from "./helpers/verified.ts";
11 import { quietLogs } from "./helpers/globals.ts";
12
13 quietLogs();
14
15 let root = "";
16 let app: App;
17 let servers: Servers;
18
19 beforeAll(async () => {
20 root = mkdtempSync(join(tmpdir(), "forge-fleet-graph-timing-"));
21 app = createApp({ dataDir: root, port: 0, forgeRepo: "alice/forge" });
22 const u = await createUser(app.db, {
23 origin: "seed",
24 trusted: true,
25 username: "alice",
26 email: "[email protected]",
27 password: "a-good-passphrase",
28 adminIfFirst: true,
29 });
30 if (!u.ok) throw new Error(u.error);
31 proveAll(app);
32 const made = await createRepo(app, { id: u.value.id, username: "alice" } as never, { name: "forge" });
33 if (!made.ok) throw new Error(made.error);
34 servers = await serve(app);
35 });
36 afterAll(() => {
37 servers.stop();
38 app.close();
39 rmSync(root, { recursive: true, force: true });
40 });
41
42 test("GET /fleet/graph names its phases", async () => {
43 const signin = await fetch(`${servers.url}/signin`, {
44 method: "POST",
45 headers: { origin: servers.url },
46 body: new URLSearchParams({ username: "alice", password: "a-good-passphrase" }),
47 redirect: "manual",
48 });
49 const cookie = (signin.headers.get("set-cookie") ?? "").split(";")[0]!;
50 const res = await fetch(`${servers.url}/fleet/graph`, { headers: { cookie } });
51 const body = await res.text();
52 expect(res.status).toBe(200);
53 expect(body).toContain("<h1>Fleet graph</h1>");
54 const parts = (res.headers.get("server-timing") ?? "").split(", ");
55 for (const name of ["app", "session", "graph", "render"])
56 expect(parts.find((p) => p.startsWith(`${name};`))).toMatch(/^[a-z]+;dur=\d+\.\d$/);
57 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs