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

+22
View File
@@ -192,6 +192,28 @@ templ bars(bs []Bar, height int) {
</svg>
}
// pathBars draws bars like bars, in a few paths and without tooltips.
templ pathBars(bs []Bar, height int) {
<svg
viewBox={ "0 0 " + strconv.Itoa(len(bs)*4) + " " + strconv.Itoa(height) }
preserveAspectRatio="none"
class="block w-full"
style={ "height:" + strconv.Itoa(height) + "px" }
role="img"
aria-label={ i18n.T(ctx, "monitors.uptime_chart") }
>
for _, p := range BarPaths(bs, height) {
<path
d={ p.D }
class={ templ.KV("fill-up", p.Status == StatusUp),
templ.KV("fill-degraded", p.Status == StatusDegraded),
templ.KV("fill-down", p.Status == StatusDown),
templ.KV("fill-rule", p.Status == StatusUnknown) }
></path>
}
</svg>
}
templ Dashboard(p Page, me Me, v DashboardView) {
@consoleShell(p, me) {
<div class="mb-6 flex flex-wrap items-center justify-between gap-x-4 gap-y-3">
File diff suppressed because it is too large. Load diff
+151
View File
@@ -3,6 +3,7 @@ package web
import (
"fmt"
"io/fs"
"net/url"
"strconv"
"strings"
"time"
@@ -30,6 +31,156 @@ type PublicAssets struct {
Now time.Time
// NoRefresh leaves out the periodic reload, on pages with a form.
NoRefresh bool
// PageSize is how many components the page lists at a time; 0 lists
// all, as in a single-file export.
PageSize int
// Page is the zero-based page of components to show and Query what the
// visitor searched them for.
Page int
Query string
}
// ComponentPage is the part of a status page's components one page of it
// lists: the sections holding them, keeping the status and count of the
// whole section.
type ComponentPage struct {
Sections []agentapi.Section
// Page is the zero-based page shown, of Pages; Matches counts the
// components the query found, of all of them.
Page, Pages int
Matches int
Query string
}
// PageComponents picks the components of page from sections, of those whose
// name or section contains query. size 0 shows all of them.
func PageComponents(sections []agentapi.Section, page, size int, query string) ComponentPage {
query = strings.TrimSpace(query)
needle := strings.ToLower(query)
match := func(path []string, c agentapi.Component) bool {
if needle == "" || strings.Contains(strings.ToLower(c.Name), needle) {
return true
}
for _, p := range path {
if strings.Contains(strings.ToLower(p), needle) {
return true
}
}
return false
}
// Components are counted in the order the page renders them: a
// section's own, then its children's. Unnamed sections are top-level
// lists without children.
var count func(sec agentapi.Section, path []string) int
count = func(sec agentapi.Section, path []string) int {
if sec.Name != "" {
path = append(path, sec.Name)
}
n := 0
for _, c := range sec.Components {
if match(path, c) {
n++
}
}
if sec.Name != "" {
for _, child := range sec.Children {
n += count(child, path)
}
}
return n
}
total := 0
for _, sec := range sections {
total += count(sec, nil)
}
out := ComponentPage{Pages: 1, Matches: total, Query: query}
if needle == "" && (size <= 0 || total <= size) {
out.Sections = sections
return out
}
from, to := 0, total
if size > 0 && total > size {
out.Pages = (total + size - 1) / size
out.Page = min(max(page, 0), out.Pages-1)
from, to = out.Page*size, min((out.Page+1)*size, total)
}
idx := 0
var cut func(sec agentapi.Section, path []string) (agentapi.Section, bool)
cut = func(sec agentapi.Section, path []string) (agentapi.Section, bool) {
part := agentapi.Section{Name: sec.Name, Status: secStatusName(sec), Total: SectionTotal(sec)}
if sec.Name != "" {
path = append(path, sec.Name)
}
for _, c := range sec.Components {
if !match(path, c) {
continue
}
if idx >= from && idx < to {
part.Components = append(part.Components, c)
}
idx++
}
if sec.Name != "" {
for _, child := range sec.Children {
if p, ok := cut(child, path); ok {
part.Children = append(part.Children, p)
}
}
}
return part, len(part.Components) > 0 || len(part.Children) > 0
}
for _, sec := range sections {
if p, ok := cut(sec, nil); ok {
out.Sections = append(out.Sections, p)
}
}
return out
}
// ComponentPageHref links page of the components of the status page at
// base, keeping the search for query.
func ComponentPageHref(base string, page int, query string) string {
v := url.Values{}
if page > 0 {
v.Set("page", strconv.Itoa(page+1))
}
if query != "" {
v.Set("q", query)
}
href := BackHref(base)
if len(v) > 0 {
href += "?" + v.Encode()
}
return href
}
// BarPath draws the bars of one status of a chart.
type BarPath struct {
Status Status
D string
}
// BarPaths draws bars as one path per status instead of an element with a
// tooltip each: status pages list thousands of components with 90 bars
// each, and their detail pages have the tooltips.
func BarPaths(bs []Bar, height int) []BarPath {
var order []Status
ds := map[Status]*strings.Builder{}
h := strconv.Itoa(height)
for i, b := range bs {
d, ok := ds[b.Status]
if !ok {
d = &strings.Builder{}
ds[b.Status] = d
order = append(order, b.Status)
}
d.WriteString("M" + strconv.Itoa(i*4) + " 0h3v" + h + "h-3z")
}
out := make([]BarPath, 0, len(order))
for _, st := range order {
out = append(out, BarPath{Status: st, D: ds[st].String()})
}
return out
}
// NoticeForm is the button of a notice page that acts on a mailed link,
+43 -3
View File
@@ -94,11 +94,18 @@ templ PublicStatusPage(s agentapi.PageSnapshot, a PublicAssets) {
<p class="text-lg font-medium">{ i18n.T(ctx, "page.status."+s.Status) }</p>
</section>
@pageMaintenance(i18n.T(ctx, "page.maintenance_ongoing"), s.Ongoing(a.Now))
if len(s.Sections) > 0 {
if cp := PageComponents(s.Sections, a.Page, a.PageSize, a.Query); len(s.Sections) > 0 {
if cp.Pages > 1 || cp.Query != "" {
@publicComponentSearch(cp, a)
}
<section class="mb-12 border-t border-rule">
for _, sec := range s.Sections {
for _, sec := range cp.Sections {
@publicSection(sec, s, a)
}
if cp.Matches == 0 {
<p class="py-6 text-sm text-muted">{ i18n.T(ctx, "page.search_none") }</p>
}
@publicComponentPager(cp, a)
</section>
}
@publicIncidents(s.Incidents)
@@ -158,6 +165,34 @@ templ PublicNoticePage(s agentapi.PageSnapshot, a PublicAssets, title, message s
}
}
// publicComponentSearch finds components on pages listing too many to scan.
templ publicComponentSearch(cp ComponentPage, a PublicAssets) {
<form method="get" action={ templ.SafeURL(BackHref(a.ComponentBase)) } role="search" class="mb-4 flex flex-wrap items-center gap-2 text-sm">
<label class="sr-only" for="component-search">{ i18n.T(ctx, "page.search") }</label>
<input id="component-search" type="search" name="q" value={ cp.Query } maxlength="100" placeholder={ i18n.T(ctx, "page.search") } class="min-w-0 flex-1 border border-rule bg-transparent px-2 py-1.5"/>
<button type="submit" class="border border-ink px-3 py-1.5 hover:bg-ink hover:text-paper">{ i18n.T(ctx, "page.search_submit") }</button>
if cp.Query != "" {
<a href={ templ.SafeURL(BackHref(a.ComponentBase)) } class="text-muted hover:text-ink">{ i18n.T(ctx, "page.search_clear") }</a>
}
</form>
}
// publicComponentPager turns the pages of components.
templ publicComponentPager(cp ComponentPage, a PublicAssets) {
if cp.Pages > 1 {
<nav class="flex flex-wrap items-center gap-x-5 gap-y-2 py-4 text-sm" aria-label={ i18n.T(ctx, "pager.label") }>
if cp.Page > 0 {
<a href={ templ.SafeURL(ComponentPageHref(a.ComponentBase, 0, cp.Query)) } class="text-muted hover:text-ink">{ i18n.T(ctx, "pager.first") }</a>
<a href={ templ.SafeURL(ComponentPageHref(a.ComponentBase, cp.Page-1, cp.Query)) } rel="prev" class="text-muted hover:text-ink">← { i18n.T(ctx, "pager.previous") }</a>
}
<span class="font-mono text-xs text-muted">{ i18n.T(ctx, "page.pages", "Page", cp.Page+1, "Pages", cp.Pages) }</span>
if cp.Page < cp.Pages-1 {
<a href={ templ.SafeURL(ComponentPageHref(a.ComponentBase, cp.Page+1, cp.Query)) } rel="next" class="ml-auto text-muted hover:text-ink">{ i18n.T(ctx, "pager.next") } →</a>
}
</nav>
}
}
// publicSection renders an unnamed root component list or a collapsible nested
// group matching the monitor dashboard hierarchy.
templ publicSection(sec agentapi.Section, s agentapi.PageSnapshot, a PublicAssets) {
@@ -238,7 +273,12 @@ templ publicComponentBody(comp agentapi.Component, s agentapi.PageSnapshot, clic
}
</span>
</div>
@bars(DayBars(comp.Days), 22)
if clickable {
// The detail page the row links to has the tooltips.
@pathBars(DayBars(comp.Days), 22)
} else {
@bars(DayBars(comp.Days), 22)
}
<div class="mt-1 flex justify-between font-mono text-xs text-muted">
<span>{ i18n.T(ctx, "page.days_ago", "Count", len(comp.Days)) }</span>
<span>{ UptimeText(comp.Uptime) }</span>
File diff suppressed because it is too large. Load diff