feat(agents): talk to the API over a WebSocket and push page changes
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / lint (pull_request) Successful in 6m29s
ci / test (pull_request) Successful in 12m55s
ci / build (pull_request) Successful in 16m45s
ci / image (pull_request) Successful in 5m41s

Checkers and status page servers keep one WebSocket open to the API at
/agent/v1/stream and send their requests over it. The API answers them
through the agent API as if they had come over HTTP, each authenticated
again, so the protocol stays the same and a revoked token ends the
stream. While the stream is down agents fall back to plain HTTP, and an
API without it is asked again every five minutes.

Over the stream the API tells status page servers which of their pages
changed, so they fetch them at once instead of on their next refresh:
when a region of a monitor changes between up and down, an incident
opens or resolves, or anything of the organization is edited. Changes
are announced through Redis to every API instance and sent at most every
five seconds per stream. A page that changes while it is fetched is
fetched once more.

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-26 17:21:30 +01:00
1 parent 27338f0557
commit 538c43b563
21 files changed
+1091 -45

No files matched your search

+7 -2
View File
@@ -58,6 +58,8 @@ type Server struct {
support *versioned[supportSettings]
// draining, once closed, ends the long polls of checkers.
draining <-chan struct{}
// handler serves the requests agents send over their streams.
handler http.Handler
// snapshots lets status page servers asking for the same page at once
// share one build of it.
snapshots singleflight.Group
@@ -107,6 +109,9 @@ func (s *Server) EndLongPollsOn(ch <-chan struct{}) { s.draining = ch }
// Mount installs session loading, locale resolution and CSRF protection and
// registers the JSON API and the console pages below them.
func (s *Server) Mount(r gin.IRouter) {
if h, ok := r.(http.Handler); ok {
s.handler = h
}
// Agents authenticate with tokens and never carry cookies, so they skip
// the session and CSRF middleware.
s.mountAgentAPI(r)
@@ -155,7 +160,7 @@ func (s *Server) Mount(r gin.IRouter) {
v1.POST("/invitations/:token/accept", auth.Require(), s.acceptInvitation)
v1.POST("/invitations/:token/signup", s.inviteSignup)
org := v1.Group("/org", s.orgAccess())
org := v1.Group("/org", s.orgAccess(), s.announcePages())
org.PUT("/policy", sessionOnly(), can(authz.OrgManage), s.updatePolicy)
org.GET("/export", sessionOnly(), can(authz.OrgManage), s.exportOrg)
org.GET("/legal", can(authz.OrgManage), s.orgListLegal)
@@ -197,7 +202,7 @@ func (s *Server) Mount(r gin.IRouter) {
org.PATCH("/agents/:id", sessionOnly(), can(authz.OrgManage), s.updateOrgAgent)
org.DELETE("/agents/:id", sessionOnly(), can(authz.OrgManage), s.deleteOrgAgent)
admin := v1.Group("/admin", s.requireAdmin())
admin := v1.Group("/admin", s.requireAdmin(), s.announcePages())
admin.GET("/audit", s.listPlatformAudit)
admin.GET("/check-types", s.adminListCheckTypes)
admin.PUT("/check-types", s.adminSetCheckTypes)