Compare commits

...
1 Commits
Author SHA1 Message Date
Sebastian UnterschützandClaude Opus 5.5 282ab27f81 feat(statuspages): page every group on its own and filter outages
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / image (pull_request) Waiting for needed jobs
ci / lint (pull_request) Successful in 11m3s
ci / test (pull_request) Successful in 12m33s
ci / build (pull_request) In progress
Paging all components of a status page at once left out whole groups on
every page, which confused visitors. Every group now shows its first 25
components and pages them on its own (?p.<group>=N), keeping the pages
of the other groups. Links jump back to the group.

Visitors can also show only the components with an outage or degraded
(?problems=1); groups without any are left out. The search stays.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
2026-11-28 14:35:24 +01:00
7 changed files with 1057 additions and 913 deletions

No files matched your search

+2
View File
@@ -1266,6 +1266,8 @@
"page.search_submit": "Suchen",
"page.search_clear": "Alle anzeigen",
"page.search_none": "Keine Komponente passt zur Suche.",
"page.filter_problems": "Nur Ausfälle ({{.Count}})",
"page.filter_no_problems": "Keine Komponente hat einen Ausfall.",
"page.updated": "Aktualisiert {{.Time}}",
"pager.earlier": "Frühere",
"pager.first": "Zum Anfang",
+2
View File
@@ -1266,6 +1266,8 @@
"page.search_submit": "Search",
"page.search_clear": "Show all",
"page.search_none": "No component matches the search.",
"page.filter_problems": "Outages only ({{.Count}})",
"page.filter_no_problems": "No component has an outage.",
"page.updated": "Updated {{.Time}}",
"pager.earlier": "Earlier",
"pager.first": "To the start",
+25 -6
View File
@@ -19,6 +19,7 @@ import (
"log/slog"
"net"
"net/http"
"net/url"
"os"
"path/filepath"
"strconv"
@@ -333,22 +334,40 @@ 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
}
assets.Pages = sectionPages(c.Request.URL.Query())
if q := c.Query("q"); len(q) <= maxComponentQuery {
assets.Query = q
}
assets.OnlyProblems = c.Query("problems") == "1"
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
// componentsPerPage is how many of its own components a section of a
// status page lists at a time; organizations put thousands on one.
const componentsPerPage = 25
// maxComponentQuery bounds the search for components.
const maxComponentQuery = 100
// maxPagedSections bounds the sections a request pages.
const maxPagedSections = 100
// sectionPages reads the pages of sections a request asks for, as
// "p.<key>=<page from 1>".
func sectionPages(q url.Values) map[string]int {
pages := map[string]int{}
for k, vs := range q {
key, ok := strings.CutPrefix(k, "p.")
if !ok || key == "" || len(vs) == 0 || len(pages) >= maxPagedSections {
continue
}
if n, err := strconv.Atoi(vs[0]); err == nil && n > 1 {
pages[key] = n - 1
}
}
return pages
}
// 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) {
+39 -12
View File
@@ -610,34 +610,61 @@ func TestEventsRefreshPagesAtOnce(t *testing.T) {
}
}
// Pages with many components list them a page at a time and let visitors
// search them.
// Every group of a page with many components lists them a page at a time,
// and visitors can search them or show those with an outage only.
func TestComponentPagingAndSearch(t *testing.T) {
comp := func(id, name, status string) agentapi.Component {
return agentapi.Component{ID: id, Name: name, Status: status, Days: []agentapi.Day{{Date: "2026-11-26", Uptime: 1}}}
}
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}}})
st := agentapi.PageOperational
if i == 7 {
st = agentapi.PageDegraded
}
core.Components = append(core.Components, comp(fmt.Sprintf("c%03d", i), fmt.Sprintf("web-%03d", i), st))
}
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})
st := agentapi.PageOperational
if i == 3 {
st = agentapi.PageOutage
}
edge.Components = append(edge.Components, comp(fmt.Sprintf("e%d", i), fmt.Sprintf("edge-%d", i), st))
}
core.Children = []agentapi.Section{edge}
other := agentapi.Section{Name: "Other"}
for i := 0; i < 30; i++ {
other.Components = append(other.Components, comp(fmt.Sprintf("o%02d", i), fmt.Sprintf("other-%02d", i), agentapi.PageOperational))
}
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}},
"|acme": {Title: "Acme status", Status: agentapi.PageOperational, ShowDetails: true, Sections: []agentapi.Section{core, other}},
"|calm": {Title: "Calm", Status: agentapi.PageOperational, Sections: []agentapi.Section{other}},
}}, t.TempDir(), &now)
if _, body := h.get("status.example.test", "/calm?problems=1"); !strings.Contains(body, "Keine Komponente hat einen Ausfall.") || strings.Contains(body, "other-00") {
t.Errorf("outages only without any lacks the notice")
}
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-"}},
// Every group shows its first page.
{"/acme", []string{"web-000", "web-024", "Seite 1 von 5", "edge-0", "edge-9", "other-00", "other-24", "Seite 1 von 2",
`id="g-0"`, `id="g-0.0"`, `id="g-1"`, `href="/acme?p.0=2#g-0"`, `href="/acme?p.1=2#g-1"`, `<path d="M0 0h3v22h-3z"`, "Nur Ausfälle (2)"},
[]string{"web-025", "other-25", `rel="prev"`, "<rect", "Alle anzeigen"}},
// Groups page on their own and keep the others' pages.
{"/acme?p.0=2", []string{"web-025", "web-049", "Seite 2 von 5", `href="/acme#g-0"`, "edge-0", "other-00"}, []string{"web-024", "web-050"}},
{"/acme?p.0=2&p.1=2", []string{"web-025", "other-29", `href="/acme?p.0=3&amp;p.1=2#g-0"`, `href="/acme?p.0=2#g-1"`}, []string{"other-00"}},
{"/acme?p.0=99", []string{"Seite 5 von 5", "web-119", "edge-9"}, nil},
{"/acme?p.0=x", []string{"Seite 1 von 5"}, nil},
// Outages only: degraded and down components, groups without any left out.
{"/acme?problems=1", []string{"web-007", "edge-3", ">Core<", ">Edge<", ">130<", "checked", "Alle anzeigen"},
[]string{"web-000", "edge-0", ">Other<", "Seite 1 von"}},
{"/acme?problems=1&q=edge", []string{"edge-3"}, []string{"web-007", "edge-0"}},
{"/acme?q=EDGE-", []string{"edge-0", "edge-9", `value="EDGE-"`, "Alle anzeigen"}, []string{"web-", "other-"}},
{"/acme?q=edge", []string{"edge-0", "edge-9", ">Core<"}, []string{"web-", ">Other<"}},
{"/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-"}},
}
+117 -90
View File
@@ -31,33 +31,104 @@ 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 is how many of a section's own 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
// Pages holds the zero-based page shown of the sections paged, by
// their PublicSection.Key.
Pages map[string]int
// Query is what the visitor searched the components for; OnlyProblems
// keeps those with an outage or degraded.
Query string
OnlyProblems bool
}
// 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.
// PublicSection is a section of a status page as a request for it shows
// it: the components of one page of the section's own, its status and
// count those of the whole section.
type PublicSection struct {
Name string
Status string
Total int
// Key identifies the section in the URLs paging it, e.g. "0.2".
Key string
Components []agentapi.Component
Children []PublicSection
// Page is the zero-based page of the section's own components shown,
// of Pages.
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)
// ComponentView is what a request for a status page shows of its
// components: every section paged on its own, filtered by a search and to
// those with problems if the visitor asked.
type ComponentView struct {
Sections []PublicSection
// Total counts all components, Matches those the filters leave and
// Problems those with an outage or degraded.
Total, Matches, Problems int
Query string
OnlyProblems bool
base string
size int
pages map[string]int
}
// Filterable reports whether the page lists enough components to offer the
// search and filter, or uses them.
func (v ComponentView) Filterable() bool {
return v.size > 0 && v.Total > v.size || v.Query != "" || v.OnlyProblems
}
// Filtered reports whether a search or filter is in use.
func (v ComponentView) Filtered() bool { return v.Query != "" || v.OnlyProblems }
// PageHref links page of the section key, keeping the other sections' pages
// and the filters.
func (v ComponentView) PageHref(key string, page int) string {
q := url.Values{}
if v.Query != "" {
q.Set("q", v.Query)
}
if v.OnlyProblems {
q.Set("problems", "1")
}
for k, p := range v.pages {
if k != key && p > 0 {
q.Set("p."+k, strconv.Itoa(p+1))
}
}
if page > 0 {
q.Set("p."+key, strconv.Itoa(page+1))
}
href := BackHref(v.base)
if len(q) > 0 {
href += "?" + q.Encode()
}
return href + "#g-" + key
}
// ResetHref links the page without search, filter and paging.
func (v ComponentView) ResetHref() string { return BackHref(v.base) }
// Problem reports whether a component counts as an outage for the filter.
func Problem(c agentapi.Component) bool {
return c.Status == agentapi.PageOutage || c.Status == agentapi.PageDegraded
}
// PublicComponents decides which components of sections a request for the
// page shows, as a.Query, a.OnlyProblems and a.Pages ask.
func PublicComponents(sections []agentapi.Section, a PublicAssets) ComponentView {
v := ComponentView{
Query: strings.TrimSpace(a.Query), OnlyProblems: a.OnlyProblems,
base: a.ComponentBase, size: a.PageSize, pages: a.Pages,
}
needle := strings.ToLower(v.Query)
match := func(path []string, c agentapi.Component) bool {
if v.OnlyProblems && !Problem(c) {
return false
}
if needle == "" || strings.Contains(strings.ToLower(c.Name), needle) {
return true
}
@@ -68,90 +139,46 @@ func PageComponents(sections []agentapi.Section, page, size int, query string) C
}
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 {
filtered := v.Filtered()
var walk func(sec agentapi.Section, key string, path []string) (PublicSection, bool)
walk = func(sec agentapi.Section, key string, path []string) (PublicSection, bool) {
ps := PublicSection{Name: sec.Name, Status: secStatusName(sec), Total: SectionTotal(sec), Key: key, Pages: 1}
if sec.Name != "" {
path = append(path, sec.Name)
}
n := 0
var own []agentapi.Component
for _, c := range sec.Components {
v.Total++
if Problem(c) {
v.Problems++
}
if match(path, c) {
n++
own = append(own, c)
}
}
v.Matches += len(own)
if v.size > 0 && len(own) > v.size {
ps.Pages = (len(own) + v.size - 1) / v.size
ps.Page = min(max(v.pages[key], 0), ps.Pages-1)
own = own[ps.Page*v.size : min((ps.Page+1)*v.size, len(own))]
}
ps.Components = own
// Unnamed sections are top-level lists without children.
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)
for i, child := range sec.Children {
if c, ok := walk(child, key+"."+strconv.Itoa(i), path); ok {
ps.Children = append(ps.Children, c)
}
}
}
return part, len(part.Components) > 0 || len(part.Children) > 0
return ps, !filtered || len(ps.Components) > 0 || len(ps.Children) > 0
}
for _, sec := range sections {
if p, ok := cut(sec, nil); ok {
out.Sections = append(out.Sections, p)
for i, sec := range sections {
if ps, ok := walk(sec, strconv.Itoa(i), nil); ok {
v.Sections = append(v.Sections, ps)
}
}
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
return v
}
// BarPath draws the bars of one status of a chart.
+42 -31
View File
@@ -94,18 +94,21 @@ 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 cp := PageComponents(s.Sections, a.Page, a.PageSize, a.Query); len(s.Sections) > 0 {
if cp.Pages > 1 || cp.Query != "" {
@publicComponentSearch(cp, a)
if v := PublicComponents(s.Sections, a); len(s.Sections) > 0 {
if v.Filterable() {
@publicComponentFilter(v, a)
}
<section class="mb-12 border-t border-rule">
for _, sec := range cp.Sections {
@publicSection(sec, s, a)
for _, sec := range v.Sections {
@publicSection(sec, v, s, a)
}
if cp.Matches == 0 {
<p class="py-6 text-sm text-muted">{ i18n.T(ctx, "page.search_none") }</p>
if v.Filtered() && v.Matches == 0 {
if v.OnlyProblems && v.Query == "" {
<p class="py-6 text-sm text-muted">{ i18n.T(ctx, "page.filter_no_problems") }</p>
} else {
<p class="py-6 text-sm text-muted">{ i18n.T(ctx, "page.search_none") }</p>
}
}
@publicComponentPager(cp, a)
</section>
}
@publicIncidents(s.Incidents)
@@ -165,29 +168,33 @@ 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">
// publicComponentFilter searches the components of pages listing too many
// to scan, or narrows them to those with an outage.
templ publicComponentFilter(v ComponentView, a PublicAssets) {
<form method="get" action={ templ.SafeURL(BackHref(a.ComponentBase)) } role="search" class="mb-4 flex flex-wrap items-center gap-x-4 gap-y-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"/>
<input id="component-search" type="search" name="q" value={ v.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"/>
<label class="flex items-center gap-2">
<input type="checkbox" name="problems" value="1" checked?={ v.OnlyProblems }/>
<span>{ i18n.T(ctx, "page.filter_problems", "Count", v.Problems) }</span>
</label>
<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>
if v.Filtered() {
<a href={ templ.SafeURL(v.ResetHref()) } 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>
// publicSectionPager turns the pages of a section's own components.
templ publicSectionPager(sec PublicSection, v ComponentView) {
if sec.Pages > 1 {
<nav class="flex flex-wrap items-center gap-x-5 gap-y-2 border-b border-rule py-2 text-sm" aria-label={ i18n.T(ctx, "pager.label") }>
if sec.Page > 0 {
<a href={ templ.SafeURL(v.PageHref(sec.Key, sec.Page-1)) } 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>
<span class="font-mono text-xs text-muted">{ i18n.T(ctx, "page.pages", "Page", sec.Page+1, "Pages", sec.Pages) }</span>
if sec.Page < sec.Pages-1 {
<a href={ templ.SafeURL(v.PageHref(sec.Key, sec.Page+1)) } rel="next" class="ml-auto text-muted hover:text-ink">{ i18n.T(ctx, "pager.next") } →</a>
}
</nav>
}
@@ -195,21 +202,25 @@ templ publicComponentPager(cp ComponentPage, a PublicAssets) {
// 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) {
templ publicSection(sec PublicSection, v ComponentView, s agentapi.PageSnapshot, a PublicAssets) {
if sec.Name == "" {
@publicComponentList(sec.Components, s, a)
<div id={ "g-" + sec.Key }>
@publicComponentList(sec.Components, s, a)
@publicSectionPager(sec, v)
</div>
} else {
<details open class="border-b border-rule">
<details open id={ "g-" + sec.Key } class="border-b border-rule">
<summary class="flex cursor-pointer items-center gap-2.5 py-3 text-sm font-medium select-none hover:bg-rule/30">
@statusDot(SectionStatus(sec))
@statusDot(PageStatus(sec.Status))
<span>{ sec.Name }</span>
<span class="font-mono text-xs font-normal text-muted">{ strconv.Itoa(SectionTotal(sec)) }</span>
<span class="ml-auto text-xs font-normal text-muted">{ i18n.T(ctx, "page.component."+string(secStatusName(sec))) }</span>
<span class="font-mono text-xs font-normal text-muted">{ strconv.Itoa(sec.Total) }</span>
<span class="ml-auto text-xs font-normal text-muted">{ i18n.T(ctx, "page.component."+sec.Status) }</span>
</summary>
<div class="ml-4 border-l border-rule pl-4">
@publicComponentList(sec.Components, s, a)
@publicSectionPager(sec, v)
for _, child := range sec.Children {
@publicSection(child, s, a)
@publicSection(child, v, s, a)
}
</div>
</details>
File diff suppressed because it is too large. Load diff