feat(api): organizations with own status page servers serve their pages alone
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / lint (pull_request) Canceled after 6m3s
ci / test (pull_request) Canceled after 6m2s
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 6m3s
ci / test (pull_request) Canceled after 6m2s
ci / build (pull_request) Canceled after 0s
ci / image (pull_request) Canceled after 0s
The platform's status page servers handed out every published page, including those of organizations running their own servers. Once one of an organization's own status page servers has connected, the agent API now answers the platform's servers 404 for its pages, so they drop them from their cache, and only the organization's servers serve them. A created but never connected token changes nothing, so moving over does not take the pages offline. The console no longer links such pages to the platform's address, which would not serve them; the editor says who does. 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
20874a5a87
commit
c0239e15bb
11 files changed
+905
-778
No files matched your search
@@ -159,7 +159,7 @@ Run as many API, checker and status page instances as you need; they share no lo
|
||||
| Hybrid | hosted | at the customer | at the customer |
|
||||
| Self-hosted | at the customer | at the customer | at the customer |
|
||||
|
||||
Checkers and status page servers reach the API over HTTPS and never the database, so they can run in other networks.
|
||||
Checkers and status page servers reach the API over HTTPS and never the database, so they can run in other networks. Once one of an organization's own status page servers has connected, only its own servers serve its pages; the platform's no longer do.
|
||||
|
||||
## Usage
|
||||
|
||||
|
||||
+22
-6
@@ -1016,19 +1016,31 @@ func (s *Server) channelsView(c *gin.Context, p *principal, page web.Page, me we
|
||||
return web.ChannelsPage(page, me, v), nil
|
||||
}
|
||||
|
||||
func (s *Server) pageURL(p store.StatusPage) string {
|
||||
// pageURL is where p is reachable, or empty when only the organization's
|
||||
// own status page servers serve it, at an address the platform does not
|
||||
// know.
|
||||
func (s *Server) pageURL(p store.StatusPage, ownServers bool) string {
|
||||
if p.CustomDomain != nil && p.DomainVerifiedAt != nil {
|
||||
return "https://" + *p.CustomDomain + "/"
|
||||
}
|
||||
if ownServers {
|
||||
return ""
|
||||
}
|
||||
return strings.TrimSuffix(s.cfg.StatusPageURL, "/") + "/" + p.Slug
|
||||
}
|
||||
|
||||
func (s *Server) statusPagesView(c *gin.Context, p *principal, page web.Page, me web.Me) (templ.Component, error) {
|
||||
ctx := c.Request.Context()
|
||||
var rows []store.StatusPage
|
||||
var (
|
||||
rows []store.StatusPage
|
||||
own bool
|
||||
)
|
||||
err := s.db.Tx(ctx, p.scope(), func(q *store.Queries) error {
|
||||
var err error
|
||||
rows, err = q.ListStatusPages(ctx)
|
||||
if rows, err = q.ListStatusPages(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
own, err = q.OrgServesOwnPages(ctx, &p.Org.ID)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
@@ -1041,7 +1053,7 @@ func (s *Server) statusPagesView(c *gin.Context, p *principal, page web.Page, me
|
||||
}
|
||||
v.Pages = append(v.Pages, web.PageRow{
|
||||
ID: r.ID.String(), Title: r.Title, Slug: r.Slug, Published: r.Published,
|
||||
URL: s.pageURL(r), Domain: deref(r.CustomDomain), Suspended: r.SuspendedAt != nil,
|
||||
URL: s.pageURL(r, own), Domain: deref(r.CustomDomain), Suspended: r.SuspendedAt != nil,
|
||||
})
|
||||
}
|
||||
return web.StatusPagesPage(page, me, v), nil
|
||||
@@ -1059,6 +1071,7 @@ func (s *Server) statusPageEditor(c *gin.Context, p *principal, page web.Page, m
|
||||
pageGroups []store.StatusPageGroup
|
||||
orgGroups []store.MonitorGroup
|
||||
monitors []store.Monitor
|
||||
own bool
|
||||
)
|
||||
err = s.db.Tx(ctx, p.scope(), func(q *store.Queries) error {
|
||||
var err error
|
||||
@@ -1074,7 +1087,10 @@ func (s *Server) statusPageEditor(c *gin.Context, p *principal, page web.Page, m
|
||||
if orgGroups, err = q.ListGroups(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
monitors, err = q.ListMonitors(ctx)
|
||||
if monitors, err = q.ListMonitors(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
own, err = q.OrgServesOwnPages(ctx, &p.Org.ID)
|
||||
return err
|
||||
})
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
@@ -1089,7 +1105,7 @@ func (s *Server) statusPageEditor(c *gin.Context, p *principal, page web.Page, m
|
||||
Published: row.Published, ShowDetails: row.ShowComponentDetails,
|
||||
Suspended: row.SuspendedAt != nil, SuspendedReason: row.SuspendedReason,
|
||||
Accent: v.Theme.Accent, LogoURL: v.Theme.LogoURL, CSS: v.Theme.CSS,
|
||||
URL: s.pageURL(row), Domain: deref(row.CustomDomain), DomainVerified: v.DomainVerified,
|
||||
URL: s.pageURL(row, own), OwnServers: own, Domain: deref(row.CustomDomain), DomainVerified: v.DomainVerified,
|
||||
HasOrgGroups: len(orgGroups) > 0,
|
||||
}
|
||||
if v.DomainRecord != nil {
|
||||
|
||||
@@ -346,14 +346,22 @@ func (s *Server) agentPage(c *gin.Context) {
|
||||
fail(c, http.StatusBadRequest, "invalid_input")
|
||||
return
|
||||
}
|
||||
var page store.StatusPage
|
||||
var (
|
||||
page store.StatusPage
|
||||
own bool
|
||||
)
|
||||
a := agentOf(c)
|
||||
err := s.db.Tx(ctx, tenant.System(), func(q *store.Queries) error {
|
||||
var err error
|
||||
page, err = q.FindPublishedPage(ctx, store.FindPublishedPageParams{Host: host, Slug: slug})
|
||||
if page, err = q.FindPublishedPage(ctx, store.FindPublishedPageParams{Host: host, Slug: slug}); err != nil || a.OrgID != nil {
|
||||
return err
|
||||
}
|
||||
own, err = q.OrgServesOwnPages(ctx, &page.OrgID)
|
||||
return err
|
||||
})
|
||||
a := agentOf(c)
|
||||
if errors.Is(err, pgx.ErrNoRows) || (err == nil && a.OrgID != nil && *a.OrgID != page.OrgID) {
|
||||
// The platform's servers leave the pages of organizations that serve
|
||||
// them on their own servers to those.
|
||||
if errors.Is(err, pgx.ErrNoRows) || (err == nil && (own || a.OrgID != nil && *a.OrgID != page.OrgID)) {
|
||||
fail(c, http.StatusNotFound, "not_found")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -192,6 +192,26 @@ func TestStatusPages(t *testing.T) {
|
||||
st, body = editor.do("PUT", "/api/v1/org/statuspages/"+second, map[string]any{"slug": "x-second", "title": "x"})
|
||||
expect(t, "edit page out of scope", st, body, http.StatusNotFound, "not_found")
|
||||
})
|
||||
|
||||
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 {
|
||||
t.Fatalf("platform server before the own one connected: %v", err)
|
||||
}
|
||||
if _, err := own.Hello(context.Background()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := platform.Page(context.Background(), "", slug); !errors.Is(err, agentapi.ErrNotFound) {
|
||||
t.Errorf("platform server still gets the page: %v", err)
|
||||
}
|
||||
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 _, _, 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")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func editorEmail(b *browser) string {
|
||||
|
||||
@@ -1256,6 +1256,8 @@
|
||||
"pages.logo": "Logo-URL (https)",
|
||||
"pages.no_group": "Ohne Gruppe",
|
||||
"pages.open": "Öffnen",
|
||||
"pages.own_servers": "Die Statusseiten dieser Organisation liefern nur ihre eigenen Statusseiten-Server aus, nicht die der Plattform. Ruf sie über die Adresse deiner Server auf oder verbinde eine eigene Domain, die auf sie zeigt.",
|
||||
"pages.own_servers_short": "eigene Server",
|
||||
"pages.page_title": "Titel",
|
||||
"pages.published": "Veröffentlicht",
|
||||
"pages.section": "Abschnitt",
|
||||
|
||||
@@ -1256,6 +1256,8 @@
|
||||
"pages.logo": "Logo URL (https)",
|
||||
"pages.no_group": "No group",
|
||||
"pages.open": "Open",
|
||||
"pages.own_servers": "Your organization's own status page servers serve its pages; the platform's do not. Open them at the address of your servers or connect a custom domain pointing at them.",
|
||||
"pages.own_servers_short": "own servers",
|
||||
"pages.page_title": "Title",
|
||||
"pages.published": "Published",
|
||||
"pages.section": "Section",
|
||||
|
||||
@@ -318,6 +318,22 @@ func (q *Queries) ListVisibleRegions(ctx context.Context) ([]Region, error) {
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const orgServesOwnPages = `-- name: OrgServesOwnPages :one
|
||||
SELECT EXISTS (
|
||||
SELECT 1 FROM agents
|
||||
WHERE org_id = $1 AND kind = 'statuspage' AND last_seen_at IS NOT NULL
|
||||
)
|
||||
`
|
||||
|
||||
// An organization serves its status pages itself once one of its own
|
||||
// status page servers has connected.
|
||||
func (q *Queries) OrgServesOwnPages(ctx context.Context, orgID *uuid.UUID) (bool, error) {
|
||||
row := q.db.QueryRow(ctx, orgServesOwnPages, orgID)
|
||||
var exists bool
|
||||
err := row.Scan(&exists)
|
||||
return exists, err
|
||||
}
|
||||
|
||||
const setAgentAllowPrivate = `-- name: SetAgentAllowPrivate :execrows
|
||||
UPDATE agents SET allow_private = $1
|
||||
WHERE id = $2 AND kind = 'checker' AND org_id = $3
|
||||
|
||||
@@ -289,6 +289,9 @@ type Querier interface {
|
||||
OrgIncidentUpdatesExport(ctx context.Context, orgID uuid.UUID) ([]OrgIncidentUpdatesExportRow, error)
|
||||
OrgIncidentsExport(ctx context.Context, orgID uuid.UUID) ([]OrgIncidentsExportRow, error)
|
||||
OrgMembersExport(ctx context.Context, orgID uuid.UUID) ([]OrgMembersExportRow, error)
|
||||
// An organization serves its status pages itself once one of its own
|
||||
// status page servers has connected.
|
||||
OrgServesOwnPages(ctx context.Context, orgID *uuid.UUID) (bool, error)
|
||||
// Organizations user owns, with their member and owner counts.
|
||||
OwnedOrgs(ctx context.Context, userID uuid.UUID) ([]OwnedOrgsRow, error)
|
||||
// The public updates of incidents shown on a status page, newest first.
|
||||
|
||||
@@ -54,3 +54,11 @@ WHERE id = $1 AND (last_seen_at IS NULL OR last_seen_at < now() - interval '30 s
|
||||
-- name: SetAgentAllowPrivate :execrows
|
||||
UPDATE agents SET allow_private = sqlc.arg(allow_private)
|
||||
WHERE id = sqlc.arg(id) AND kind = 'checker' AND org_id = sqlc.arg(org_id);
|
||||
|
||||
-- name: OrgServesOwnPages :one
|
||||
-- An organization serves its status pages itself once one of its own
|
||||
-- status page servers has connected.
|
||||
SELECT EXISTS (
|
||||
SELECT 1 FROM agents
|
||||
WHERE org_id = $1 AND kind = 'statuspage' AND last_seen_at IS NOT NULL
|
||||
);
|
||||
@@ -44,6 +44,8 @@ templ StatusPagesPage(p Page, me Me, v PagesView) {
|
||||
}
|
||||
if pg.Suspended {
|
||||
<span class="ml-auto text-xs text-down">{ i18n.T(ctx, "pages.suspended") }</span>
|
||||
} else if pg.Published && pg.URL == "" {
|
||||
<span class="ml-auto text-xs text-muted">{ i18n.T(ctx, "pages.own_servers_short") }</span>
|
||||
} else if pg.Published {
|
||||
<a href={ templ.SafeURL(pg.URL) } class="ml-auto text-muted hover:text-ink" target="_blank" rel="noopener">{ i18n.T(ctx, "pages.open") } ↗</a>
|
||||
} else {
|
||||
@@ -89,6 +91,9 @@ type PageMonitorOption struct {
|
||||
|
||||
// PageEditor is the data of the status page editor.
|
||||
type PageEditor struct {
|
||||
// OwnServers is set when the organization's own status page servers
|
||||
// serve its pages instead of the platform's.
|
||||
OwnServers bool
|
||||
ID string
|
||||
Title string
|
||||
Slug string
|
||||
@@ -124,12 +129,15 @@ templ StatusPageEditor(p Page, me Me, e PageEditor) {
|
||||
<div class="mb-8 flex flex-wrap items-baseline justify-between gap-4">
|
||||
<h1 class="text-lg font-semibold">{ e.Title }</h1>
|
||||
<span class="flex gap-5 text-sm">
|
||||
if e.Published {
|
||||
if e.Published && e.URL != "" {
|
||||
<a href={ templ.SafeURL(e.URL) } target="_blank" rel="noopener" class="text-muted hover:text-ink">{ i18n.T(ctx, "pages.open") } ↗</a>
|
||||
}
|
||||
<a href={ templ.SafeURL("/api/v1/org/statuspages/" + e.ID + "/export") } class="text-muted hover:text-ink">{ i18n.T(ctx, "pages.export") }</a>
|
||||
</span>
|
||||
</div>
|
||||
if e.OwnServers {
|
||||
<p class="mb-6 border-l-2 border-ink pl-3 text-sm">{ i18n.T(ctx, "pages.own_servers") }</p>
|
||||
}
|
||||
<div class="grid gap-12 md:grid-cols-2">
|
||||
<section>
|
||||
@sectionHeading("pages.settings")
|
||||
|
||||
+810
-766
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user