| index b8704d40a..ecd9870c4 100644 |
| --- a/internal/console/perfwiring_test.go |
| +++ b/internal/console/perfwiring_test.go |
| @@ -6,6 +6,7 @@ import ( |
| "errors" |
| "io" |
| "log" |
| + "log/slog" |
| "net/http" |
| "net/http/httptest" |
| "regexp" |
| @@ -203,6 +204,34 @@ func TestServerTimingNamesDBAndRegistry(t *testing.T) { |
| } |
| } |
| |
| +// The registry read in Assemble is a db span of its own. The page test |
| +// above cannot tell it from the gate's console-DB spans, so this one runs |
| +// Assemble alone, on the fixture's own registry and store, under the perf |
| +// middleware: the only db time the sample can carry is the registry's. |
| +func TestAssembleTimesTheRegistryRead(t *testing.T) { |
| + fx := newConsoleFixture(t) |
| + var rec perf.Recorder |
| + mux := http.NewServeMux() |
| + mux.HandleFunc("GET /assemble", func(w http.ResponseWriter, r *http.Request) { |
| + if _, err := Assemble(r.Context(), fx.srv.cfg.Registry, fx.srv.cfg.Releases, fx.srv.cfg.ReleasePub, release.OpsAccount, []string{"kass"}, DNSTargets{}); err != nil { |
| + t.Errorf("Assemble: %v", err) |
| + } |
| + }) |
| + quiet := slog.New(slog.NewTextHandler(io.Discard, nil)) |
| + w := httptest.NewRecorder() |
| + perf.Middleware(&rec, perf.Options{Logger: quiet})(mux).ServeHTTP(w, httptest.NewRequest(http.MethodGet, "/assemble", nil)) |
| + ss := rec.Snapshot() |
| + if len(ss) != 1 { |
| + t.Fatalf("samples = %d, want 1", len(ss)) |
| + } |
| + if _, ok := ss[0].Spans["db"]; !ok { |
| + t.Errorf("spans = %v, want a db span for the registry read", ss[0].Spans) |
| + } |
| + if st := w.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{} |
| @@ -233,6 +262,20 @@ func TestRunningTabTimesTheAppHost(t *testing.T) { |
| if st := resp.Header.Get("Server-Timing"); !strings.Contains(st, "box;dur=") { |
| t.Errorf("Server-Timing = %q, want a box span", st) |
| } |
| + // And the call is counted on that page's own sample, once. |
| + var found bool |
| + for _, smp := range fx.srv.perf.Snapshot() { |
| + if smp.Screen != "GET /a/{sqid}/apps/{app}/instances" { |
| + continue |
| + } |
| + found = true |
| + if smp.Calls["box"] != 1 { |
| + t.Errorf("instances tab calls = %v, want box 1", smp.Calls) |
| + } |
| + } |
| + if !found { |
| + t.Errorf("no sample for the instances tab in %+v", fx.srv.perf.Snapshot()) |
| + } |
| } |
| |
| // slowGetStore is a release store whose Get takes 160 ms once slow is set, |