feat: page long and truncated lists
ci / image (pull_request) Successful in 3m18s
ci / build (pull_request) Successful in 8m38s
ci / test (pull_request) Successful in 12m6s
ci / lint (pull_request) Successful in 15m0s

Lists that were cut off by a fixed LIMIT, or could grow without bound,
are paged by keyset: the cursor holds the sort key and an ID, so pages
neither skip nor repeat items as others are added. The audit logs had a
timestamp-only cursor that could skip entries with equal times.

The API returns at most 100 items per list (limit takes up to 500) with
next_cursor and prev_cursor, passed back as after and before. The
console shows Newer/Older (or Previous/Next) links and To the start,
without JavaScript.

Paged: incidents (optionally of one monitor), a monitor's results and
evidence, a checker's results, the audit logs, members, maintenance
windows, firing Alertmanager alerts, the monitors API and the admin
lists of status pages and organizations, which move to their own admin
pages. A monitor's page shows its latest incidents and results and links
to all of them. The dashboard caps every group at 50 of its own monitors
with a link to a paged view of the group, and gains a search by name or
target. Lists filtered by permission after reading may show fewer items
on a page.

Closes #116

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-22 21:40:25 +01:00
1 parent 98fb5d3a82
commit d7c5cd711e
63 files changed
+5427 -3041

No files matched your search

+102 -57
View File
@@ -343,6 +343,82 @@ func (q *Queries) LatestResultsForMonitor(ctx context.Context, arg LatestResults
return items, nil
}
const listResults = `-- name: ListResults :many
SELECT time, region, ok, latency_ms, status_code, error, checker_id,
(region || '|' || checker_id::text)::text AS position
FROM check_results
WHERE org_id = $1 AND monitor_id = $2
AND ($3::timestamptz IS NULL
OR time <= $3 AND (time, region || '|' || checker_id::text) < ($3, $4::text))
AND ($5::timestamptz IS NULL
OR time >= $5 AND (time, region || '|' || checker_id::text) > ($5, $6::text))
ORDER BY
CASE WHEN $5::timestamptz IS NULL THEN time END DESC,
CASE WHEN $5::timestamptz IS NULL THEN region || '|' || checker_id::text END DESC,
time, region || '|' || checker_id::text
LIMIT $7
`
type ListResultsParams struct {
OrgID uuid.UUID
MonitorID uuid.UUID
AfterT *time.Time
AfterS *string
BeforeT *time.Time
BeforeS *string
MaxRows int32
}
type ListResultsRow struct {
Time time.Time
Region string
Ok bool
LatencyMs *int32
StatusCode *int32
Error *string
CheckerID uuid.UUID
Position string
}
// A monitor's results newest first, a page from a keyset cursor (see
// paging.go) whose string key is region and checker.
func (q *Queries) ListResults(ctx context.Context, arg ListResultsParams) ([]ListResultsRow, error) {
rows, err := q.db.Query(ctx, listResults,
arg.OrgID,
arg.MonitorID,
arg.AfterT,
arg.AfterS,
arg.BeforeT,
arg.BeforeS,
arg.MaxRows,
)
if err != nil {
return nil, err
}
defer rows.Close()
items := []ListResultsRow{}
for rows.Next() {
var i ListResultsRow
if err := rows.Scan(
&i.Time,
&i.Region,
&i.Ok,
&i.LatencyMs,
&i.StatusCode,
&i.Error,
&i.CheckerID,
&i.Position,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const rangeBuckets = `-- name: RangeBuckets :many
SELECT monitor_id, time_bucket($2::text::interval, time)::timestamptz AS bucket,
count(*)::bigint AS total, count(*) FILTER (WHERE ok)::bigint AS ok_count,
@@ -517,58 +593,6 @@ func (q *Queries) RangeBucketsHourly(ctx context.Context, arg RangeBucketsHourly
return items, nil
}
const recentResults = `-- name: RecentResults :many
SELECT time, region, ok, latency_ms, status_code, error, checker_id
FROM check_results
WHERE org_id = $1 AND monitor_id = $2 AND time > $3
ORDER BY time DESC
LIMIT 500
`
type RecentResultsParams struct {
OrgID uuid.UUID
MonitorID uuid.UUID
Time time.Time
}
type RecentResultsRow struct {
Time time.Time
Region string
Ok bool
LatencyMs *int32
StatusCode *int32
Error *string
CheckerID uuid.UUID
}
func (q *Queries) RecentResults(ctx context.Context, arg RecentResultsParams) ([]RecentResultsRow, error) {
rows, err := q.db.Query(ctx, recentResults, arg.OrgID, arg.MonitorID, arg.Time)
if err != nil {
return nil, err
}
defer rows.Close()
items := []RecentResultsRow{}
for rows.Next() {
var i RecentResultsRow
if err := rows.Scan(
&i.Time,
&i.Region,
&i.Ok,
&i.LatencyMs,
&i.StatusCode,
&i.Error,
&i.CheckerID,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const regionBuckets = `-- name: RegionBuckets :many
SELECT region, time_bucket($2::text::interval, time)::timestamptz AS bucket,
count(*)::bigint AS total, count(*) FILTER (WHERE ok)::bigint AS ok_count
@@ -732,14 +756,26 @@ func (q *Queries) RegionBucketsHourly(ctx context.Context, arg RegionBucketsHour
const resultsByChecker = `-- name: ResultsByChecker :many
SELECT r.time, r.monitor_id, r.region, r.ok, r.latency_ms, r.status_code, r.error
FROM check_results r
WHERE r.org_id = $1 AND r.checker_id = $2 AND r.time > now() - interval '1 day'
ORDER BY r.time DESC
LIMIT 50
WHERE r.org_id = $1 AND r.checker_id = $2
AND ($3::timestamptz IS NULL
OR r.time <= $3 AND (r.time, r.monitor_id::text || '|' || r.region) < ($3, $4::text))
AND ($5::timestamptz IS NULL
OR r.time >= $5 AND (r.time, r.monitor_id::text || '|' || r.region) > ($5, $6::text))
ORDER BY
CASE WHEN $5::timestamptz IS NULL THEN r.time END DESC,
CASE WHEN $5::timestamptz IS NULL THEN r.monitor_id::text || '|' || r.region END DESC,
r.time, r.monitor_id::text || '|' || r.region
LIMIT $7
`
type ResultsByCheckerParams struct {
OrgID uuid.UUID
CheckerID uuid.UUID
AfterT *time.Time
AfterS *string
BeforeT *time.Time
BeforeS *string
MaxRows int32
}
type ResultsByCheckerRow struct {
@@ -752,9 +788,18 @@ type ResultsByCheckerRow struct {
Error *string
}
// The organization's latest results run by one checker instance.
// The organization's results run by one checker instance, newest first, a
// page from a keyset cursor whose string key is monitor and region.
func (q *Queries) ResultsByChecker(ctx context.Context, arg ResultsByCheckerParams) ([]ResultsByCheckerRow, error) {
rows, err := q.db.Query(ctx, resultsByChecker, arg.OrgID, arg.CheckerID)
rows, err := q.db.Query(ctx, resultsByChecker,
arg.OrgID,
arg.CheckerID,
arg.AfterT,
arg.AfterS,
arg.BeforeT,
arg.BeforeS,
arg.MaxRows,
)
if err != nil {
return nil, err
}