perf(statuspages): page, search and compress public status pages
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:
1 parent
52d2ce25c9
commit
b051f6c430
12 files changed
+4059
-3094
No files matched your search
@@ -88,6 +88,7 @@ func run(log *slog.Logger, level *slog.LevelVar) error {
|
||||
return err
|
||||
}
|
||||
health.Register(r)
|
||||
r.Use(platform.Compress())
|
||||
r.StaticFS("/static", web.Static())
|
||||
pages.Mount(r)
|
||||
go pages.Run(ctx)
|
||||
|
||||
@@ -1261,6 +1261,11 @@
|
||||
"page.status.outage": "Größere Störung",
|
||||
"page.status.unknown": "Status derzeit nicht verfügbar",
|
||||
"page.today": "Heute",
|
||||
"page.pages": "Seite {{.Page}} von {{.Pages}}",
|
||||
"page.search": "Komponenten suchen",
|
||||
"page.search_submit": "Suchen",
|
||||
"page.search_clear": "Alle anzeigen",
|
||||
"page.search_none": "Keine Komponente passt zur Suche.",
|
||||
"page.updated": "Aktualisiert {{.Time}}",
|
||||
"pager.earlier": "Frühere",
|
||||
"pager.first": "Zum Anfang",
|
||||
|
||||
@@ -1261,6 +1261,11 @@
|
||||
"page.status.outage": "Major outage",
|
||||
"page.status.unknown": "Status currently unavailable",
|
||||
"page.today": "Today",
|
||||
"page.pages": "Page {{.Page}} of {{.Pages}}",
|
||||
"page.search": "Search components",
|
||||
"page.search_submit": "Search",
|
||||
"page.search_clear": "Show all",
|
||||
"page.search_none": "No component matches the search.",
|
||||
"page.updated": "Updated {{.Time}}",
|
||||
"pager.earlier": "Earlier",
|
||||
"pager.first": "To the start",
|
||||
|
||||
@@ -0,0 +1,139 @@
|
||||
package platform
|
||||
|
||||
import (
|
||||
"compress/gzip"
|
||||
"io"
|
||||
"mime"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// compressMin is the smallest body worth compressing, for responses that
|
||||
// state their length.
|
||||
const compressMin = 1024
|
||||
|
||||
var gzipWriters = sync.Pool{New: func() any {
|
||||
w, _ := gzip.NewWriterLevel(io.Discard, gzip.DefaultCompression)
|
||||
return w
|
||||
}}
|
||||
|
||||
// Compress gzips text responses (HTML, CSS, JavaScript, JSON, XML, SVG) for
|
||||
// clients that accept it. Status pages list thousands of components in
|
||||
// markup that repeats itself, so this shrinks them many times over.
|
||||
func Compress() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
c.Writer.Header().Add("Vary", "Accept-Encoding")
|
||||
if c.Request.Method == http.MethodHead || !acceptsGzip(c.Request.Header.Get("Accept-Encoding")) {
|
||||
c.Next()
|
||||
return
|
||||
}
|
||||
w := &gzipWriter{ResponseWriter: c.Writer}
|
||||
c.Writer = w
|
||||
defer w.finish()
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
|
||||
// acceptsGzip reports whether an Accept-Encoding header allows gzip.
|
||||
func acceptsGzip(header string) bool {
|
||||
for _, part := range strings.Split(header, ",") {
|
||||
name, params, _ := strings.Cut(part, ";")
|
||||
name = strings.ToLower(strings.TrimSpace(name))
|
||||
if name != "gzip" && name != "*" {
|
||||
continue
|
||||
}
|
||||
for _, p := range strings.Split(params, ";") {
|
||||
k, v, _ := strings.Cut(strings.TrimSpace(p), "=")
|
||||
if strings.EqualFold(k, "q") {
|
||||
if q, err := strconv.ParseFloat(strings.TrimSpace(v), 64); err == nil && q == 0 {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func compressible(contentType string) bool {
|
||||
mt, _, err := mime.ParseMediaType(contentType)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
switch {
|
||||
case strings.HasPrefix(mt, "text/"):
|
||||
return true
|
||||
case mt == "application/json", mt == "application/javascript", mt == "image/svg+xml",
|
||||
mt == "application/xml", mt == "application/rss+xml", mt == "application/atom+xml":
|
||||
return true
|
||||
}
|
||||
return strings.HasSuffix(mt, "+json") || strings.HasSuffix(mt, "+xml")
|
||||
}
|
||||
|
||||
// gzipWriter decides at the first write whether to compress, when the
|
||||
// handler has set the status and headers.
|
||||
type gzipWriter struct {
|
||||
gin.ResponseWriter
|
||||
decided bool
|
||||
gz *gzip.Writer
|
||||
}
|
||||
|
||||
func (w *gzipWriter) decide() {
|
||||
w.decided = true
|
||||
h := w.Header()
|
||||
switch status := w.Status(); {
|
||||
case status < 200, status == http.StatusNoContent, status == http.StatusNotModified, status == http.StatusPartialContent:
|
||||
return
|
||||
}
|
||||
if h.Get("Content-Encoding") != "" || !compressible(h.Get("Content-Type")) {
|
||||
return
|
||||
}
|
||||
if n, err := strconv.Atoi(h.Get("Content-Length")); err == nil && n < compressMin {
|
||||
return
|
||||
}
|
||||
h.Set("Content-Encoding", "gzip")
|
||||
h.Del("Content-Length")
|
||||
if etag := h.Get("ETag"); etag != "" && !strings.HasPrefix(etag, "W/") {
|
||||
h.Set("ETag", "W/"+etag)
|
||||
}
|
||||
w.gz = gzipWriters.Get().(*gzip.Writer)
|
||||
w.gz.Reset(w.ResponseWriter)
|
||||
}
|
||||
|
||||
func (w *gzipWriter) Write(b []byte) (int, error) {
|
||||
if !w.decided {
|
||||
if w.Header().Get("Content-Type") == "" {
|
||||
w.Header().Set("Content-Type", http.DetectContentType(b))
|
||||
}
|
||||
w.decide()
|
||||
}
|
||||
if w.gz == nil {
|
||||
return w.ResponseWriter.Write(b)
|
||||
}
|
||||
return w.gz.Write(b)
|
||||
}
|
||||
|
||||
func (w *gzipWriter) WriteString(s string) (int, error) {
|
||||
return w.Write([]byte(s))
|
||||
}
|
||||
|
||||
func (w *gzipWriter) Flush() {
|
||||
if w.gz != nil {
|
||||
_ = w.gz.Flush()
|
||||
}
|
||||
w.ResponseWriter.Flush()
|
||||
}
|
||||
|
||||
func (w *gzipWriter) finish() {
|
||||
if w.gz == nil {
|
||||
return
|
||||
}
|
||||
_ = w.gz.Close()
|
||||
w.gz.Reset(io.Discard)
|
||||
gzipWriters.Put(w.gz)
|
||||
w.gz = nil
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
package platform
|
||||
|
||||
import (
|
||||
"compress/gzip"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func TestCompress(t *testing.T) {
|
||||
gin.SetMode(gin.TestMode)
|
||||
page := strings.Repeat("<li>component</li>", 2000)
|
||||
r := gin.New()
|
||||
r.Use(Compress())
|
||||
r.GET("/page", func(c *gin.Context) {
|
||||
c.Header("Content-Type", "text/html; charset=utf-8")
|
||||
c.Status(http.StatusOK)
|
||||
for i := 0; i < 2000; i++ {
|
||||
_, _ = c.Writer.WriteString("<li>component</li>")
|
||||
}
|
||||
})
|
||||
r.GET("/small", func(c *gin.Context) { c.String(http.StatusOK, "ok") })
|
||||
r.GET("/sized", func(c *gin.Context) {
|
||||
c.Header("Content-Length", strconv.Itoa(len("tiny")))
|
||||
c.Data(http.StatusOK, "text/plain", []byte("tiny"))
|
||||
})
|
||||
r.GET("/png", func(c *gin.Context) { c.Data(http.StatusOK, "image/png", []byte(page)) })
|
||||
r.GET("/json", func(c *gin.Context) { c.JSON(http.StatusOK, gin.H{"page": page}) })
|
||||
r.GET("/notmodified", func(c *gin.Context) { c.Status(http.StatusNotModified) })
|
||||
|
||||
get := func(path, accept string) *httptest.ResponseRecorder {
|
||||
req := httptest.NewRequest(http.MethodGet, path, nil)
|
||||
if accept != "" {
|
||||
req.Header.Set("Accept-Encoding", accept)
|
||||
}
|
||||
rec := httptest.NewRecorder()
|
||||
r.ServeHTTP(rec, req)
|
||||
return rec
|
||||
}
|
||||
gunzip := func(t *testing.T, rec *httptest.ResponseRecorder) string {
|
||||
t.Helper()
|
||||
zr, err := gzip.NewReader(rec.Body)
|
||||
if err != nil {
|
||||
t.Fatalf("gzip.NewReader() error = %v", err)
|
||||
}
|
||||
b, err := io.ReadAll(zr)
|
||||
if err != nil {
|
||||
t.Fatalf("reading gzip body error = %v", err)
|
||||
}
|
||||
return string(b)
|
||||
}
|
||||
|
||||
rec := get("/page", "br, gzip;q=0.8")
|
||||
if rec.Header().Get("Content-Encoding") != "gzip" || rec.Header().Get("Vary") != "Accept-Encoding" {
|
||||
t.Fatalf("headers = %v, want gzip with Vary", rec.Header())
|
||||
}
|
||||
if rec.Body.Len() >= len(page)/10 {
|
||||
t.Errorf("compressed size = %d, want far below %d", rec.Body.Len(), len(page))
|
||||
}
|
||||
if got := gunzip(t, rec); got != page {
|
||||
t.Errorf("decompressed body differs: %d bytes, want %d", len(got), len(page))
|
||||
}
|
||||
if rec := get("/json", "gzip"); rec.Header().Get("Content-Encoding") != "gzip" || !strings.Contains(gunzip(t, rec), "component") {
|
||||
t.Errorf("JSON not compressed: %v", rec.Header())
|
||||
}
|
||||
for _, tc := range []struct{ path, accept string }{
|
||||
{"/page", ""},
|
||||
{"/page", "gzip;q=0, deflate"},
|
||||
{"/page", "identity"},
|
||||
{"/sized", "gzip"},
|
||||
{"/png", "gzip"},
|
||||
{"/notmodified", "gzip"},
|
||||
} {
|
||||
if rec := get(tc.path, tc.accept); rec.Header().Get("Content-Encoding") != "" {
|
||||
t.Errorf("GET %s with %q compressed, want plain", tc.path, tc.accept)
|
||||
}
|
||||
}
|
||||
if rec := get("/page", "*"); rec.Header().Get("Content-Encoding") != "gzip" {
|
||||
t.Errorf("Accept-Encoding * not compressed")
|
||||
}
|
||||
}
|
||||
@@ -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) {
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
@@ -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">
|
||||
|
||||
+2704
-2577
File diff suppressed because it is too large.
Load diff
@@ -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,
|
||||
|
||||
@@ -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>
|
||||
|
||||
+833
-514
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user