feat(statuspage): refresh pages by checksum
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / lint (pull_request) Successful in 6m46s
ci / test (pull_request) Successful in 14m46s
ci / build (pull_request) Successful in 18m49s
ci / image (pull_request) Successful in 3m24s
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / lint (pull_request) Successful in 6m46s
ci / test (pull_request) Successful in 14m46s
ci / build (pull_request) Successful in 18m49s
ci / image (pull_request) Successful in 3m24s
Each refresh sent the whole page again even when nothing had changed. Status page servers now send the checksum of their copy (If-None-Match) and the API answers 304 when the page, leaving out when it was generated, is unchanged; the server then only marks its copy current. The checksum is kept on disk with the page, so it survives restarts. 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
4e9a198b2f
commit
fcf615dce7
6 files changed
+120
-8
No files matched your search
@@ -374,6 +374,14 @@ func (s *Server) agentPage(c *gin.Context) {
|
||||
internalError(c, err)
|
||||
return
|
||||
}
|
||||
// The server sends the checksum of its copy; an unchanged page is not
|
||||
// sent again.
|
||||
etag := `"` + snap.Checksum() + `"`
|
||||
c.Header("ETag", etag)
|
||||
if c.GetHeader("If-None-Match") == etag {
|
||||
c.Status(http.StatusNotModified)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, snap)
|
||||
}
|
||||
|
||||
|
||||
@@ -96,6 +96,12 @@ func TestStatusPages(t *testing.T) {
|
||||
snap.Sections[1].Components[0].Name != "Public API" {
|
||||
t.Errorf("snapshot = %+v, want degraded page with the Public API in outage", snap)
|
||||
}
|
||||
if _, err := platform.PageIfChanged(context.Background(), "", slug, snap.Checksum()); !errors.Is(err, agentapi.ErrNotModified) {
|
||||
t.Errorf("PageIfChanged(current checksum) error = %v, want not modified", err)
|
||||
}
|
||||
if again, err := platform.PageIfChanged(context.Background(), "", slug, "stale"); err != nil || again.Title != "Acme Status" {
|
||||
t.Errorf("PageIfChanged(stale checksum) = %v, %v", again.Title, err)
|
||||
}
|
||||
raw, _ := json.Marshal(snap)
|
||||
for _, secret := range []string{up.URL, down.URL, "unexpected status"} {
|
||||
if strings.Contains(string(raw), secret) {
|
||||
|
||||
Reference in new issue
Block a user