feat(statuspage): fetch every served page every five minutes
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / lint (pull_request) Canceled after 5m23s
ci / test (pull_request) Canceled after 5m23s
ci / build (pull_request) Canceled after 0s
ci / image (pull_request) Canceled after 0s

A status page server only knew the pages visitors had asked it for, so
during an API outage a server that had never seen a page could not
serve it. The agent API now lists the pages a server serves
(GET /agent/v1/pages/index), following the same rule as single pages,
and status page servers fetch all of them on start and every five
minutes, also dropping those no longer listed. Pages visited within the
last ten minutes are still refreshed every 30 seconds; the outdated
notice now appears after ten minutes, twice the sync interval.

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-24 22:51:46 +01:00
1 parent c0239e15bb
commit 4e9a198b2f
10 files changed
+217 -15

No files matched your search

+44
View File
@@ -49,6 +49,21 @@ func (f *fakeSource) Page(ctx context.Context, host, slug string) (agentapi.Page
return p, nil
}
// Pages lists the fake's pages by their keys: "host|" or "|slug".
func (f *fakeSource) Pages(context.Context) ([]agentapi.PageRef, error) {
f.mu.Lock()
defer f.mu.Unlock()
if f.err != nil {
return nil, f.err
}
var out []agentapi.PageRef
for k := range f.pages {
host, slug, _ := strings.Cut(k, "|")
out = append(out, agentapi.PageRef{Host: host, Slug: slug})
}
return out, nil
}
func (f *fakeSource) set(fn func(*fakeSource)) {
f.mu.Lock()
defer f.mu.Unlock()
@@ -464,3 +479,32 @@ func TestNestedGroupsAndComponentDetails(t *testing.T) {
}
})
}
func TestSyncCachesPagesBeforeTheirFirstVisit(t *testing.T) {
dir := t.TempDir()
now := time.Now()
src := newSource()
h := newHarness(t, src, dir, &now)
h.srv.Sync(context.Background())
// Nobody visited them, yet both survive an outage and a restart.
now = now.Add(syncInterval)
restarted := newHarness(t, &fakeSource{err: errors.New("down")}, dir, &now)
if code, body := restarted.get("status.example.test", "/acme"); code != 200 || !strings.Contains(body, "Acme status") || strings.Contains(body, "Live-Aktualisierung") {
t.Errorf("GET of a synced page with the API down = %d, want it without stale notice", code)
}
if code, body := restarted.get("status.acme.test", "/"); code != 200 || !strings.Contains(body, "Acme on own domain") {
t.Errorf("GET of a synced custom domain with the API down = %d", code)
}
restarted.srv.Sync(context.Background())
if code, _ := restarted.get("status.example.test", "/acme"); code != 200 {
t.Errorf("a failed sync dropped the cache: %d", code)
}
// A page the API no longer lists is dropped by the next sync.
src.set(func(f *fakeSource) { delete(f.pages, "|acme") })
h.srv.Sync(context.Background())
if code, _ := h.get("status.example.test", "/acme"); code != 404 {
t.Errorf("GET after the page left the list = %d, want 404", code)
}
}