Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8ff4a86371 |
No files matched your search
+4
-13
@@ -651,19 +651,6 @@ func (s *Server) loadUser(ctx context.Context, id uuid.UUID) (store.User, error)
|
||||
return u, err
|
||||
}
|
||||
|
||||
// purgeOrg deletes an organization with everything in it, including check
|
||||
// results and status page server storage, which have no foreign key.
|
||||
func purgeOrg(ctx context.Context, q *store.Queries, org uuid.UUID) error {
|
||||
if err := q.PurgeOrgCheckData(ctx, org); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := q.DeleteOrgStorage(ctx, org); err != nil {
|
||||
return err
|
||||
}
|
||||
_, err := q.DeleteOrg(ctx, org)
|
||||
return err
|
||||
}
|
||||
|
||||
// deleteAccount erases the signed-in user (Art. 17). Organizations the
|
||||
// user is the last owner of go with the account, monitors and all, even
|
||||
// when they have other members: nobody would be left to run them. The user
|
||||
@@ -744,6 +731,9 @@ func (s *Server) eraseAccount(ctx context.Context, u store.User) (orgsDeleted in
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if orgsDeleted > 0 {
|
||||
s.wakeOrgPurges()
|
||||
}
|
||||
if err := s.sessions.DeleteAllForUser(ctx, u.ID); err != nil {
|
||||
s.log.ErrorContext(ctx, "ending sessions of deleted account failed", "error", err)
|
||||
}
|
||||
@@ -790,6 +780,7 @@ func (s *Server) deleteOrg(c *gin.Context) {
|
||||
internalError(c, err)
|
||||
return
|
||||
}
|
||||
s.wakeOrgPurges()
|
||||
if sess := auth.Current(c); sess != nil {
|
||||
_ = s.sessions.SwitchOrg(ctx, sess, uuid.Nil)
|
||||
}
|
||||
|
||||
@@ -176,6 +176,12 @@ func TestDeleteOrganization(t *testing.T) {
|
||||
})
|
||||
keepOrg := uuid.MustParse(keep.orgID())
|
||||
e.seedResults(t, keepOrg, uuid.MustParse(km["id"].(string)))
|
||||
// Results older than a week are compressed; the purge goes through them
|
||||
// as well.
|
||||
if _, err := e.dbPool.Exec(context.Background(),
|
||||
`SELECT compress_chunk(c, if_not_compressed => true) FROM show_chunks('check_results', older_than => now() - interval '1 day') c`); err != nil {
|
||||
t.Fatalf("compressing chunks: %v", err)
|
||||
}
|
||||
|
||||
admin := e.joinVia(t, owner.invite("a@"+uniq("d")+".test", owner.roleID("admin")))
|
||||
if st, body := admin.do("POST", "/api/v1/org/delete", map[string]any{"slug": slug, "password": password}); st != http.StatusForbidden {
|
||||
@@ -191,17 +197,33 @@ func TestDeleteOrganization(t *testing.T) {
|
||||
t.Fatalf("owner deletes org = %d %v", st, body)
|
||||
}
|
||||
|
||||
// The organization is gone at once, its check data is purged in the
|
||||
// background, chunk by chunk.
|
||||
for query, want := range map[string]int{
|
||||
`SELECT count(*) FROM orgs WHERE id = $1`: 0,
|
||||
`SELECT count(*) FROM monitors WHERE org_id = $1`: 0,
|
||||
`SELECT count(*) FROM check_results WHERE org_id = $1`: 0,
|
||||
`SELECT count(*) FROM check_results_1h WHERE org_id = $1`: 0,
|
||||
`SELECT count(*) FROM audit_events WHERE org_id = $1`: 0,
|
||||
`SELECT count(*) FROM orgs WHERE id = $1`: 0,
|
||||
`SELECT count(*) FROM monitors WHERE org_id = $1`: 0,
|
||||
`SELECT count(*) FROM org_purges WHERE org_id = $1`: 1,
|
||||
} {
|
||||
if got := e.count(t, query, org); got != want {
|
||||
t.Errorf("%s = %d, want %d", query, got, want)
|
||||
}
|
||||
}
|
||||
if err := e.api.PurgeDeletedOrgs(context.Background()); err != nil {
|
||||
t.Fatalf("PurgeDeletedOrgs() = %v", err)
|
||||
}
|
||||
for query, want := range map[string]int{
|
||||
`SELECT count(*) FROM check_results WHERE org_id = $1`: 0,
|
||||
`SELECT count(*) FROM check_results_1h WHERE org_id = $1`: 0,
|
||||
`SELECT count(*) FROM audit_events WHERE org_id = $1`: 0,
|
||||
`SELECT count(*) FROM org_purges WHERE org_id = $1`: 0,
|
||||
} {
|
||||
if got := e.count(t, query, org); got != want {
|
||||
t.Errorf("%s = %d, want %d", query, got, want)
|
||||
}
|
||||
}
|
||||
if e.count(t, `SELECT count(*) FROM check_results WHERE org_id = $1`, keepOrg) != 30 {
|
||||
t.Error("another organization's results were deleted")
|
||||
}
|
||||
if e.count(t, `SELECT count(*) FROM check_results_1h WHERE org_id = $1`, keepOrg) == 0 {
|
||||
t.Error("another organization's aggregates were deleted")
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ func (s *Server) RunHousekeeping(ctx context.Context) {
|
||||
// policies as owner.
|
||||
s.log.WarnContext(ctx, "applying retention policies failed", "error", err)
|
||||
}
|
||||
go s.runOrgPurges(ctx)
|
||||
tick := time.NewTicker(time.Hour)
|
||||
defer tick.Stop()
|
||||
for {
|
||||
|
||||
@@ -205,6 +205,7 @@ func (s *Server) adminDeleteOrg(c *gin.Context) {
|
||||
return purgeOrg(ctx, q, id)
|
||||
})
|
||||
if moderated(c, err) {
|
||||
s.wakeOrgPurges()
|
||||
c.Status(http.StatusNoContent)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5"
|
||||
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/store"
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/tenant"
|
||||
)
|
||||
|
||||
// orgPurgeEvery is how often an instance looks for deleted organizations
|
||||
// whose check data is left, besides right after a deletion.
|
||||
const orgPurgeEvery = time.Minute
|
||||
|
||||
// purgeOrg deletes an organization with everything in it at once, except
|
||||
// its check results and aggregates: they carry no foreign key and can run
|
||||
// to gigabytes, more than a request can delete in time, so it queues them
|
||||
// for PurgeDeletedOrgs. Nothing shows them once the organization is gone.
|
||||
func purgeOrg(ctx context.Context, q *store.Queries, org uuid.UUID) error {
|
||||
if err := q.QueueOrgPurge(ctx, org); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := q.DeleteOrgStorage(ctx, org); err != nil {
|
||||
return err
|
||||
}
|
||||
_, err := q.DeleteOrg(ctx, org)
|
||||
return err
|
||||
}
|
||||
|
||||
// wakeOrgPurges has PurgeDeletedOrgs run soon after a deletion instead of
|
||||
// at the next tick.
|
||||
func (s *Server) wakeOrgPurges() {
|
||||
select {
|
||||
case s.orgPurges <- struct{}{}:
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
// runOrgPurges purges the check data of deleted organizations every
|
||||
// orgPurgeEvery and when woken, until ctx ends.
|
||||
func (s *Server) runOrgPurges(ctx context.Context) {
|
||||
tick := time.NewTicker(orgPurgeEvery)
|
||||
defer tick.Stop()
|
||||
for {
|
||||
if err := s.PurgeDeletedOrgs(ctx); err != nil && ctx.Err() == nil {
|
||||
s.log.ErrorContext(ctx, "purging deleted organizations failed", "error", err)
|
||||
}
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case <-tick.C:
|
||||
case <-s.orgPurges:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// PurgeDeletedOrgs deletes the check data of deleted organizations a chunk
|
||||
// at a time, each in a transaction of its own, until none is left. An
|
||||
// instance leases an organization while it purges it; if it stops, another
|
||||
// takes over once the lease runs out and repeats the chunks, which then
|
||||
// delete nothing.
|
||||
func (s *Server) PurgeDeletedOrgs(ctx context.Context) error {
|
||||
for ctx.Err() == nil {
|
||||
var org uuid.UUID
|
||||
err := s.db.Tx(ctx, tenant.System(), func(q *store.Queries) error {
|
||||
var err error
|
||||
org, err = q.ClaimOrgPurge(ctx)
|
||||
return err
|
||||
})
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return nil
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.purgeOrgCheckData(ctx, org); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return ctx.Err()
|
||||
}
|
||||
|
||||
func (s *Server) purgeOrgCheckData(ctx context.Context, org uuid.UUID) error {
|
||||
start := time.Now()
|
||||
var chunks []string
|
||||
err := s.db.Tx(ctx, tenant.System(), func(q *store.Queries) error {
|
||||
var err error
|
||||
chunks, err = q.OrgCheckDataChunks(ctx)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var rows int64
|
||||
for _, chunk := range chunks {
|
||||
err := s.db.Tx(ctx, tenant.System(), func(q *store.Queries) error {
|
||||
n, err := q.PurgeOrgCheckChunk(ctx, store.PurgeOrgCheckChunkParams{OrgID: org, Chunk: chunk})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
rows += n
|
||||
return q.ExtendOrgPurge(ctx, org)
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
err = s.db.Tx(ctx, tenant.System(), func(q *store.Queries) error { return q.FinishOrgPurge(ctx, org) })
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
s.log.InfoContext(ctx, "purged check data of deleted organization",
|
||||
"org", org, "rows", rows, "chunks", len(chunks), "duration", time.Since(start).Round(time.Millisecond))
|
||||
return nil
|
||||
}
|
||||
+17
-14
@@ -31,20 +31,22 @@ const localeCookie = "lang"
|
||||
|
||||
// Server holds the dependencies shared by all handlers.
|
||||
type Server struct {
|
||||
cfg config.API
|
||||
log *slog.Logger
|
||||
db *tenant.DB
|
||||
rdb redis.UniversalClient
|
||||
keys *sealed.Keyring
|
||||
catalog *i18n.Catalog
|
||||
sessions *auth.Sessions
|
||||
limiter *auth.Limiter
|
||||
totp *auth.TOTPVerifier
|
||||
sso *sso.Client
|
||||
sched *schedule.Scheduler
|
||||
eval *evaluate.Evaluator
|
||||
smtp *notify.SMTP
|
||||
legal *versioned[[]agentapi.LegalDoc]
|
||||
// orgPurges wakes runOrgPurges after an organization was deleted.
|
||||
orgPurges chan struct{}
|
||||
cfg config.API
|
||||
log *slog.Logger
|
||||
db *tenant.DB
|
||||
rdb redis.UniversalClient
|
||||
keys *sealed.Keyring
|
||||
catalog *i18n.Catalog
|
||||
sessions *auth.Sessions
|
||||
limiter *auth.Limiter
|
||||
totp *auth.TOTPVerifier
|
||||
sso *sso.Client
|
||||
sched *schedule.Scheduler
|
||||
eval *evaluate.Evaluator
|
||||
smtp *notify.SMTP
|
||||
legal *versioned[[]agentapi.LegalDoc]
|
||||
// consent caches the versions of the documents accounts accept.
|
||||
consent *versioned[map[string]int64]
|
||||
// checkTypes caches the check types switched off platform-wide.
|
||||
@@ -82,6 +84,7 @@ func New(cfg config.API, d Deps) *Server {
|
||||
allowPrivate := cfg.SSOAllowPrivate()
|
||||
mail, _ := notify.ParseSMTP(cfg.SMTPURL)
|
||||
return &Server{
|
||||
orgPurges: make(chan struct{}, 1),
|
||||
eval: evaluate.New(d.Redis),
|
||||
smtp: mail,
|
||||
cfg: cfg,
|
||||
|
||||
@@ -1266,8 +1266,6 @@
|
||||
"page.search_submit": "Suchen",
|
||||
"page.search_clear": "Alle anzeigen",
|
||||
"page.search_none": "Keine Komponente passt zur Suche.",
|
||||
"page.filter_problems": "Nur Ausfälle ({{.Count}})",
|
||||
"page.filter_no_problems": "Keine Komponente hat einen Ausfall.",
|
||||
"page.updated": "Aktualisiert {{.Time}}",
|
||||
"pager.earlier": "Frühere",
|
||||
"pager.first": "Zum Anfang",
|
||||
|
||||
@@ -1266,8 +1266,6 @@
|
||||
"page.search_submit": "Search",
|
||||
"page.search_clear": "Show all",
|
||||
"page.search_none": "No component matches the search.",
|
||||
"page.filter_problems": "Outages only ({{.Count}})",
|
||||
"page.filter_no_problems": "No component has an outage.",
|
||||
"page.updated": "Updated {{.Time}}",
|
||||
"pager.earlier": "Earlier",
|
||||
"pager.first": "To the start",
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
-- +goose Up
|
||||
-- Deleting an organization removes it at once but leaves its check results
|
||||
-- and aggregates, which carry no foreign key, to the background: years of
|
||||
-- results take far longer to delete than a request may last. The purge
|
||||
-- goes a chunk at a time, each in a transaction of its own, so it never
|
||||
-- holds locks for long and resumes where it stopped.
|
||||
CREATE TABLE org_purges (
|
||||
org_id uuid PRIMARY KEY,
|
||||
requested_at timestamptz NOT NULL DEFAULT now(),
|
||||
-- An API instance purging the organization holds it until then.
|
||||
leased_until timestamptz NOT NULL DEFAULT '-infinity'
|
||||
);
|
||||
|
||||
ALTER TABLE org_purges ENABLE ROW LEVEL SECURITY;
|
||||
ALTER TABLE org_purges FORCE ROW LEVEL SECURITY;
|
||||
CREATE POLICY org_purges_system ON org_purges FOR ALL
|
||||
USING (app_scope_system()) WITH CHECK (app_scope_system());
|
||||
|
||||
-- +goose StatementBegin
|
||||
-- The chunks holding check data: those of the raw results first, so the
|
||||
-- aggregates' refresh does not materialize again what was purged from them,
|
||||
-- then those of both aggregates, oldest first. Runs with the owner's rights because the application role
|
||||
-- may not reach TimescaleDB's internal schema.
|
||||
CREATE FUNCTION org_check_data_chunks() RETURNS SETOF text
|
||||
LANGUAGE sql STABLE SECURITY DEFINER SET search_path = public, pg_temp AS $$
|
||||
SELECT format('%I.%I', c.chunk_schema, c.chunk_name)
|
||||
FROM timescaledb_information.chunks c
|
||||
WHERE (c.hypertable_schema, c.hypertable_name) IN (
|
||||
SELECT 'public'::name, 'check_results'::name
|
||||
UNION ALL
|
||||
SELECT materialization_hypertable_schema, materialization_hypertable_name
|
||||
FROM timescaledb_information.continuous_aggregates
|
||||
WHERE view_name IN ('check_results_1h', 'check_results_1d'))
|
||||
ORDER BY c.hypertable_name <> 'check_results', c.range_start, 1
|
||||
$$;
|
||||
-- +goose StatementEnd
|
||||
|
||||
-- +goose StatementBegin
|
||||
-- Deletes an organization's rows in one chunk of org_check_data_chunks,
|
||||
-- through its hypertable and limited to the chunk's time range, so that
|
||||
-- TimescaleDB handles compressed chunks. Chunks dropped meanwhile, and
|
||||
-- names of anything else, delete nothing.
|
||||
CREATE FUNCTION purge_org_check_chunk(org uuid, chunk text) RETURNS bigint
|
||||
LANGUAGE plpgsql SECURITY DEFINER SET search_path = public, pg_temp AS $$
|
||||
DECLARE
|
||||
r record;
|
||||
n bigint;
|
||||
BEGIN
|
||||
SELECT c.hypertable_schema AS hs, c.hypertable_name AS hn, d.column_name AS col,
|
||||
c.range_start AS lo, c.range_end AS hi
|
||||
INTO r
|
||||
FROM timescaledb_information.chunks c
|
||||
JOIN timescaledb_information.dimensions d
|
||||
ON d.hypertable_schema = c.hypertable_schema AND d.hypertable_name = c.hypertable_name
|
||||
AND d.dimension_number = 1
|
||||
WHERE format('%I.%I', c.chunk_schema, c.chunk_name) = chunk
|
||||
AND chunk IN (SELECT org_check_data_chunks());
|
||||
IF NOT FOUND THEN
|
||||
RETURN 0;
|
||||
END IF;
|
||||
EXECUTE format('DELETE FROM %I.%I WHERE org_id = $1 AND %I >= $2 AND %I < $3', r.hs, r.hn, r.col, r.col)
|
||||
USING org, r.lo, r.hi;
|
||||
GET DIAGNOSTICS n = ROW_COUNT;
|
||||
RETURN n;
|
||||
END
|
||||
$$;
|
||||
-- +goose StatementEnd
|
||||
|
||||
-- +goose Down
|
||||
DROP FUNCTION purge_org_check_chunk(uuid, text);
|
||||
DROP FUNCTION org_check_data_chunks();
|
||||
DROP TABLE org_purges;
|
||||
@@ -19,7 +19,6 @@ import (
|
||||
"log/slog"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
@@ -334,40 +333,22 @@ func (s *Server) serve(c *gin.Context) {
|
||||
s.localizeRequest(c)
|
||||
c.Header("Cache-Control", "public, max-age=30")
|
||||
assets.PageSize = componentsPerPage
|
||||
assets.Pages = sectionPages(c.Request.URL.Query())
|
||||
if n, err := strconv.Atoi(c.Query("page")); err == nil && n > 1 {
|
||||
assets.Page = n - 1
|
||||
}
|
||||
if q := c.Query("q"); len(q) <= maxComponentQuery {
|
||||
assets.Query = q
|
||||
}
|
||||
assets.OnlyProblems = c.Query("problems") == "1"
|
||||
web.Render(c, http.StatusOK, web.PublicStatusPage(e.Snap.WithMaintenance(s.now()), assets))
|
||||
}
|
||||
|
||||
// componentsPerPage is how many of its own components a section of a
|
||||
// status page lists at a time; organizations put thousands on one.
|
||||
const componentsPerPage = 25
|
||||
// componentsPerPage is how many components a status page lists at a time;
|
||||
// organizations put thousands on one.
|
||||
const componentsPerPage = 50
|
||||
|
||||
// maxComponentQuery bounds the search for components.
|
||||
const maxComponentQuery = 100
|
||||
|
||||
// maxPagedSections bounds the sections a request pages.
|
||||
const maxPagedSections = 100
|
||||
|
||||
// sectionPages reads the pages of sections a request asks for, as
|
||||
// "p.<key>=<page from 1>".
|
||||
func sectionPages(q url.Values) map[string]int {
|
||||
pages := map[string]int{}
|
||||
for k, vs := range q {
|
||||
key, ok := strings.CutPrefix(k, "p.")
|
||||
if !ok || key == "" || len(vs) == 0 || len(pages) >= maxPagedSections {
|
||||
continue
|
||||
}
|
||||
if n, err := strconv.Atoi(vs[0]); err == nil && n > 1 {
|
||||
pages[key] = n - 1
|
||||
}
|
||||
}
|
||||
return pages
|
||||
}
|
||||
|
||||
// serveComponent renders one component's public detail page from the cached
|
||||
// snapshot when the status page has enabled ShowDetails.
|
||||
func (s *Server) serveComponent(c *gin.Context, e entry, compID string, assets web.PublicAssets) {
|
||||
|
||||
@@ -610,61 +610,34 @@ func TestEventsRefreshPagesAtOnce(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// Every group of a page with many components lists them a page at a time,
|
||||
// and visitors can search them or show those with an outage only.
|
||||
// Pages with many components list them a page at a time and let visitors
|
||||
// search them.
|
||||
func TestComponentPagingAndSearch(t *testing.T) {
|
||||
comp := func(id, name, status string) agentapi.Component {
|
||||
return agentapi.Component{ID: id, Name: name, Status: status, Days: []agentapi.Day{{Date: "2026-11-26", Uptime: 1}}}
|
||||
}
|
||||
core := agentapi.Section{Name: "Core"}
|
||||
for i := 0; i < 120; i++ {
|
||||
st := agentapi.PageOperational
|
||||
if i == 7 {
|
||||
st = agentapi.PageDegraded
|
||||
}
|
||||
core.Components = append(core.Components, comp(fmt.Sprintf("c%03d", i), fmt.Sprintf("web-%03d", i), st))
|
||||
core.Components = append(core.Components, agentapi.Component{ID: fmt.Sprintf("c%03d", i), Name: fmt.Sprintf("web-%03d", i), Status: agentapi.PageOperational, Days: []agentapi.Day{{Date: "2026-11-26", Uptime: 1}}})
|
||||
}
|
||||
edge := agentapi.Section{Name: "Edge"}
|
||||
for i := 0; i < 10; i++ {
|
||||
st := agentapi.PageOperational
|
||||
if i == 3 {
|
||||
st = agentapi.PageOutage
|
||||
}
|
||||
edge.Components = append(edge.Components, comp(fmt.Sprintf("e%d", i), fmt.Sprintf("edge-%d", i), st))
|
||||
edge.Components = append(edge.Components, agentapi.Component{ID: fmt.Sprintf("e%d", i), Name: fmt.Sprintf("edge-%d", i), Status: agentapi.PageOperational})
|
||||
}
|
||||
core.Children = []agentapi.Section{edge}
|
||||
other := agentapi.Section{Name: "Other"}
|
||||
for i := 0; i < 30; i++ {
|
||||
other.Components = append(other.Components, comp(fmt.Sprintf("o%02d", i), fmt.Sprintf("other-%02d", i), agentapi.PageOperational))
|
||||
}
|
||||
now := time.Now()
|
||||
h := newHarness(t, &fakeSource{pages: map[string]agentapi.PageSnapshot{
|
||||
"|acme": {Title: "Acme status", Status: agentapi.PageOperational, ShowDetails: true, Sections: []agentapi.Section{core, other}},
|
||||
"|calm": {Title: "Calm", Status: agentapi.PageOperational, Sections: []agentapi.Section{other}},
|
||||
"|acme": {Title: "Acme status", Status: agentapi.PageOperational, ShowDetails: true, Sections: []agentapi.Section{core}},
|
||||
}}, t.TempDir(), &now)
|
||||
if _, body := h.get("status.example.test", "/calm?problems=1"); !strings.Contains(body, "Keine Komponente hat einen Ausfall.") || strings.Contains(body, "other-00") {
|
||||
t.Errorf("outages only without any lacks the notice")
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
path string
|
||||
has, hasNot []string
|
||||
}{
|
||||
// Every group shows its first page.
|
||||
{"/acme", []string{"web-000", "web-024", "Seite 1 von 5", "edge-0", "edge-9", "other-00", "other-24", "Seite 1 von 2",
|
||||
`id="g-0"`, `id="g-0.0"`, `id="g-1"`, `href="/acme?p.0=2#g-0"`, `href="/acme?p.1=2#g-1"`, `<path d="M0 0h3v22h-3z"`, "Nur Ausfälle (2)"},
|
||||
[]string{"web-025", "other-25", `rel="prev"`, "<rect", "Alle anzeigen"}},
|
||||
// Groups page on their own and keep the others' pages.
|
||||
{"/acme?p.0=2", []string{"web-025", "web-049", "Seite 2 von 5", `href="/acme#g-0"`, "edge-0", "other-00"}, []string{"web-024", "web-050"}},
|
||||
{"/acme?p.0=2&p.1=2", []string{"web-025", "other-29", `href="/acme?p.0=3&p.1=2#g-0"`, `href="/acme?p.0=2#g-1"`}, []string{"other-00"}},
|
||||
{"/acme?p.0=99", []string{"Seite 5 von 5", "web-119", "edge-9"}, nil},
|
||||
{"/acme?p.0=x", []string{"Seite 1 von 5"}, nil},
|
||||
// Outages only: degraded and down components, groups without any left out.
|
||||
{"/acme?problems=1", []string{"web-007", "edge-3", ">Core<", ">Edge<", ">130<", "checked", "Alle anzeigen"},
|
||||
[]string{"web-000", "edge-0", ">Other<", "Seite 1 von"}},
|
||||
{"/acme?problems=1&q=edge", []string{"edge-3"}, []string{"web-007", "edge-0"}},
|
||||
{"/acme?q=EDGE-", []string{"edge-0", "edge-9", `value="EDGE-"`, "Alle anzeigen"}, []string{"web-", "other-"}},
|
||||
{"/acme?q=edge", []string{"edge-0", "edge-9", ">Core<"}, []string{"web-", ">Other<"}},
|
||||
{"/acme", []string{"web-000", "web-049", "Seite 1 von 3", `href="/acme?page=2"`, `<path d="M0 0h3v22h-3z"`}, []string{"web-050", "edge-0", `rel="prev"`, "<rect"}},
|
||||
{"/acme?page=2", []string{"web-050", "web-099", "Seite 2 von 3", `href="/acme?page=3"`, `href="/acme"`}, []string{"web-049", "web-100"}},
|
||||
{"/acme?page=3", []string{"web-119", "edge-9", ">Core<", ">Edge<", ">130<", "Seite 3 von 3"}, []string{"web-099", `rel="next"`}},
|
||||
{"/acme?page=99", []string{"Seite 3 von 3", "edge-9"}, nil},
|
||||
{"/acme?page=x", []string{"Seite 1 von 3"}, nil},
|
||||
{"/acme?q=EDGE-", []string{"edge-0", "edge-9", `value="EDGE-"`, "Alle anzeigen"}, []string{"web-", "Seite 1"}},
|
||||
{"/acme?q=edge", []string{"edge-0", "edge-9"}, []string{"web-"}},
|
||||
{"/acme?q=web-11", []string{"web-110", "web-119"}, []string{"web-109", "edge-"}},
|
||||
{"/acme?q=nothing", []string{"Keine Komponente passt zur Suche."}, []string{"web-", "edge-"}},
|
||||
}
|
||||
|
||||
@@ -345,15 +345,6 @@ func (q *Queries) OwnedOrgs(ctx context.Context, userID uuid.UUID) ([]OwnedOrgsR
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const purgeOrgCheckData = `-- name: PurgeOrgCheckData :exec
|
||||
SELECT purge_org_check_data($1)
|
||||
`
|
||||
|
||||
func (q *Queries) PurgeOrgCheckData(ctx context.Context, org uuid.UUID) error {
|
||||
_, err := q.db.Exec(ctx, purgeOrgCheckData, org)
|
||||
return err
|
||||
}
|
||||
|
||||
const scrubAuditEmail = `-- name: ScrubAuditEmail :exec
|
||||
UPDATE audit_events SET details = details - 'email' WHERE lower(details->>'email') = lower($1::text)
|
||||
`
|
||||
|
||||
@@ -337,6 +337,12 @@ type Org struct {
|
||||
LimitSubscribersPerWeek *int32
|
||||
}
|
||||
|
||||
type OrgPurge struct {
|
||||
OrgID uuid.UUID
|
||||
RequestedAt time.Time
|
||||
LeasedUntil time.Time
|
||||
}
|
||||
|
||||
type PlatformIdentity struct {
|
||||
ProviderID uuid.UUID
|
||||
Subject string
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
// source: org_purges.sql
|
||||
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
const claimOrgPurge = `-- name: ClaimOrgPurge :one
|
||||
UPDATE org_purges SET leased_until = now() + interval '15 minutes'
|
||||
WHERE org_id = (
|
||||
SELECT org_id FROM org_purges WHERE leased_until < now()
|
||||
ORDER BY requested_at LIMIT 1
|
||||
FOR UPDATE SKIP LOCKED
|
||||
)
|
||||
RETURNING org_id
|
||||
`
|
||||
|
||||
// System scope: leases the longest waiting purge no other instance holds.
|
||||
func (q *Queries) ClaimOrgPurge(ctx context.Context) (uuid.UUID, error) {
|
||||
row := q.db.QueryRow(ctx, claimOrgPurge)
|
||||
var org_id uuid.UUID
|
||||
err := row.Scan(&org_id)
|
||||
return org_id, err
|
||||
}
|
||||
|
||||
const countOrgPurges = `-- name: CountOrgPurges :one
|
||||
SELECT count(*) FROM org_purges
|
||||
`
|
||||
|
||||
func (q *Queries) CountOrgPurges(ctx context.Context) (int64, error) {
|
||||
row := q.db.QueryRow(ctx, countOrgPurges)
|
||||
var count int64
|
||||
err := row.Scan(&count)
|
||||
return count, err
|
||||
}
|
||||
|
||||
const extendOrgPurge = `-- name: ExtendOrgPurge :exec
|
||||
UPDATE org_purges SET leased_until = now() + interval '15 minutes' WHERE org_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) ExtendOrgPurge(ctx context.Context, orgID uuid.UUID) error {
|
||||
_, err := q.db.Exec(ctx, extendOrgPurge, orgID)
|
||||
return err
|
||||
}
|
||||
|
||||
const finishOrgPurge = `-- name: FinishOrgPurge :exec
|
||||
DELETE FROM org_purges WHERE org_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) FinishOrgPurge(ctx context.Context, orgID uuid.UUID) error {
|
||||
_, err := q.db.Exec(ctx, finishOrgPurge, orgID)
|
||||
return err
|
||||
}
|
||||
|
||||
const orgCheckDataChunks = `-- name: OrgCheckDataChunks :many
|
||||
SELECT chunk::text FROM org_check_data_chunks() AS chunk
|
||||
`
|
||||
|
||||
func (q *Queries) OrgCheckDataChunks(ctx context.Context) ([]string, error) {
|
||||
rows, err := q.db.Query(ctx, orgCheckDataChunks)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []string{}
|
||||
for rows.Next() {
|
||||
var chunk string
|
||||
if err := rows.Scan(&chunk); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, chunk)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const purgeOrgCheckChunk = `-- name: PurgeOrgCheckChunk :one
|
||||
SELECT purge_org_check_chunk($1::uuid, $2::text)::bigint AS rows
|
||||
`
|
||||
|
||||
type PurgeOrgCheckChunkParams struct {
|
||||
OrgID uuid.UUID
|
||||
Chunk string
|
||||
}
|
||||
|
||||
func (q *Queries) PurgeOrgCheckChunk(ctx context.Context, arg PurgeOrgCheckChunkParams) (int64, error) {
|
||||
row := q.db.QueryRow(ctx, purgeOrgCheckChunk, arg.OrgID, arg.Chunk)
|
||||
var rows int64
|
||||
err := row.Scan(&rows)
|
||||
return rows, err
|
||||
}
|
||||
|
||||
const queueOrgPurge = `-- name: QueueOrgPurge :exec
|
||||
INSERT INTO org_purges (org_id) VALUES ($1) ON CONFLICT DO NOTHING
|
||||
`
|
||||
|
||||
// System scope: has the check data of a deleted organization purged.
|
||||
func (q *Queries) QueueOrgPurge(ctx context.Context, orgID uuid.UUID) error {
|
||||
_, err := q.db.Exec(ctx, queueOrgPurge, orgID)
|
||||
return err
|
||||
}
|
||||
@@ -46,6 +46,8 @@ type Querier interface {
|
||||
// System scope. Leases due rows for five minutes so a crashed sender's rows
|
||||
// come back; SKIP LOCKED lets every API replica work the outbox.
|
||||
ClaimNotifications(ctx context.Context, max int32) ([]uuid.UUID, error)
|
||||
// System scope: leases the longest waiting purge no other instance holds.
|
||||
ClaimOrgPurge(ctx context.Context) (uuid.UUID, error)
|
||||
// System scope; leased like ClaimNotifications.
|
||||
ClaimSubscriberNotifications(ctx context.Context, max int32) ([]uuid.UUID, error)
|
||||
// Shortens tokens that would outlive a newly set maximum lifetime.
|
||||
@@ -56,6 +58,7 @@ type Querier interface {
|
||||
ConfirmPageSubscriber(ctx context.Context, id uuid.UUID) error
|
||||
CountMonitors(ctx context.Context, orgID uuid.UUID) (int64, error)
|
||||
CountOpenSupportTickets(ctx context.Context, userID uuid.UUID) (int64, error)
|
||||
CountOrgPurges(ctx context.Context) (int64, error)
|
||||
CountOwnedOrgs(ctx context.Context, userID uuid.UUID) (int64, error)
|
||||
CountOwners(ctx context.Context, orgID uuid.UUID) (int64, error)
|
||||
CountPageSubscribers(ctx context.Context, pageID uuid.UUID) (CountPageSubscribersRow, error)
|
||||
@@ -147,9 +150,11 @@ type Querier interface {
|
||||
EnsurePlatformRegion(ctx context.Context, arg EnsurePlatformRegionParams) (Region, error)
|
||||
// Evidence of a monitor in a time span, to link results to it.
|
||||
EvidenceBetween(ctx context.Context, arg EvidenceBetweenParams) ([]EvidenceBetweenRow, error)
|
||||
ExtendOrgPurge(ctx context.Context, orgID uuid.UUID) error
|
||||
// System scope: resolves a request to a page by verified custom domain or
|
||||
// by slug.
|
||||
FindPublishedPage(ctx context.Context, arg FindPublishedPageParams) (StatusPage, error)
|
||||
FinishOrgPurge(ctx context.Context, orgID uuid.UUID) error
|
||||
// Alerts of org that fire and were repeated within the stale period.
|
||||
FiringAlerts(ctx context.Context, arg FiringAlertsParams) ([]FiringAlertsRow, error)
|
||||
// FiringAlerts newest first, a page from a keyset cursor (see paging.go)
|
||||
@@ -323,6 +328,7 @@ type Querier interface {
|
||||
OpenIncidents(ctx context.Context, orgID uuid.UUID) ([]Incident, error)
|
||||
OrgAssignmentsExport(ctx context.Context, orgID uuid.UUID) ([]OrgAssignmentsExportRow, error)
|
||||
OrgAuditExport(ctx context.Context, orgID uuid.UUID) ([]OrgAuditExportRow, error)
|
||||
OrgCheckDataChunks(ctx context.Context) ([]string, error)
|
||||
OrgDailyStats(ctx context.Context, orgID uuid.UUID) ([]OrgDailyStatsRow, error)
|
||||
OrgIDBySlug(ctx context.Context, slug string) (uuid.UUID, error)
|
||||
OrgIncidentUpdatesExport(ctx context.Context, orgID uuid.UUID) ([]OrgIncidentUpdatesExportRow, error)
|
||||
@@ -347,13 +353,15 @@ type Querier interface {
|
||||
PurgeInvitations(ctx context.Context, expiresAt time.Time) (int64, error)
|
||||
// Delivered and given-up notifications; pending ones are still being worked.
|
||||
PurgeNotifications(ctx context.Context, createdAt time.Time) (int64, error)
|
||||
PurgeOrgCheckData(ctx context.Context, org uuid.UUID) error
|
||||
PurgeOrgCheckChunk(ctx context.Context, arg PurgeOrgCheckChunkParams) (int64, error)
|
||||
PurgeSubscriberNotifications(ctx context.Context, createdAt time.Time) (int64, error)
|
||||
// Unconfirmed subscriptions are kept for as long as they count towards the
|
||||
// weekly limit, so letting them lapse frees no room for more.
|
||||
PurgeUnconfirmedSubscribers(ctx context.Context, createdAt time.Time) (int64, error)
|
||||
// Accounts never confirmed; they belong to no organization.
|
||||
PurgeUnverifiedUsers(ctx context.Context, createdAt time.Time) (int64, error)
|
||||
// System scope: has the check data of a deleted organization purged.
|
||||
QueueOrgPurge(ctx context.Context, orgID uuid.UUID) error
|
||||
// Raw results bucketed by width since a point in time, for short ranges.
|
||||
RangeBuckets(ctx context.Context, arg RangeBucketsParams) ([]RangeBucketsRow, error)
|
||||
// The daily aggregate rebucketed by width, for ranges of months.
|
||||
|
||||
@@ -49,9 +49,6 @@ UPDATE audit_events SET details = details - 'email' WHERE lower(details->>'email
|
||||
-- name: DeleteInvitationsForEmail :exec
|
||||
DELETE FROM invitations WHERE email = $1;
|
||||
|
||||
-- name: PurgeOrgCheckData :exec
|
||||
SELECT purge_org_check_data($1);
|
||||
|
||||
-- name: DeleteOrgStorage :exec
|
||||
DELETE FROM agent_storage WHERE owner = 'org:' || sqlc.arg(org_id)::uuid::text;
|
||||
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
-- name: QueueOrgPurge :exec
|
||||
-- System scope: has the check data of a deleted organization purged.
|
||||
INSERT INTO org_purges (org_id) VALUES ($1) ON CONFLICT DO NOTHING;
|
||||
|
||||
-- name: ClaimOrgPurge :one
|
||||
-- System scope: leases the longest waiting purge no other instance holds.
|
||||
UPDATE org_purges SET leased_until = now() + interval '15 minutes'
|
||||
WHERE org_id = (
|
||||
SELECT org_id FROM org_purges WHERE leased_until < now()
|
||||
ORDER BY requested_at LIMIT 1
|
||||
FOR UPDATE SKIP LOCKED
|
||||
)
|
||||
RETURNING org_id;
|
||||
|
||||
-- name: ExtendOrgPurge :exec
|
||||
UPDATE org_purges SET leased_until = now() + interval '15 minutes' WHERE org_id = $1;
|
||||
|
||||
-- name: FinishOrgPurge :exec
|
||||
DELETE FROM org_purges WHERE org_id = $1;
|
||||
|
||||
-- name: CountOrgPurges :one
|
||||
SELECT count(*) FROM org_purges;
|
||||
|
||||
-- name: OrgCheckDataChunks :many
|
||||
SELECT chunk::text FROM org_check_data_chunks() AS chunk;
|
||||
|
||||
-- name: PurgeOrgCheckChunk :one
|
||||
SELECT purge_org_check_chunk(sqlc.arg(org_id)::uuid, sqlc.arg(chunk)::text)::bigint AS rows;
|
||||
+90
-117
@@ -31,104 +31,33 @@ type PublicAssets struct {
|
||||
Now time.Time
|
||||
// NoRefresh leaves out the periodic reload, on pages with a form.
|
||||
NoRefresh bool
|
||||
// PageSize is how many of a section's own components the page lists
|
||||
// at a time; 0 lists all, as in a single-file export.
|
||||
// PageSize is how many components the page lists at a time; 0 lists
|
||||
// all, as in a single-file export.
|
||||
PageSize int
|
||||
// Pages holds the zero-based page shown of the sections paged, by
|
||||
// their PublicSection.Key.
|
||||
Pages map[string]int
|
||||
// Query is what the visitor searched the components for; OnlyProblems
|
||||
// keeps those with an outage or degraded.
|
||||
Query string
|
||||
OnlyProblems bool
|
||||
// Page is the zero-based page of components to show and Query what the
|
||||
// visitor searched them for.
|
||||
Page int
|
||||
Query string
|
||||
}
|
||||
|
||||
// PublicSection is a section of a status page as a request for it shows
|
||||
// it: the components of one page of the section's own, its status and
|
||||
// count those of the whole section.
|
||||
type PublicSection struct {
|
||||
Name string
|
||||
Status string
|
||||
Total int
|
||||
// Key identifies the section in the URLs paging it, e.g. "0.2".
|
||||
Key string
|
||||
Components []agentapi.Component
|
||||
Children []PublicSection
|
||||
// Page is the zero-based page of the section's own components shown,
|
||||
// of Pages.
|
||||
// ComponentPage is the part of a status page's components one page of it
|
||||
// lists: the sections holding them, keeping the status and count of the
|
||||
// whole section.
|
||||
type ComponentPage struct {
|
||||
Sections []agentapi.Section
|
||||
// Page is the zero-based page shown, of Pages; Matches counts the
|
||||
// components the query found, of all of them.
|
||||
Page, Pages int
|
||||
Matches int
|
||||
Query string
|
||||
}
|
||||
|
||||
// ComponentView is what a request for a status page shows of its
|
||||
// components: every section paged on its own, filtered by a search and to
|
||||
// those with problems if the visitor asked.
|
||||
type ComponentView struct {
|
||||
Sections []PublicSection
|
||||
// Total counts all components, Matches those the filters leave and
|
||||
// Problems those with an outage or degraded.
|
||||
Total, Matches, Problems int
|
||||
Query string
|
||||
OnlyProblems bool
|
||||
|
||||
base string
|
||||
size int
|
||||
pages map[string]int
|
||||
}
|
||||
|
||||
// Filterable reports whether the page lists enough components to offer the
|
||||
// search and filter, or uses them.
|
||||
func (v ComponentView) Filterable() bool {
|
||||
return v.size > 0 && v.Total > v.size || v.Query != "" || v.OnlyProblems
|
||||
}
|
||||
|
||||
// Filtered reports whether a search or filter is in use.
|
||||
func (v ComponentView) Filtered() bool { return v.Query != "" || v.OnlyProblems }
|
||||
|
||||
// PageHref links page of the section key, keeping the other sections' pages
|
||||
// and the filters.
|
||||
func (v ComponentView) PageHref(key string, page int) string {
|
||||
q := url.Values{}
|
||||
if v.Query != "" {
|
||||
q.Set("q", v.Query)
|
||||
}
|
||||
if v.OnlyProblems {
|
||||
q.Set("problems", "1")
|
||||
}
|
||||
for k, p := range v.pages {
|
||||
if k != key && p > 0 {
|
||||
q.Set("p."+k, strconv.Itoa(p+1))
|
||||
}
|
||||
}
|
||||
if page > 0 {
|
||||
q.Set("p."+key, strconv.Itoa(page+1))
|
||||
}
|
||||
href := BackHref(v.base)
|
||||
if len(q) > 0 {
|
||||
href += "?" + q.Encode()
|
||||
}
|
||||
return href + "#g-" + key
|
||||
}
|
||||
|
||||
// ResetHref links the page without search, filter and paging.
|
||||
func (v ComponentView) ResetHref() string { return BackHref(v.base) }
|
||||
|
||||
// Problem reports whether a component counts as an outage for the filter.
|
||||
func Problem(c agentapi.Component) bool {
|
||||
return c.Status == agentapi.PageOutage || c.Status == agentapi.PageDegraded
|
||||
}
|
||||
|
||||
// PublicComponents decides which components of sections a request for the
|
||||
// page shows, as a.Query, a.OnlyProblems and a.Pages ask.
|
||||
func PublicComponents(sections []agentapi.Section, a PublicAssets) ComponentView {
|
||||
v := ComponentView{
|
||||
Query: strings.TrimSpace(a.Query), OnlyProblems: a.OnlyProblems,
|
||||
base: a.ComponentBase, size: a.PageSize, pages: a.Pages,
|
||||
}
|
||||
needle := strings.ToLower(v.Query)
|
||||
// PageComponents picks the components of page from sections, of those whose
|
||||
// name or section contains query. size 0 shows all of them.
|
||||
func PageComponents(sections []agentapi.Section, page, size int, query string) ComponentPage {
|
||||
query = strings.TrimSpace(query)
|
||||
needle := strings.ToLower(query)
|
||||
match := func(path []string, c agentapi.Component) bool {
|
||||
if v.OnlyProblems && !Problem(c) {
|
||||
return false
|
||||
}
|
||||
if needle == "" || strings.Contains(strings.ToLower(c.Name), needle) {
|
||||
return true
|
||||
}
|
||||
@@ -139,46 +68,90 @@ func PublicComponents(sections []agentapi.Section, a PublicAssets) ComponentView
|
||||
}
|
||||
return false
|
||||
}
|
||||
filtered := v.Filtered()
|
||||
var walk func(sec agentapi.Section, key string, path []string) (PublicSection, bool)
|
||||
walk = func(sec agentapi.Section, key string, path []string) (PublicSection, bool) {
|
||||
ps := PublicSection{Name: sec.Name, Status: secStatusName(sec), Total: SectionTotal(sec), Key: key, Pages: 1}
|
||||
// Components are counted in the order the page renders them: a
|
||||
// section's own, then its children's. Unnamed sections are top-level
|
||||
// lists without children.
|
||||
var count func(sec agentapi.Section, path []string) int
|
||||
count = func(sec agentapi.Section, path []string) int {
|
||||
if sec.Name != "" {
|
||||
path = append(path, sec.Name)
|
||||
}
|
||||
var own []agentapi.Component
|
||||
n := 0
|
||||
for _, c := range sec.Components {
|
||||
v.Total++
|
||||
if Problem(c) {
|
||||
v.Problems++
|
||||
}
|
||||
if match(path, c) {
|
||||
own = append(own, c)
|
||||
n++
|
||||
}
|
||||
}
|
||||
v.Matches += len(own)
|
||||
if v.size > 0 && len(own) > v.size {
|
||||
ps.Pages = (len(own) + v.size - 1) / v.size
|
||||
ps.Page = min(max(v.pages[key], 0), ps.Pages-1)
|
||||
own = own[ps.Page*v.size : min((ps.Page+1)*v.size, len(own))]
|
||||
}
|
||||
ps.Components = own
|
||||
// Unnamed sections are top-level lists without children.
|
||||
if sec.Name != "" {
|
||||
for i, child := range sec.Children {
|
||||
if c, ok := walk(child, key+"."+strconv.Itoa(i), path); ok {
|
||||
ps.Children = append(ps.Children, c)
|
||||
for _, child := range sec.Children {
|
||||
n += count(child, path)
|
||||
}
|
||||
}
|
||||
return n
|
||||
}
|
||||
total := 0
|
||||
for _, sec := range sections {
|
||||
total += count(sec, nil)
|
||||
}
|
||||
out := ComponentPage{Pages: 1, Matches: total, Query: query}
|
||||
if needle == "" && (size <= 0 || total <= size) {
|
||||
out.Sections = sections
|
||||
return out
|
||||
}
|
||||
from, to := 0, total
|
||||
if size > 0 && total > size {
|
||||
out.Pages = (total + size - 1) / size
|
||||
out.Page = min(max(page, 0), out.Pages-1)
|
||||
from, to = out.Page*size, min((out.Page+1)*size, total)
|
||||
}
|
||||
idx := 0
|
||||
var cut func(sec agentapi.Section, path []string) (agentapi.Section, bool)
|
||||
cut = func(sec agentapi.Section, path []string) (agentapi.Section, bool) {
|
||||
part := agentapi.Section{Name: sec.Name, Status: secStatusName(sec), Total: SectionTotal(sec)}
|
||||
if sec.Name != "" {
|
||||
path = append(path, sec.Name)
|
||||
}
|
||||
for _, c := range sec.Components {
|
||||
if !match(path, c) {
|
||||
continue
|
||||
}
|
||||
if idx >= from && idx < to {
|
||||
part.Components = append(part.Components, c)
|
||||
}
|
||||
idx++
|
||||
}
|
||||
if sec.Name != "" {
|
||||
for _, child := range sec.Children {
|
||||
if p, ok := cut(child, path); ok {
|
||||
part.Children = append(part.Children, p)
|
||||
}
|
||||
}
|
||||
}
|
||||
return ps, !filtered || len(ps.Components) > 0 || len(ps.Children) > 0
|
||||
return part, len(part.Components) > 0 || len(part.Children) > 0
|
||||
}
|
||||
for i, sec := range sections {
|
||||
if ps, ok := walk(sec, strconv.Itoa(i), nil); ok {
|
||||
v.Sections = append(v.Sections, ps)
|
||||
for _, sec := range sections {
|
||||
if p, ok := cut(sec, nil); ok {
|
||||
out.Sections = append(out.Sections, p)
|
||||
}
|
||||
}
|
||||
return v
|
||||
return out
|
||||
}
|
||||
|
||||
// ComponentPageHref links page of the components of the status page at
|
||||
// base, keeping the search for query.
|
||||
func ComponentPageHref(base string, page int, query string) string {
|
||||
v := url.Values{}
|
||||
if page > 0 {
|
||||
v.Set("page", strconv.Itoa(page+1))
|
||||
}
|
||||
if query != "" {
|
||||
v.Set("q", query)
|
||||
}
|
||||
href := BackHref(base)
|
||||
if len(v) > 0 {
|
||||
href += "?" + v.Encode()
|
||||
}
|
||||
return href
|
||||
}
|
||||
|
||||
// BarPath draws the bars of one status of a chart.
|
||||
|
||||
+31
-42
@@ -94,21 +94,18 @@ templ PublicStatusPage(s agentapi.PageSnapshot, a PublicAssets) {
|
||||
<p class="text-lg font-medium">{ i18n.T(ctx, "page.status."+s.Status) }</p>
|
||||
</section>
|
||||
@pageMaintenance(i18n.T(ctx, "page.maintenance_ongoing"), s.Ongoing(a.Now))
|
||||
if v := PublicComponents(s.Sections, a); len(s.Sections) > 0 {
|
||||
if v.Filterable() {
|
||||
@publicComponentFilter(v, a)
|
||||
if cp := PageComponents(s.Sections, a.Page, a.PageSize, a.Query); len(s.Sections) > 0 {
|
||||
if cp.Pages > 1 || cp.Query != "" {
|
||||
@publicComponentSearch(cp, a)
|
||||
}
|
||||
<section class="mb-12 border-t border-rule">
|
||||
for _, sec := range v.Sections {
|
||||
@publicSection(sec, v, s, a)
|
||||
for _, sec := range cp.Sections {
|
||||
@publicSection(sec, s, a)
|
||||
}
|
||||
if v.Filtered() && v.Matches == 0 {
|
||||
if v.OnlyProblems && v.Query == "" {
|
||||
<p class="py-6 text-sm text-muted">{ i18n.T(ctx, "page.filter_no_problems") }</p>
|
||||
} else {
|
||||
<p class="py-6 text-sm text-muted">{ i18n.T(ctx, "page.search_none") }</p>
|
||||
}
|
||||
if cp.Matches == 0 {
|
||||
<p class="py-6 text-sm text-muted">{ i18n.T(ctx, "page.search_none") }</p>
|
||||
}
|
||||
@publicComponentPager(cp, a)
|
||||
</section>
|
||||
}
|
||||
@publicIncidents(s.Incidents)
|
||||
@@ -168,33 +165,29 @@ templ PublicNoticePage(s agentapi.PageSnapshot, a PublicAssets, title, message s
|
||||
}
|
||||
}
|
||||
|
||||
// publicComponentFilter searches the components of pages listing too many
|
||||
// to scan, or narrows them to those with an outage.
|
||||
templ publicComponentFilter(v ComponentView, a PublicAssets) {
|
||||
<form method="get" action={ templ.SafeURL(BackHref(a.ComponentBase)) } role="search" class="mb-4 flex flex-wrap items-center gap-x-4 gap-y-2 text-sm">
|
||||
// publicComponentSearch finds components on pages listing too many to scan.
|
||||
templ publicComponentSearch(cp ComponentPage, a PublicAssets) {
|
||||
<form method="get" action={ templ.SafeURL(BackHref(a.ComponentBase)) } role="search" class="mb-4 flex flex-wrap items-center gap-2 text-sm">
|
||||
<label class="sr-only" for="component-search">{ i18n.T(ctx, "page.search") }</label>
|
||||
<input id="component-search" type="search" name="q" value={ v.Query } maxlength="100" placeholder={ i18n.T(ctx, "page.search") } class="min-w-0 flex-1 border border-rule bg-transparent px-2 py-1.5"/>
|
||||
<label class="flex items-center gap-2">
|
||||
<input type="checkbox" name="problems" value="1" checked?={ v.OnlyProblems }/>
|
||||
<span>{ i18n.T(ctx, "page.filter_problems", "Count", v.Problems) }</span>
|
||||
</label>
|
||||
<input id="component-search" type="search" name="q" value={ cp.Query } maxlength="100" placeholder={ i18n.T(ctx, "page.search") } class="min-w-0 flex-1 border border-rule bg-transparent px-2 py-1.5"/>
|
||||
<button type="submit" class="border border-ink px-3 py-1.5 hover:bg-ink hover:text-paper">{ i18n.T(ctx, "page.search_submit") }</button>
|
||||
if v.Filtered() {
|
||||
<a href={ templ.SafeURL(v.ResetHref()) } class="text-muted hover:text-ink">{ i18n.T(ctx, "page.search_clear") }</a>
|
||||
if cp.Query != "" {
|
||||
<a href={ templ.SafeURL(BackHref(a.ComponentBase)) } class="text-muted hover:text-ink">{ i18n.T(ctx, "page.search_clear") }</a>
|
||||
}
|
||||
</form>
|
||||
}
|
||||
|
||||
// publicSectionPager turns the pages of a section's own components.
|
||||
templ publicSectionPager(sec PublicSection, v ComponentView) {
|
||||
if sec.Pages > 1 {
|
||||
<nav class="flex flex-wrap items-center gap-x-5 gap-y-2 border-b border-rule py-2 text-sm" aria-label={ i18n.T(ctx, "pager.label") }>
|
||||
if sec.Page > 0 {
|
||||
<a href={ templ.SafeURL(v.PageHref(sec.Key, sec.Page-1)) } rel="prev" class="text-muted hover:text-ink">← { i18n.T(ctx, "pager.previous") }</a>
|
||||
// publicComponentPager turns the pages of components.
|
||||
templ publicComponentPager(cp ComponentPage, a PublicAssets) {
|
||||
if cp.Pages > 1 {
|
||||
<nav class="flex flex-wrap items-center gap-x-5 gap-y-2 py-4 text-sm" aria-label={ i18n.T(ctx, "pager.label") }>
|
||||
if cp.Page > 0 {
|
||||
<a href={ templ.SafeURL(ComponentPageHref(a.ComponentBase, 0, cp.Query)) } class="text-muted hover:text-ink">{ i18n.T(ctx, "pager.first") }</a>
|
||||
<a href={ templ.SafeURL(ComponentPageHref(a.ComponentBase, cp.Page-1, cp.Query)) } rel="prev" class="text-muted hover:text-ink">← { i18n.T(ctx, "pager.previous") }</a>
|
||||
}
|
||||
<span class="font-mono text-xs text-muted">{ i18n.T(ctx, "page.pages", "Page", sec.Page+1, "Pages", sec.Pages) }</span>
|
||||
if sec.Page < sec.Pages-1 {
|
||||
<a href={ templ.SafeURL(v.PageHref(sec.Key, sec.Page+1)) } rel="next" class="ml-auto text-muted hover:text-ink">{ i18n.T(ctx, "pager.next") } →</a>
|
||||
<span class="font-mono text-xs text-muted">{ i18n.T(ctx, "page.pages", "Page", cp.Page+1, "Pages", cp.Pages) }</span>
|
||||
if cp.Page < cp.Pages-1 {
|
||||
<a href={ templ.SafeURL(ComponentPageHref(a.ComponentBase, cp.Page+1, cp.Query)) } rel="next" class="ml-auto text-muted hover:text-ink">{ i18n.T(ctx, "pager.next") } →</a>
|
||||
}
|
||||
</nav>
|
||||
}
|
||||
@@ -202,25 +195,21 @@ templ publicSectionPager(sec PublicSection, v ComponentView) {
|
||||
|
||||
// publicSection renders an unnamed root component list or a collapsible nested
|
||||
// group matching the monitor dashboard hierarchy.
|
||||
templ publicSection(sec PublicSection, v ComponentView, s agentapi.PageSnapshot, a PublicAssets) {
|
||||
templ publicSection(sec agentapi.Section, s agentapi.PageSnapshot, a PublicAssets) {
|
||||
if sec.Name == "" {
|
||||
<div id={ "g-" + sec.Key }>
|
||||
@publicComponentList(sec.Components, s, a)
|
||||
@publicSectionPager(sec, v)
|
||||
</div>
|
||||
@publicComponentList(sec.Components, s, a)
|
||||
} else {
|
||||
<details open id={ "g-" + sec.Key } class="border-b border-rule">
|
||||
<details open class="border-b border-rule">
|
||||
<summary class="flex cursor-pointer items-center gap-2.5 py-3 text-sm font-medium select-none hover:bg-rule/30">
|
||||
@statusDot(PageStatus(sec.Status))
|
||||
@statusDot(SectionStatus(sec))
|
||||
<span>{ sec.Name }</span>
|
||||
<span class="font-mono text-xs font-normal text-muted">{ strconv.Itoa(sec.Total) }</span>
|
||||
<span class="ml-auto text-xs font-normal text-muted">{ i18n.T(ctx, "page.component."+sec.Status) }</span>
|
||||
<span class="font-mono text-xs font-normal text-muted">{ strconv.Itoa(SectionTotal(sec)) }</span>
|
||||
<span class="ml-auto text-xs font-normal text-muted">{ i18n.T(ctx, "page.component."+string(secStatusName(sec))) }</span>
|
||||
</summary>
|
||||
<div class="ml-4 border-l border-rule pl-4">
|
||||
@publicComponentList(sec.Components, s, a)
|
||||
@publicSectionPager(sec, v)
|
||||
for _, child := range sec.Children {
|
||||
@publicSection(child, v, s, a)
|
||||
@publicSection(child, s, a)
|
||||
}
|
||||
</div>
|
||||
</details>
|
||||
|
||||
+778
-834
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user