console: spans at the seams (s3 doer, app host, gate db reads, registry); Assemble and Versions take the request context
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
11 files changed,
+235
−50
cmd/console/deploydir_opener_test.go+1 −1cmd/console/main.go+15 −6cmd/console/perfs3_test.go+67 −0internal/console/apiversion.go+1 −1internal/console/instances.go+10 −3internal/console/instances_test.go+9 −9internal/console/perfs3.go+25 −0internal/console/perfwiring_test.go+47 −0internal/console/server.go+41 −12internal/console/view.go+5 −4internal/console/view_test.go+14 −14
CI failed — run details
diff --git a/cmd/console/deploydir_opener_test.go b/cmd/console/deploydir_opener_test.go| index dce627f13..4e6e472a5 100644 |
| --- a/cmd/console/deploydir_opener_test.go |
| +++ b/cmd/console/deploydir_opener_test.go |
| @@ -13,7 +13,7 @@ func TestDeployDirOpenerBumpsScopedKey(t *testing.T) { |
| t.Setenv("CARLOS_DEPLOYMENT_BUCKET", "") |
| t.Setenv("CARLOS_DEPLOYMENT_DIR", t.TempDir()) |
| ctx := context.Background() |
| - s := openStore() |
| + s := openStore(nil) |
| if _, err := s.Put(ctx, "accounts/shop/manifest.json", []byte("{}"), ""); err != nil { |
| t.Fatal(err) |
| } |
diff --git a/cmd/console/main.go b/cmd/console/main.go| index 773114ee3..905c71b8a 100644 |
| --- a/cmd/console/main.go |
| +++ b/cmd/console/main.go |
| @@ -148,6 +148,7 @@ import ( |
| "github.com/carlosframework/platform/internal/mail" |
| "github.com/carlosframework/platform/internal/moves" |
| "github.com/carlosframework/platform/internal/objstore" |
| + "github.com/carlosframework/platform/internal/perf" |
| "github.com/carlosframework/platform/internal/plans" |
| "github.com/carlosframework/platform/internal/provision" |
| "github.com/carlosframework/platform/internal/release" |
| @@ -360,9 +361,13 @@ func serve() { |
| return mail.NewAWSProvisioner(ctx, region, mailBoundary) |
| } |
| mailProvisioner, dnsWriter := mailBackends(mailDep, newMailProvisioner, dnsrec.NewRoute53Writer) |
| + // One request-timing ring for the whole console: the server records |
| + // into it, and the S3 clients below count their calls into it, so a |
| + // page's S3 requests are charged to the page that made them. |
| + rec := new(perf.Recorder) |
| // One release.Store, named, because the senders sweep below needs the |
| // same one the server got. |
| - rel := openStore() |
| + rel := openStore(rec) |
| consoleMail, ensureConsoleMail := consoleMailer(mailDep, rel, mailProvisioner, dnsWriter, mail.NewSESEmailSender, hostClaim) |
| dbBucket, dbRegion, dbPrefix, placement := dbDoorWiring() |
| var dbVersions lease.VersionedStore |
| @@ -389,7 +394,7 @@ func serve() { |
| if sd, err := release.NewS3StoreIn(context.Background(), dbBucket, dbRegion); err != nil { |
| log.Printf("console: seed data store: %v (the seed doors will answer 503)", err) |
| } else { |
| - seedData = sd |
| + seedData = console.TimeS3Store(sd, rec) |
| } |
| } |
| // Before the server exists: every door that seals reads this switch. |
| @@ -517,6 +522,7 @@ func serve() { |
| if cfg.HostClaim { |
| cfg.WakeRetryReset = console.NewProductionWakeRetryReset() |
| } |
| + cfg.Perf = rec |
| srv, err := console.NewServer(cfg, st) |
| if err != nil { |
| log.Fatal(err) |
| @@ -710,18 +716,21 @@ func optionalStore() release.Store { |
| if os.Getenv("CARLOS_DEPLOYMENT_BUCKET") == "" && os.Getenv("CARLOS_DEPLOYMENT_DIR") == "" { |
| return nil |
| } |
| - return openStore() |
| + return openStore(nil) |
| } |
| // openStore mirrors the carlos CLI's ~10-line store-open helper (cli.go); |
| -// duplicated here because cmd/console cannot import package main. |
| -func openStore() release.Store { |
| +// duplicated here because cmd/console cannot import package main. An S3 |
| +// store's HTTP requests are timed and counted into rec (nil counts |
| +// nothing): each in the console request that made it, or in rec's |
| +// background counts. |
| +func openStore(rec *perf.Recorder) release.Store { |
| if b := os.Getenv("CARLOS_DEPLOYMENT_BUCKET"); b != "" { |
| s, err := release.NewDeploymentS3Store(context.Background(), b) |
| if err != nil { |
| log.Fatal(err) |
| } |
| - return s |
| + return console.TimeS3Store(s, rec) |
| } |
| if d := os.Getenv("CARLOS_DEPLOYMENT_DIR"); d != "" { |
| ds := release.NewDirStore(d) |
diff --git a/cmd/console/perfs3_test.go b/cmd/console/perfs3_test.go| new file mode 100644 |
| index 000000000..7a3dca9de |
| --- /dev/null |
| +++ b/cmd/console/perfs3_test.go |
| @@ -0,0 +1,67 @@ |
| +package main |
| + |
| +import ( |
| + "context" |
| + "net/http" |
| + "net/http/httptest" |
| + "strings" |
| + "sync/atomic" |
| + "testing" |
| + |
| + "github.com/carlosframework/platform/internal/perf" |
| +) |
| + |
| +// The store serve() hands the console times and counts every S3 HTTP |
| +// request: in the measured request that made it, or in the background |
| +// counts when no request owns the context. The far end is an in-process |
| +// S3 fake; the store is the real one openStore builds. |
| +func TestOpenStoreTimesS3Requests(t *testing.T) { |
| + var seen atomic.Int64 |
| + s3 := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| + seen.Add(1) |
| + w.Header().Set("Content-Type", "application/xml") |
| + w.WriteHeader(http.StatusNotFound) |
| + _, _ = w.Write([]byte(`<?xml version="1.0" encoding="UTF-8"?>` + |
| + `<Error><Code>NoSuchKey</Code><Message>The specified key does not exist.</Message><Key>k</Key></Error>`)) |
| + })) |
| + defer s3.Close() |
| + t.Setenv("CARLOS_DEPLOYMENT_BUCKET", "b") |
| + t.Setenv("CARLOS_S3_ENDPOINT", s3.URL) |
| + t.Setenv("AWS_ACCESS_KEY_ID", "x") |
| + t.Setenv("AWS_SECRET_ACCESS_KEY", "y") |
| + t.Setenv("AWS_REGION", "us-east-1") |
| + |
| + rec := new(perf.Recorder) |
| + st := openStore(rec) |
| + mux := http.NewServeMux() |
| + mux.HandleFunc("GET /page", func(w http.ResponseWriter, r *http.Request) { |
| + _, _, _ = st.Get(r.Context(), "k") |
| + w.WriteHeader(http.StatusNoContent) |
| + }) |
| + srv := httptest.NewServer(perf.Middleware(rec, perf.Options{})(mux)) |
| + defer srv.Close() |
| + |
| + resp, err := http.Get(srv.URL + "/page") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + resp.Body.Close() |
| + if got := resp.Header.Get("Server-Timing"); !strings.Contains(got, "s3;dur=") { |
| + t.Errorf("Server-Timing = %q, want an s3 span", got) |
| + } |
| + if n := seen.Load(); n != 1 { |
| + t.Errorf("the S3 fake saw %d requests, want 1", n) |
| + } |
| + samples := rec.Snapshot() |
| + if len(samples) != 1 { |
| + t.Fatalf("recorded %d samples, want 1", len(samples)) |
| + } |
| + if got := samples[0].Calls["s3"]; got != 1 { |
| + t.Errorf("sample Calls[s3] = %d, want 1 (calls %v)", got, samples[0].Calls) |
| + } |
| + |
| + _, _, _ = st.Get(context.Background(), "k") |
| + if got := rec.Background()["s3"]; got != 1 { |
| + t.Errorf("Background()[s3] = %d after one unowned Get, want 1", got) |
| + } |
| +} |
diff --git a/internal/console/apiversion.go b/internal/console/apiversion.go| index a511be848..a1147fcde 100644 |
| --- a/internal/console/apiversion.go |
| +++ b/internal/console/apiversion.go |
| @@ -202,7 +202,7 @@ func (s *Server) handleAPIReleasesList(w http.ResponseWriter, r *http.Request) { |
| } |
| ctx, cancel := context.WithTimeout(r.Context(), 15*time.Second) |
| defer cancel() |
| - versions, err := Versions(s.cfg.Releases, acct.Sqid, app) |
| + versions, err := Versions(r.Context(), s.cfg.Releases, acct.Sqid, app) |
| if err != nil { |
| log.Printf("console: api releases list %s/%s: %v", acct.Sqid, app, err) |
| jsonError(w, http.StatusBadGateway, "could not read the releases") |
diff --git a/internal/console/instances.go b/internal/console/instances.go| index 412cfdce7..bf6989223 100644 |
| --- a/internal/console/instances.go |
| +++ b/internal/console/instances.go |
| @@ -13,6 +13,8 @@ import ( |
| "strings" |
| "sync" |
| "time" |
| + |
| + "github.com/carlosframework/platform/internal/perf" |
| ) |
| const ( |
| @@ -52,7 +54,9 @@ type InstanceReport struct { |
| // instanceFetcher polls apps for their reports through their public hosts, |
| // caching per host so page reloads don't drum on tenants. |
| type instanceFetcher struct { |
| - client *http.Client |
| + // client is the app-host client wrapped by perf.TimeDoer: each fetch |
| + // is a "box" span and count on the page that asked. |
| + client perf.Doer |
| scheme string |
| timeout time.Duration |
| @@ -65,7 +69,10 @@ type instanceCacheEntry struct { |
| fetched time.Time |
| } |
| -func newInstanceFetcher(client *http.Client, scheme string) *instanceFetcher { |
| +// newInstanceFetcher builds the fetcher over client (nil is a plain client |
| +// with the fetch timeout). It reads s.perf, so NewServer calls it once that |
| +// is set. |
| +func (s *Server) newInstanceFetcher(client *http.Client, scheme string) *instanceFetcher { |
| if client == nil { |
| client = &http.Client{Timeout: instancesTimeout} |
| } |
| @@ -73,7 +80,7 @@ func newInstanceFetcher(client *http.Client, scheme string) *instanceFetcher { |
| scheme = "https" |
| } |
| return &instanceFetcher{ |
| - client: client, |
| + client: perf.TimeDoer(client, "box", s.perf), |
| scheme: scheme, |
| timeout: instancesTimeout, |
| cache: map[string]instanceCacheEntry{}, |
diff --git a/internal/console/instances_test.go b/internal/console/instances_test.go| index b8780fee2..81d672fe0 100644 |
| --- a/internal/console/instances_test.go |
| +++ b/internal/console/instances_test.go |
| @@ -62,7 +62,7 @@ func readyRoute(host string) RouteView { |
| func TestInstancesFetchAndCache(t *testing.T) { |
| app := newInstanceApp(t, kassReport) |
| - f := newInstanceFetcher(nil, "http") |
| + f := (&Server{}).newInstanceFetcher(nil, "http") |
| rep := f.Report(context.Background(), []RouteView{readyRoute(app.host(t))}) |
| if rep == nil || !rep.Reporting { |
| t.Fatalf("report = %+v, want reporting", rep) |
| @@ -90,21 +90,21 @@ func TestInstancesNotReporting(t *testing.T) { |
| "nonarray": newInstanceApp(t, `{"slug":"x"}`), |
| "oversized": newInstanceApp(t, `[{"slug":"`+strings.Repeat("x", instancesMaxBody)+`"}]`), |
| } { |
| - f := newInstanceFetcher(nil, "http") |
| + f := (&Server{}).newInstanceFetcher(nil, "http") |
| rep := f.Report(context.Background(), []RouteView{readyRoute(app.host(t))}) |
| if rep == nil || rep.Reporting { |
| t.Fatalf("%s: report = %+v, want polled but not reporting", name, rep) |
| } |
| } |
| // A host that isn't even listening: same graceful silence. |
| - f := newInstanceFetcher(nil, "http") |
| + f := (&Server{}).newInstanceFetcher(nil, "http") |
| rep := f.Report(context.Background(), []RouteView{readyRoute("127.0.0.1:1")}) |
| if rep == nil || rep.Reporting { |
| t.Fatalf("dead host: report = %+v, want not reporting", rep) |
| } |
| // And the failure is cached too — no re-poll inside the TTL. |
| app := newInstanceApp(t, "junk") |
| - f2 := newInstanceFetcher(nil, "http") |
| + f2 := (&Server{}).newInstanceFetcher(nil, "http") |
| f2.Report(context.Background(), []RouteView{readyRoute(app.host(t))}) |
| f2.Report(context.Background(), []RouteView{readyRoute(app.host(t))}) |
| if n := app.hits.Load(); n != 1 { |
| @@ -114,7 +114,7 @@ func TestInstancesNotReporting(t *testing.T) { |
| func TestInstancesSlugRequired(t *testing.T) { |
| app := newInstanceApp(t, `[{"slug":"good"},{"status":"ready"},{"slug":" "}]`) |
| - f := newInstanceFetcher(nil, "http") |
| + f := (&Server{}).newInstanceFetcher(nil, "http") |
| rep := f.Report(context.Background(), []RouteView{readyRoute(app.host(t))}) |
| if !rep.Reporting || len(rep.Instances) != 1 || rep.Instances[0].Slug != "good" { |
| t.Fatalf("report = %+v, want only the slugged row", rep) |
| @@ -124,7 +124,7 @@ func TestInstancesSlugRequired(t *testing.T) { |
| func TestInstancesTimeoutDoesNotHang(t *testing.T) { |
| app := newInstanceApp(t, kassReport) |
| app.wait = 500 * time.Millisecond |
| - f := newInstanceFetcher(nil, "http") |
| + f := (&Server{}).newInstanceFetcher(nil, "http") |
| f.timeout = 50 * time.Millisecond |
| start := time.Now() |
| rep := f.Report(context.Background(), []RouteView{readyRoute(app.host(t))}) |
| @@ -138,7 +138,7 @@ func TestInstancesTimeoutDoesNotHang(t *testing.T) { |
| func TestInstancesNeverPollsHibernatableOrStatic(t *testing.T) { |
| app := newInstanceApp(t, kassReport) |
| - f := newInstanceFetcher(nil, "http") |
| + f := (&Server{}).newInstanceFetcher(nil, "http") |
| routes := []RouteView{ |
| {Host: app.host(t), Kind: "instance", Status: "ready", Hibernate: true}, |
| {Host: app.host(t), Kind: "static", Status: "ready"}, |
| @@ -172,7 +172,7 @@ func TestInstancesNeverPollsHibernatableOrStatic(t *testing.T) { |
| func TestInstancesNeverPollsSidecar(t *testing.T) { |
| sidecar := newInstanceApp(t, kassReport) |
| real := newInstanceApp(t, kassReport) |
| - f := newInstanceFetcher(nil, "http") |
| + f := (&Server{}).newInstanceFetcher(nil, "http") |
| routes := []RouteView{ |
| {Host: sidecar.host(t), Kind: "sidecar", Status: "ready"}, |
| readyRoute(real.host(t)), |
| @@ -186,7 +186,7 @@ func TestInstancesNeverPollsSidecar(t *testing.T) { |
| } |
| // A sidecar-only route set: nothing pollable, same as hibernating/static. |
| - f2 := newInstanceFetcher(nil, "http") |
| + f2 := (&Server{}).newInstanceFetcher(nil, "http") |
| if rep := f2.Report(context.Background(), []RouteView{{Host: sidecar.host(t), Kind: "sidecar", Status: "ready"}}); rep != nil { |
| t.Fatalf("report = %+v, want nil — a sidecar-only app has nothing pollable", rep) |
| } |
diff --git a/internal/console/perfs3.go b/internal/console/perfs3.go| new file mode 100644 |
| index 000000000..9c753d039 |
| --- /dev/null |
| +++ b/internal/console/perfs3.go |
| @@ -0,0 +1,25 @@ |
| +package console |
| + |
| +import ( |
| + awss3 "github.com/aws/aws-sdk-go-v2/service/s3" |
| + |
| + "github.com/carlosframework/platform/internal/perf" |
| + "github.com/carlosframework/platform/internal/release" |
| +) |
| + |
| +// TimeS3Store makes every HTTP request s's S3 client sends one "s3" |
| +// span and one count on the console request whose context it carries, |
| +// or one background count in rec when no measured request owns it. |
| +// s is changed in place and returned. |
| +// |
| +// The timing sits on the client's HTTP doer, not around the Store, on |
| +// purpose: callers type-assert the store for optional interfaces |
| +// (release.AppMutationRunner, ModLister, SizeLister, the stamp check in |
| +// release.VersionCandidates), and a wrapper would change those answers. |
| +// Swapping the client changes no method set and sends no request. |
| +func TimeS3Store(s *release.S3Store, rec *perf.Recorder) *release.S3Store { |
| + s.Client = awss3.New(s.Client.Options(), func(o *awss3.Options) { |
| + o.HTTPClient = perf.TimeDoer(o.HTTPClient, "s3", rec) |
| + }) |
| + return s |
| +} |
diff --git a/internal/console/perfwiring_test.go b/internal/console/perfwiring_test.go| index 7492fa0d9..b28f139ab 100644 |
| --- a/internal/console/perfwiring_test.go |
| +++ b/internal/console/perfwiring_test.go |
| @@ -8,6 +8,7 @@ import ( |
| "regexp" |
| "strings" |
| "testing" |
| + "time" |
| "github.com/carlosframework/platform/internal/perf" |
| ) |
| @@ -182,3 +183,49 @@ func TestRenderWriteErrorIsNotSuccess(t *testing.T) { |
| t.Fatal("a delivered page recorded no notice") |
| } |
| } |
| + |
| +// The app page's gate reads the console DB (session, membership, the |
| +// app's claim) and Assemble reads the registry: both are db spans. |
| +func TestServerTimingNamesDBAndRegistry(t *testing.T) { |
| + fx := newConsoleFixture(t) |
| + c := signInPaul(t, fx) |
| + resp, _ := perfGet(t, c, fx.u("/apps/kass")) |
| + if resp.StatusCode != http.StatusOK { |
| + t.Fatalf("GET app page = %d, want 200", resp.StatusCode) |
| + } |
| + if st := resp.Header.Get("Server-Timing"); !strings.Contains(st, "db;dur=") { |
| + t.Errorf("Server-Timing = %q, want a db span", st) |
| + } |
| +} |
| + |
| +// instancesOnlyTransport answers the instance-report contract with an |
| +// empty list, standing in for an app host at the Config.AppClient seam. |
| +type instancesOnlyTransport struct{} |
| + |
| +func (instancesOnlyTransport) RoundTrip(r *http.Request) (*http.Response, error) { |
| + if r.URL.Path != InstancesPath { |
| + return &http.Response{StatusCode: http.StatusNotFound, Body: io.NopCloser(strings.NewReader("")), Request: r}, nil |
| + } |
| + return &http.Response{ |
| + StatusCode: http.StatusOK, |
| + Header: http.Header{"Content-Type": {"application/json"}}, |
| + Body: io.NopCloser(strings.NewReader("[]")), |
| + Request: r, |
| + }, nil |
| +} |
| + |
| +// The Running tab's one call to an app host is a box span. |
| +func TestRunningTabTimesTheAppHost(t *testing.T) { |
| + fx := newConsoleFixture(t) |
| + client := &http.Client{Transport: instancesOnlyTransport{}} |
| + fx.srv.instances = fx.srv.newInstanceFetcher(client, "http") |
| + fx.srv.instances.timeout = 100 * time.Millisecond |
| + c := signInPaul(t, fx) |
| + resp, _ := perfGet(t, c, fx.u("/apps/kass/instances")) |
| + if resp.StatusCode != http.StatusOK { |
| + t.Fatalf("GET instances tab = %d, want 200", resp.StatusCode) |
| + } |
| + if st := resp.Header.Get("Server-Timing"); !strings.Contains(st, "box;dur=") { |
| + t.Errorf("Server-Timing = %q, want a box span", st) |
| + } |
| +} |
diff --git a/internal/console/server.go b/internal/console/server.go| index 904814bf8..9d1d2bf0d 100644 |
| --- a/internal/console/server.go |
| +++ b/internal/console/server.go |
| @@ -1414,7 +1414,6 @@ func NewServer(cfg Config, st *Store) (*Server, error) { |
| store: st, |
| km: km, |
| mux: http.NewServeMux(), |
| - instances: newInstanceFetcher(cfg.AppClient, cfg.AppScheme), |
| secure: strings.HasPrefix(cfg.Origin, "https://"), |
| cli: newCLILimits(), |
| redirects: redirects, |
| @@ -1444,6 +1443,8 @@ func NewServer(cfg Config, st *Store) (*Server, error) { |
| if s.perf == nil { |
| s.perf = &perf.Recorder{} |
| } |
| + // After s.perf: the fetcher counts its app-host calls into it. |
| + s.instances = s.newInstanceFetcher(cfg.AppClient, cfg.AppScheme) |
| // The middleware wraps the mux directly, nothing between them: it reads |
| // the matched route pattern back from the request it handed the mux. |
| // Every test built on NewServer serves through this same chain. |
| @@ -2308,7 +2309,9 @@ func (s *Server) session(r *http.Request) (address, rawToken string, ok bool) { |
| if err != nil || c.Value == "" { |
| return "", "", false |
| } |
| + end := perf.Span(r, "db") |
| addr, ok := s.store.SessionAddress(c.Value, time.Now()) |
| + end() |
| if !ok { |
| return "", "", false |
| } |
| @@ -2493,7 +2496,9 @@ func (s *Server) account(w http.ResponseWriter, r *http.Request) (addr, raw stri |
| http.Redirect(w, r, "/", http.StatusFound) |
| return "", "", nil, "", false |
| } |
| + end := perf.Span(r, "db") |
| accts, err := s.store.AccountsFor(addr) |
| + end() |
| if err != nil { |
| log.Printf("console: account lookup: %v", err) |
| http.NotFound(w, r) |
| @@ -3155,7 +3160,9 @@ func (s *Server) operatorOnly(w http.ResponseWriter, r *http.Request) (address, |
| http.NotFound(w, r) |
| return "", "", false |
| } |
| + end := perf.Span(r, "db") |
| isOp, err := s.store.IsOperator(addr) |
| + end() |
| if err != nil { |
| log.Printf("console: IsOperator %s: %v", addr, err) |
| http.NotFound(w, r) |
| @@ -3318,7 +3325,7 @@ func (s *Server) handleAccountHome(w http.ResponseWriter, r *http.Request) { |
| return |
| } |
| if len(apps) > 0 { |
| - views, err := Assemble(s.cfg.Registry, s.cfg.Releases, s.cfg.ReleasePub, acct.Sqid, apps, s.dnsTargets()) |
| + views, err := Assemble(r.Context(), s.cfg.Registry, s.cfg.Releases, s.cfg.ReleasePub, acct.Sqid, apps, s.dnsTargets()) |
| if err != nil { |
| log.Printf("console: assemble: %v", err) |
| s.renderMessage(w, r, http.StatusInternalServerError, "Error", "Could not read platform state. Please try again.") |
| @@ -3411,16 +3418,21 @@ func (s *Server) handleAccountSettings(w http.ResponseWriter, r *http.Request) { |
| // switcher, the base URL its forms post to, the viewer's role — and records |
| // the MRU, so signing in lands you back on the account you were last in. |
| func (s *Server) accountPage(w http.ResponseWriter, r *http.Request, addr, raw string, acct *Account, role string) page { |
| + end := perf.Span(r, "db") |
| if err := s.store.SetLastAccount(addr, acct.ID); err != nil { |
| log.Printf("console: set last account: %v", err) |
| } |
| + end() |
| p := page{ |
| Address: addr, CSRF: raw, |
| Account: acct, Role: role, Base: "/a/" + url.PathEscape(acct.Sqid), |
| CanPromote: s.cfg.Key != nil, |
| } |
| p.Flash, p.FlashErr = s.takeFlash(w, r) |
| - if accts, err := s.store.AccountsFor(addr); err != nil { |
| + end = perf.Span(r, "db") |
| + accts, err := s.store.AccountsFor(addr) |
| + end() |
| + if err != nil { |
| log.Printf("console: switcher: %v", err) |
| } else { |
| p.Accounts = accts |
| @@ -3451,7 +3463,9 @@ func (s *Server) accountApp(w http.ResponseWriter, r *http.Request) (addr, raw s |
| return "", "", nil, "", "", false |
| } |
| app = r.PathValue("app") |
| + end := perf.Span(r, "db") |
| has, err := s.store.HasAppIn(acct.ID, app) |
| + end() |
| if err != nil { |
| s.renderMessage(w, r, http.StatusInternalServerError, "Error", "Could not read your apps. Please try again.") |
| return "", "", nil, "", "", false |
| @@ -3474,7 +3488,7 @@ func (s *Server) appPage(w http.ResponseWriter, r *http.Request, tab string) (pa |
| // bucket hiccup there is deliberately non-fatal, and this is where it gets |
| // another chance. Best-effort — a page view never fails on it. |
| s.ensureAccountManifest(r.Context(), acct) |
| - views, err := Assemble(s.cfg.Registry, s.cfg.Releases, s.cfg.ReleasePub, acct.Sqid, []string{app}, s.dnsTargets()) |
| + views, err := Assemble(r.Context(), s.cfg.Registry, s.cfg.Releases, s.cfg.ReleasePub, acct.Sqid, []string{app}, s.dnsTargets()) |
| if err != nil || len(views) != 1 { |
| log.Printf("console: assemble %s: %v", app, err) |
| s.renderMessage(w, r, http.StatusInternalServerError, "Error", "Could not read platform state. Please try again.") |
| @@ -3486,7 +3500,10 @@ func (s *Server) appPage(w http.ResponseWriter, r *http.Request, tab string) (pa |
| p.ActiveTab = tab |
| p.ActiveNav = "apps" |
| p.Detail = &views[0] |
| - if life, err := s.store.AppLife(acct.ID, app); err != nil { |
| + end := perf.Span(r, "db") |
| + life, err := s.store.AppLife(acct.ID, app) |
| + end() |
| + if err != nil { |
| log.Printf("console: app lifecycle %s/%s: %v", acct.Sqid, app, err) |
| } else if life != nil && life.Temporary() { |
| p.ExpiresAt = time.Unix(life.ExpiresAt, 0).UTC() |
| @@ -3610,7 +3627,7 @@ func (s *Server) handleApp(w http.ResponseWriter, r *http.Request) { |
| return |
| } |
| app := p.Detail.App |
| - versions, err := Versions(s.cfg.Releases, acct.Sqid, app) |
| + versions, err := Versions(r.Context(), s.cfg.Releases, acct.Sqid, app) |
| if err != nil { |
| log.Printf("console: versions %s: %v", app, err) |
| p.FlashErr = "Could not list this app's releases." |
| @@ -3633,12 +3650,18 @@ func (s *Server) handleApp(w http.ResponseWriter, r *http.Request) { |
| latest, latestAt = versions[0].Version, versions[0].BuiltAt |
| } |
| p.Flow = assembleFlow(p.Detail, p.InstanceRows, latest, latestAt, p.Nav+"/apps/"+p.AppName+"/instances") |
| - if events, err := s.store.Events(acct.ID, app, overviewActivityCap); err != nil { |
| + end := perf.Span(r, "db") |
| + events, err := s.store.Events(acct.ID, app, overviewActivityCap) |
| + end() |
| + if err != nil { |
| log.Printf("console: events %s: %v", app, err) |
| } else { |
| p.Events = events |
| } |
| - if pcs, err := s.store.PendingChangesForContext(r.Context(), acct.ID, app, time.Now()); err != nil { |
| + end = perf.Span(r, "db") |
| + pcs, err := s.store.PendingChangesForContext(r.Context(), acct.ID, app, time.Now()) |
| + end() |
| + if err != nil { |
| log.Printf("console: pending changes %s/%s: %v", acct.Sqid, app, err) |
| } else if len(pcs) > 0 { |
| // One pipeline read for the whole card: the rows show the quorum |
| @@ -3661,7 +3684,10 @@ func (s *Server) handleAppReleases(w http.ResponseWriter, r *http.Request) { |
| } |
| if strings.HasSuffix(r.URL.Path, "/deployments") { |
| p.DeploymentTargets = assembleDeploymentTargets(p.Detail, acct.Sqid) |
| - if pcs, err := s.store.PendingChangesForContext(r.Context(), acct.ID, p.AppName, time.Now()); err != nil { |
| + end := perf.Span(r, "db") |
| + pcs, err := s.store.PendingChangesForContext(r.Context(), acct.ID, p.AppName, time.Now()) |
| + end() |
| + if err != nil { |
| log.Printf("console: pending changes %s/%s: %v", acct.Sqid, p.AppName, err) |
| } else if len(pcs) > 0 { |
| p.Pending = s.pendingChangeViews(pcs, s.pendingPipeline(r.Context(), acct, p.AppName)) |
| @@ -3671,7 +3697,7 @@ func (s *Server) handleAppReleases(w http.ResponseWriter, r *http.Request) { |
| } |
| p.ReleaseSummary = assembleReleaseSummary(p.Detail.Channels, p.Detail.Routes, acct.Sqid) |
| p.PromoteChannels = promoteChannelOptions(p.Detail.Channels, p.Detail.Pipeline) |
| - versions, err := Versions(s.cfg.Releases, acct.Sqid, p.AppName) |
| + versions, err := Versions(r.Context(), s.cfg.Releases, acct.Sqid, p.AppName) |
| if err != nil { |
| log.Printf("console: versions %s: %v", p.AppName, err) |
| p.FlashErr = "Could not list this app's releases." |
| @@ -3689,7 +3715,7 @@ func (s *Server) handleAppReleases(w http.ResponseWriter, r *http.Request) { |
| // Assemble's already-built ChannelView rows since assembleChannels |
| // itself leaves Tag "". A failed read degrades this tab's tag |
| // decoration only; the page still renders. |
| - if tags, terr := release.ListTags(context.Background(), s.cfg.Releases, acct.Sqid, p.AppName); terr != nil { |
| + if tags, terr := release.ListTags(r.Context(), s.cfg.Releases, acct.Sqid, p.AppName); terr != nil { |
| log.Printf("console: tags %s: %v", p.AppName, terr) |
| } else { |
| byRelease := tagIndex(tags) |
| @@ -4015,7 +4041,10 @@ func (s *Server) handleAppActivity(w http.ResponseWriter, r *http.Request) { |
| return |
| } |
| p.ActivityCopy = activityText |
| - if events, err := s.store.Events(acct.ID, p.AppName, activityCap); err != nil { |
| + end := perf.Span(r, "db") |
| + events, err := s.store.Events(acct.ID, p.AppName, activityCap) |
| + end() |
| + if err != nil { |
| log.Printf("console: events %s: %v", p.AppName, err) |
| } else { |
| // Only link targets this account's assembled view proves still exist. |
diff --git a/internal/console/view.go b/internal/console/view.go| index 47b09e3f4..d8ce57c37 100644 |
| --- a/internal/console/view.go |
| +++ b/internal/console/view.go |
| @@ -19,6 +19,7 @@ import ( |
| "golang.org/x/net/publicsuffix" |
| + "github.com/carlosframework/platform/internal/perf" |
| "github.com/carlosframework/platform/internal/registry" |
| "github.com/carlosframework/platform/internal/release" |
| "github.com/carlosframework/platform/internal/status" |
| @@ -549,13 +550,14 @@ func openRegistry(path string) (consoleRegistry, error) { |
| // edge addresses nor a steering hostname known). Every app in apps gets an |
| // AppView, even an empty one; per-channel failures degrade to |
| // ChannelView.Err. |
| -func Assemble(regPath string, s release.Store, pub ed25519.PublicKey, acct string, apps []string, dns DNSTargets) ([]AppView, error) { |
| - ctx := context.Background() |
| +func Assemble(ctx context.Context, regPath string, s release.Store, pub ed25519.PublicKey, acct string, apps []string, dns DNSTargets) ([]AppView, error) { |
| reg, err := openRegistry(regPath) |
| if err != nil { |
| return nil, err |
| } |
| + endDB := perf.SpanContext(ctx, "db") |
| routes, err := reg.List() |
| + endDB() |
| if err != nil { |
| return nil, err |
| } |
| @@ -938,8 +940,7 @@ const tagsCap = 20 |
| // survivors — fetch-then-sort made this page O(every version ever shipped) |
| // in sequential bucket GETs, ~8s at tito's 318. A plain Store (test fakes |
| // only) still yields every version, fetched and sorted exactly as before. |
| -func Versions(s release.Store, acct, app string) ([]VersionView, error) { |
| - ctx := context.Background() |
| +func Versions(ctx context.Context, s release.Store, acct, app string) ([]VersionView, error) { |
| cands, _, err := release.VersionCandidates(ctx, s, acct, app, versionsCap) |
| if err != nil { |
| return nil, err |
diff --git a/internal/console/view_test.go b/internal/console/view_test.go| index 06833ce5d..3e1d3de90 100644 |
| --- a/internal/console/view_test.go |
| +++ b/internal/console/view_test.go |
| @@ -179,7 +179,7 @@ func TestAssemble(t *testing.T) { |
| if err := release.SetProduction(context.Background(), store, priv, release.OpsAccount, "kass", true, "test"); err != nil { |
| t.Fatal(err) |
| } |
| - views, err := Assemble(regPath, store, pub, release.OpsAccount, []string{"kass"}, DNSTargets{}) |
| + views, err := Assemble(context.Background(), regPath, store, pub, release.OpsAccount, []string{"kass"}, DNSTargets{}) |
| if err != nil { |
| t.Fatal(err) |
| } |
| @@ -235,7 +235,7 @@ func TestAssembleCanaries(t *testing.T) { |
| Status: "ready", App: "kass", Channel: "canary/x", Canary: true}); err != nil { |
| t.Fatal(err) |
| } |
| - views, err := Assemble(regPath, store, pub, release.OpsAccount, []string{"kass"}, DNSTargets{}) |
| + views, err := Assemble(context.Background(), regPath, store, pub, release.OpsAccount, []string{"kass"}, DNSTargets{}) |
| if err != nil { |
| t.Fatal(err) |
| } |
| @@ -257,7 +257,7 @@ func TestAssembleCanaries(t *testing.T) { |
| func TestAssembleFiltersToGivenApps(t *testing.T) { |
| regPath, store, _, pub := buildFixtures(t) |
| - views, err := Assemble(regPath, store, pub, release.OpsAccount, []string{"kass"}, DNSTargets{}) |
| + views, err := Assemble(context.Background(), regPath, store, pub, release.OpsAccount, []string{"kass"}, DNSTargets{}) |
| if err != nil { |
| t.Fatal(err) |
| } |
| @@ -275,7 +275,7 @@ func TestAssembleFiltersToGivenApps(t *testing.T) { |
| func TestAssembleEmptyAppStillListed(t *testing.T) { |
| regPath, store, _, pub := buildFixtures(t) |
| - views, err := Assemble(regPath, store, pub, release.OpsAccount, []string{"ghost", "kass"}, DNSTargets{}) |
| + views, err := Assemble(context.Background(), regPath, store, pub, release.OpsAccount, []string{"ghost", "kass"}, DNSTargets{}) |
| if err != nil { |
| t.Fatal(err) |
| } |
| @@ -293,7 +293,7 @@ func TestAssembleDegradesBadChannel(t *testing.T) { |
| if _, err := store.Put(context.Background(), release.ChannelKey(release.OpsAccount, "kass", "beta"), []byte("not a signed pointer"), ""); err != nil { |
| t.Fatal(err) |
| } |
| - views, err := Assemble(regPath, store, pub, release.OpsAccount, []string{"kass"}, DNSTargets{}) |
| + views, err := Assemble(context.Background(), regPath, store, pub, release.OpsAccount, []string{"kass"}, DNSTargets{}) |
| if err != nil { |
| t.Fatalf("Assemble must not fail on a bad channel: %v", err) |
| } |
| @@ -322,7 +322,7 @@ func TestAssembleCarriesProcessOwnership(t *testing.T) { |
| Unit: "titogo@demo.service", Backing: registry.BackingUnit, Provisioned: true}); err != nil { |
| t.Fatal(err) |
| } |
| - views, err := Assemble(regPath, store, pub, release.OpsAccount, []string{"kass"}, DNSTargets{}) |
| + views, err := Assemble(context.Background(), regPath, store, pub, release.OpsAccount, []string{"kass"}, DNSTargets{}) |
| if err != nil { |
| t.Fatal(err) |
| } |
| @@ -365,7 +365,7 @@ func TestMismatchListsRoutes(t *testing.T) { |
| t.Fatal(err) |
| } |
| } |
| - views, err := Assemble(regPath, store, pub, release.OpsAccount, []string{"mismatchlist"}, DNSTargets{}) |
| + views, err := Assemble(context.Background(), regPath, store, pub, release.OpsAccount, []string{"mismatchlist"}, DNSTargets{}) |
| if err != nil { |
| t.Fatal(err) |
| } |
| @@ -402,7 +402,7 @@ func TestMismatchAllRoutes(t *testing.T) { |
| t.Fatal(err) |
| } |
| } |
| - views, err := Assemble(regPath, store, pub, release.OpsAccount, []string{"mismatchall"}, DNSTargets{}) |
| + views, err := Assemble(context.Background(), regPath, store, pub, release.OpsAccount, []string{"mismatchall"}, DNSTargets{}) |
| if err != nil { |
| t.Fatal(err) |
| } |
| @@ -432,7 +432,7 @@ func TestMismatchIgnoresPlatformRoutes(t *testing.T) { |
| t.Fatal(err) |
| } |
| } |
| - views, err := Assemble(regPath, store, pub, release.OpsAccount, []string{"mismatchplatform"}, DNSTargets{}) |
| + views, err := Assemble(context.Background(), regPath, store, pub, release.OpsAccount, []string{"mismatchplatform"}, DNSTargets{}) |
| if err != nil { |
| t.Fatal(err) |
| } |
| @@ -450,7 +450,7 @@ func TestMismatchIgnoresPlatformRoutes(t *testing.T) { |
| func TestVersionsNewestFirst(t *testing.T) { |
| _, store, _, _ := buildFixtures(t) |
| - vs, err := Versions(store, release.OpsAccount, "kass") |
| + vs, err := Versions(context.Background(), store, release.OpsAccount, "kass") |
| if err != nil { |
| t.Fatal(err) |
| } |
| @@ -470,7 +470,7 @@ func TestVersionsDegradesBadManifest(t *testing.T) { |
| if _, err := store.Put(context.Background(), release.ManifestKey(release.OpsAccount, "kass", "v3"), []byte("junk"), ""); err != nil { |
| t.Fatal(err) |
| } |
| - vs, err := Versions(store, release.OpsAccount, "kass") |
| + vs, err := Versions(context.Background(), store, release.OpsAccount, "kass") |
| if err != nil { |
| t.Fatalf("Versions must not fail on one bad manifest: %v", err) |
| } |
| @@ -544,7 +544,7 @@ func TestVersionsBoundsManifestReads(t *testing.T) { |
| shipAt(t, store, dir, fmt.Sprintf("v%02d", i), base.Add(time.Duration(shipped-i)*time.Minute)) |
| } |
| store.gets = 0 // Ship reads during setup don't count |
| - vs, err := Versions(store, release.OpsAccount, "kass") |
| + vs, err := Versions(context.Background(), store, release.OpsAccount, "kass") |
| if err != nil { |
| t.Fatal(err) |
| } |
| @@ -586,7 +586,7 @@ func TestVersionsRankedPathDegrades(t *testing.T) { |
| if _, err := store.Put(ctx, release.ArtifactKey(release.OpsAccount, "kass", "dead1", "kass"), []byte("bin"), ""); err != nil { |
| t.Fatal(err) |
| } |
| - vs, err := Versions(store, release.OpsAccount, "kass") |
| + vs, err := Versions(context.Background(), store, release.OpsAccount, "kass") |
| if err != nil { |
| t.Fatalf("Versions must not fail on bad rows: %v", err) |
| } |
| @@ -606,7 +606,7 @@ func TestVersionsRankedPathDegrades(t *testing.T) { |
| func TestVersionsEmptyApp(t *testing.T) { |
| _, store, _, _ := buildFixtures(t) |
| - vs, err := Versions(store, release.OpsAccount, "ghost") |
| + vs, err := Versions(context.Background(), store, release.OpsAccount, "ghost") |
| if err != nil || len(vs) != 0 { |
| t.Fatalf("Versions(ghost) = %+v %v, want empty nil", vs, err) |
| } |