perf(statuspages): page, search and compress public status pages
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / lint (pull_request) Failing after 13m31s
ci / test (pull_request) Successful in 13m30s
ci / build (pull_request) Skipped
ci / image (pull_request) Skipped

A status page with 3128 components was 30 MB of uncompressed HTML: all
components at once, each with 90 bars carrying a tooltip.

- The status page server gzips text responses.
- Status pages list 50 components at a time (?page=N) and offer a search
  (?q=) over component and group names once they have more than one
  page. Group headings keep the status and count of the whole group.
  Single-file exports still list every component.
- Rows linking a detail page draw their bars as one path per status,
  without tooltips; the detail page keeps them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
Sebastian UnterschützandClaude Opus 5.5 committed 2026-11-27 00:10:27 +01:00
1 parent 52d2ce25c9
commit b051f6c430
12 files changed
+4059 -3094

No files matched your search

+15
View File
@@ -21,6 +21,7 @@ import (
"net/http"
"os"
"path/filepath"
"strconv"
"strings"
"sync"
"time"
@@ -331,9 +332,23 @@ func (s *Server) serve(c *gin.Context) {
}
s.localizeRequest(c)
c.Header("Cache-Control", "public, max-age=30")
assets.PageSize = componentsPerPage
if n, err := strconv.Atoi(c.Query("page")); err == nil && n > 1 {
assets.Page = n - 1
}
if q := c.Query("q"); len(q) <= maxComponentQuery {
assets.Query = q
}
web.Render(c, http.StatusOK, web.PublicStatusPage(e.Snap.WithMaintenance(s.now()), assets))
}
// componentsPerPage is how many components a status page lists at a time;
// organizations put thousands on one.
const componentsPerPage = 50
// maxComponentQuery bounds the search for components.
const maxComponentQuery = 100
// serveComponent renders one component's public detail page from the cached
// snapshot when the status page has enabled ShowDetails.
func (s *Server) serveComponent(c *gin.Context, e entry, compID string, assets web.PublicAssets) {
+55
View File
@@ -3,6 +3,7 @@ package statuspage
import (
"context"
"errors"
"fmt"
"log/slog"
"net/http"
"net/http/httptest"
@@ -608,3 +609,57 @@ func TestEventsRefreshPagesAtOnce(t *testing.T) {
t.Errorf("fetches = %d, want 2: one for the event, one for the change during it", calls)
}
}
// Pages with many components list them a page at a time and let visitors
// search them.
func TestComponentPagingAndSearch(t *testing.T) {
core := agentapi.Section{Name: "Core"}
for i := 0; i < 120; i++ {
core.Components = append(core.Components, agentapi.Component{ID: fmt.Sprintf("c%03d", i), Name: fmt.Sprintf("web-%03d", i), Status: agentapi.PageOperational, Days: []agentapi.Day{{Date: "2026-11-26", Uptime: 1}}})
}
edge := agentapi.Section{Name: "Edge"}
for i := 0; i < 10; i++ {
edge.Components = append(edge.Components, agentapi.Component{ID: fmt.Sprintf("e%d", i), Name: fmt.Sprintf("edge-%d", i), Status: agentapi.PageOperational})
}
core.Children = []agentapi.Section{edge}
now := time.Now()
h := newHarness(t, &fakeSource{pages: map[string]agentapi.PageSnapshot{
"|acme": {Title: "Acme status", Status: agentapi.PageOperational, ShowDetails: true, Sections: []agentapi.Section{core}},
}}, t.TempDir(), &now)
tests := []struct {
path string
has, hasNot []string
}{
{"/acme", []string{"web-000", "web-049", "Seite 1 von 3", `href="/acme?page=2"`, `<path d="M0 0h3v22h-3z"`}, []string{"web-050", "edge-0", `rel="prev"`, "<rect"}},
{"/acme?page=2", []string{"web-050", "web-099", "Seite 2 von 3", `href="/acme?page=3"`, `href="/acme"`}, []string{"web-049", "web-100"}},
{"/acme?page=3", []string{"web-119", "edge-9", ">Core<", ">Edge<", ">130<", "Seite 3 von 3"}, []string{"web-099", `rel="next"`}},
{"/acme?page=99", []string{"Seite 3 von 3", "edge-9"}, nil},
{"/acme?page=x", []string{"Seite 1 von 3"}, nil},
{"/acme?q=EDGE-", []string{"edge-0", "edge-9", `value="EDGE-"`, "Alle anzeigen"}, []string{"web-", "Seite 1"}},
{"/acme?q=edge", []string{"edge-0", "edge-9"}, []string{"web-"}},
{"/acme?q=web-11", []string{"web-110", "web-119"}, []string{"web-109", "edge-"}},
{"/acme?q=nothing", []string{"Keine Komponente passt zur Suche."}, []string{"web-", "edge-"}},
}
for _, tt := range tests {
code, body := h.get("status.example.test", tt.path)
if code != http.StatusOK {
t.Errorf("GET %s = %d", tt.path, code)
continue
}
for _, s := range tt.has {
if !strings.Contains(body, s) {
t.Errorf("GET %s lacks %q", tt.path, s)
}
}
for _, s := range tt.hasNot {
if strings.Contains(body, s) {
t.Errorf("GET %s has %q", tt.path, s)
}
}
}
// The detail page keeps the tooltips of the bars.
if _, body := h.get("status.example.test", "/acme/components/c000"); !strings.Contains(body, "<title>2026-11-26") {
t.Errorf("component page lacks the bar tooltips")
}
}