carlos / platform Public

console: the registry's db span and the app-host call count have tests of their own

Assemble's registry read is now timed alone under the perf middleware,
so removing its span fails a test (the page test could not tell it from
the gate's console-DB spans). The Running tab test asserts the box call
is counted once on that page's sample. The copy gate's self-test comment
no longer claims an "@path" case it does not have.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev e42436c7f695dae7bbf2a58a5f3039612bfeee12 parent 9c11f55
2 files changed, +47 −2
  • approved_console_perf_copy_test.go +4 −2
  • internal/console/perfwiring_test.go +43 −0
diff --git a/approved_console_perf_copy_test.go b/approved_console_perf_copy_test.go
index 58b958a28..5ab430df5 100644
--- a/approved_console_perf_copy_test.go
+++ b/approved_console_perf_copy_test.go
@@ -83,8 +83,10 @@ func TestConsolePerfCopyBuiltRowsAreApprovedAndPresent(t *testing.T) {
reportAll(t, checkConsolePerfBuilt(mustParseConsolePerfCopyRecord(t), consolePerfCopyBuilt, "."))
}
-// The gate itself: a pending row, a missing row and a repeated entry are
-// refused, and an "@path" entry is checked in that file.
+// The gate itself: text missing from its file, a pending row, an id with
+// no row and a repeated entry are refused. No case here uses "@path": that
+// entry form is the shared entryBuiltRows', tested with the asset cache
+// gate (TestAssetCacheCopyGateChecksTheNamedFile).
func TestConsolePerfCopyGateRefusesWhatItShould(t *testing.T) {
dir := t.TempDir()
if err := os.WriteFile(dir+"/has.html", []byte("<h2>Console speed</h2>\n"), 0o644); err != nil {
diff --git a/internal/console/perfwiring_test.go b/internal/console/perfwiring_test.go
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,