console: account settings reads the account telemetry key only
handleAccountSettings resolved telemetry with an empty app name, which read apps/<sqid>//telemetry.json, a key nothing writes (the s3fake refuses it, so the two account telemetry forms did not render in the fixture). It now reads the account key the two account forms write and folds it over the defaults: 3 S3 calls become 2.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 files changed,
+70
−9
internal/console/perfquickwins_test.go+59 −0internal/console/server.go+10 −8internal/console/testdata/perf-budgets.txt+1 −1
CI failed — run details
diff --git a/internal/console/perfquickwins_test.go b/internal/console/perfquickwins_test.go| index 028e91967..a08a77e3d 100644 |
| --- a/internal/console/perfquickwins_test.go |
| +++ b/internal/console/perfquickwins_test.go |
| @@ -5,6 +5,7 @@ import ( |
| "errors" |
| "net/http" |
| "net/http/httptest" |
| + "net/url" |
| "slices" |
| "strings" |
| "sync" |
| @@ -570,3 +571,61 @@ func TestAppDeployEmptyAsksForOneKey(t *testing.T) { |
| }) |
| } |
| } |
| + |
| +// TestAccountSettingsReadsNoAppTelemetryKey: the account settings page asks |
| +// for the account's telemetry object and for no app-level key (an empty app |
| +// name makes a key with "//" in it, which nothing writes). |
| +func TestAccountSettingsReadsNoAppTelemetryKey(t *testing.T) { |
| + fx, lat := newPerfFixture(t) |
| + c := signInPaul(t, fx) |
| + if status, _, body := get(t, c, fx.u("/settings")); status != http.StatusOK { |
| + t.Fatalf("settings = %d:\n%s", status, body) |
| + } |
| + rec := recordS3(lat, nil) |
| + status, _, body := get(t, c, fx.u("/settings")) |
| + if status != http.StatusOK { |
| + t.Fatalf("settings = %d:\n%s", status, body) |
| + } |
| + for _, q := range rec.all() { |
| + if strings.Contains(q.Key, "//") || strings.Contains(q.Prefix, "//") { |
| + t.Errorf("account settings requested %+v, an app-level key with no app", q) |
| + } |
| + } |
| + if n := rec.touching("accounts/" + fx.sqid + "/telemetry.json"); n != 1 { |
| + t.Errorf("account telemetry requested %d times, want 1 (requests: %v)", n, rec.all()) |
| + } |
| + for _, w := range []string{`action="`, "/errors/level", "/analytics/setting"} { |
| + if !strings.Contains(body, w) { |
| + t.Errorf("account settings lacks %q", w) |
| + } |
| + } |
| +} |
| + |
| +// TestAccountSettingsShowsAccountLevel: an Errors level and an analytics |
| +// setting saved through the real account doors show on the account page, |
| +// said to come from the account. |
| +func TestAccountSettingsShowsAccountLevel(t *testing.T) { |
| + fx, _ := newPerfFixture(t) |
| + c := signInPaul(t, fx) |
| + csrf := sessionToken(t, fx, c) |
| + if status, _, body := postForm(t, c, fx.u("/errors/level"), url.Values{"csrf": {csrf}, "level": {"warn"}}); status != http.StatusSeeOther { |
| + t.Fatalf("errors level = %d:\n%s", status, body) |
| + } |
| + if status, _, body := postForm(t, c, fx.u("/analytics/setting"), url.Values{"csrf": {csrf}, "count": {"edge"}}); status != http.StatusSeeOther { |
| + t.Fatalf("analytics setting = %d:\n%s", status, body) |
| + } |
| + status, _, body := get(t, c, fx.u("/settings")) |
| + if status != http.StatusOK { |
| + t.Fatalf("settings = %d:\n%s", status, body) |
| + } |
| + for _, w := range []string{ |
| + `<option value="warn" selected>`, |
| + "Currently warn, from the account", |
| + `<option value="edge" selected>`, |
| + "Currently edge, from the account", |
| + } { |
| + if !strings.Contains(body, w) { |
| + t.Errorf("account settings lacks %q:\n%s", w, body) |
| + } |
| + } |
| +} |
diff --git a/internal/console/server.go b/internal/console/server.go| index 9f71b3cec..2dacb22d9 100644 |
| --- a/internal/console/server.go |
| +++ b/internal/console/server.go |
| @@ -3521,17 +3521,19 @@ func (s *Server) handleAccountSettings(w http.ResponseWriter, r *http.Request) { |
| if role == RoleOwner { |
| s.servicePane(&p, acct) |
| } |
| - // The account's own Errors log level. Resolved with an EMPTY app name on |
| - // purpose: AppKey(sqid, "") names a key no app ever writes, so the app |
| - // layer contributes nothing and what comes back is the account setting |
| - // or the default — which is exactly what this page sets. A failed read |
| - // is said rather than defaulted (see ErrLevelUnread), and never fails |
| - // the page. |
| - if res, err := telemetry.Resolve(r.Context(), s.cfg.Releases, acct.Sqid, ""); err != nil { |
| + // The account's own Errors log level: the account's telemetry object, |
| + // the key the two account forms write, folded over the defaults. No app |
| + // layer is read (an empty app name would name apps/<sqid>//telemetry.json, |
| + // which nothing writes). A failed read is said rather than defaulted (see |
| + // ErrLevelUnread), and never fails the page. A bucketless console folds |
| + // the defaults, as telemetry.Resolve does. |
| + if s.cfg.Releases == nil { |
| + p.ErrLevelSetting = telemetry.Fold(telemetry.Settings{}, telemetry.Settings{}) |
| + } else if st, _, err := telemetry.Read(r.Context(), s.cfg.Releases, telemetry.AccountKey(acct.Sqid)); err != nil { |
| log.Printf("console: account telemetry %s: %v", acct.Sqid, err) |
| p.ErrLevelUnread = true |
| } else { |
| - p.ErrLevelSetting = res |
| + p.ErrLevelSetting = telemetry.Fold(st, telemetry.Settings{}) |
| } |
| // The analytics switch is the OTHER half of that same resolved object — |
| // one settings file, one read — under the name its own section uses. |
diff --git a/internal/console/testdata/perf-budgets.txt b/internal/console/testdata/perf-budgets.txt| index ae47c4dcf..a556f17e5 100644 |
| --- a/internal/console/testdata/perf-budgets.txt |
| +++ b/internal/console/testdata/perf-budgets.txt |
| @@ -53,7 +53,7 @@ GET /a/{sqid}/apps/{app}/settings/{section} over: Domains still reads the domain |
| GET /a/{sqid}/fleet over: reads status/fleet.json and lists and reads each customer fleet's box reports (3 S3 calls warm) |
| GET /a/{sqid}/fleets/{fleet} over: lists and reads the fleet's box reports (2 S3 calls warm) |
| GET /a/{sqid}/plan/keep over: the lapse inventory lists every app's instance records and reads each one, lists every app's sidecar records, and lists the domain claims (8 S3 calls warm for two apps and three instances, median 209 ms; it grows with the account) |
| -GET /a/{sqid}/settings over: reads the account and app telemetry settings and the storage entitlement (3 S3 calls warm) |
| +GET /a/{sqid}/settings calls 2: the account telemetry settings and the storage entitlement |
| GET /a/{sqid}/{$} over: a warm view reads nothing (each app's frame is cached); a cold view reads every app's frame (6 S3 calls per app, about 160 ms for one) |
| GET /a/{sqid}/trash over: reads each trashed app's deleted.json marker (1 S3 call warm per app) |
| GET /fleet over: lists and reads every box report, reads status/fleet.json, and lists and reads the storage entitlements (8 S3 calls warm) |