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
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:
1 parent
c0239e15bb
commit
4e9a198b2f
10 files changed
+217
-15
No files matched your search
@@ -41,6 +41,7 @@ func (s *Server) mountAgentAPI(r gin.IRouter) {
|
||||
g.GET("/update", s.agentUpdate)
|
||||
sp := g.Group("", requireAgentKind("statuspage"))
|
||||
sp.GET("/pages", s.agentPage)
|
||||
sp.GET("/pages/index", s.agentPageIndex)
|
||||
sp.GET("/storage", s.storageGet)
|
||||
sp.PUT("/storage", s.storagePut)
|
||||
sp.DELETE("/storage", s.storageDelete)
|
||||
|
||||
@@ -377,6 +377,26 @@ func (s *Server) agentPage(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, snap)
|
||||
}
|
||||
|
||||
// agentPageIndex lists the pages the status page server serves.
|
||||
func (s *Server) agentPageIndex(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
var rows []store.ServablePagesRow
|
||||
err := s.db.Tx(ctx, tenant.System(), func(q *store.Queries) error {
|
||||
var err error
|
||||
rows, err = q.ServablePages(ctx, agentOf(c).OrgID)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
internalError(c, err)
|
||||
return
|
||||
}
|
||||
out := make([]agentapi.PageRef, len(rows))
|
||||
for i, r := range rows {
|
||||
out[i] = agentapi.PageRef{Slug: r.Slug, Host: r.Host}
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"pages": out})
|
||||
}
|
||||
|
||||
type statusPageRequest struct {
|
||||
Slug string `json:"slug" binding:"required,max=63"`
|
||||
Title string `json:"title" binding:"required,max=200"`
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -196,7 +197,15 @@ func TestStatusPages(t *testing.T) {
|
||||
t.Run("own servers replace the platform's", func(t *testing.T) {
|
||||
org := uuid.MustParse(owner.orgID())
|
||||
own := e.statuspageClient(t, &org)
|
||||
if _, err := platform.Page(context.Background(), "", slug); err != nil {
|
||||
lists := func(c *agentapi.Client) bool {
|
||||
t.Helper()
|
||||
refs, err := c.Pages(context.Background())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return slices.ContainsFunc(refs, func(r agentapi.PageRef) bool { return r.Slug == slug && r.Host != "" })
|
||||
}
|
||||
if _, err := platform.Page(context.Background(), "", slug); err != nil || !lists(platform) {
|
||||
t.Fatalf("platform server before the own one connected: %v", err)
|
||||
}
|
||||
if _, err := own.Hello(context.Background()); err != nil {
|
||||
@@ -208,6 +217,9 @@ func TestStatusPages(t *testing.T) {
|
||||
if snap, err := own.Page(context.Background(), "", slug); err != nil || snap.Title != "Acme Status" {
|
||||
t.Errorf("own server Page() = %v, %v", snap.Title, err)
|
||||
}
|
||||
if lists(platform) || !lists(own) {
|
||||
t.Error("the page lists do not follow who serves the page")
|
||||
}
|
||||
if _, _, html := owner.page("/statuspages/" + pageID); !strings.Contains(html, "own status page servers serve its pages") {
|
||||
t.Error("the editor does not say who serves the pages")
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user