feat: page long and truncated lists
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:
1 parent
98fb5d3a82
commit
d7c5cd711e
63 files changed
+5427
-3041
No files matched your search
+55
-15
@@ -131,22 +131,29 @@ func (s *Server) listEvidence(c *gin.Context) {
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
pg, ok := parsePage(c, apiPageSize)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
ctx := c.Request.Context()
|
||||
var rows []store.ListEvidenceRow
|
||||
err := s.db.Tx(ctx, current(c).scope(), func(q *store.Queries) error {
|
||||
var err error
|
||||
rows, err = q.ListEvidence(ctx, m.ID)
|
||||
rows, err = q.ListEvidence(ctx, store.ListEvidenceParams{
|
||||
MonitorID: m.ID, AfterT: pg.afterT(), AfterID: pg.afterID(), BeforeT: pg.beforeT(), BeforeID: pg.beforeID(), MaxRows: pg.fetch(),
|
||||
})
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
internalError(c, err)
|
||||
return
|
||||
}
|
||||
rows, info := paginate(pg, rows, func(r store.ListEvidenceRow) cursor { return cursor{T: r.Time, ID: r.ID} })
|
||||
out := make([]evidenceSummary, len(rows))
|
||||
for i, r := range rows {
|
||||
out[i] = evidenceSummary{ID: r.ID, Region: r.Region, Time: r.Time, OK: r.Ok, StatusCode: r.StatusCode, Error: r.Error}
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"evidence": out})
|
||||
c.JSON(http.StatusOK, gin.H{"evidence": out, "next_cursor": info.Next, "prev_cursor": info.Prev})
|
||||
}
|
||||
|
||||
func (s *Server) loadEvidence(c *gin.Context, m store.Monitor) (store.CheckEvidence, check.Evidence, bool) {
|
||||
@@ -295,32 +302,65 @@ func prettyBody(contentType, body string) string {
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
// evidenceRows lists stored evidence of m for its page.
|
||||
func (s *Server) evidenceRows(ctx context.Context, p *principal, d monitorData, m store.Monitor) ([]web.EvidenceRow, map[string]string, error) {
|
||||
// evidenceShown is how much of a monitor's evidence its page lists.
|
||||
const evidenceShown = 20
|
||||
|
||||
// evidenceRows lists the latest stored evidence of m for its page.
|
||||
func (s *Server) evidenceRows(ctx context.Context, p *principal, d monitorData, m store.Monitor) ([]web.EvidenceRow, error) {
|
||||
var rows []store.ListEvidenceRow
|
||||
err := s.db.Tx(ctx, p.scope(), func(q *store.Queries) error {
|
||||
var err error
|
||||
rows, err = q.ListEvidence(ctx, m.ID)
|
||||
rows, err = q.ListEvidence(ctx, store.ListEvidenceParams{MonitorID: m.ID, MaxRows: evidenceShown})
|
||||
return err
|
||||
})
|
||||
byResult := map[string]string{}
|
||||
out := make([]web.EvidenceRow, 0, min(len(rows), 20))
|
||||
for i, r := range rows {
|
||||
url := "/monitors/" + m.ID.String() + "/evidence/" + r.ID.String()
|
||||
byResult[evidenceKey(r.Region, r.Time)] = url
|
||||
if i >= 20 {
|
||||
continue
|
||||
}
|
||||
out := make([]web.EvidenceRow, 0, len(rows))
|
||||
for _, r := range rows {
|
||||
detail := deref(r.Error)
|
||||
if detail == "" && r.StatusCode != nil {
|
||||
detail = strconv.Itoa(int(*r.StatusCode))
|
||||
}
|
||||
out = append(out, web.EvidenceRow{URL: url, Time: r.Time.Local().Format("01-02 15:04:05"), Region: d.regionNameString(r.Region), OK: r.Ok, Detail: detail})
|
||||
out = append(out, web.EvidenceRow{
|
||||
URL: "/monitors/" + m.ID.String() + "/evidence/" + r.ID.String(), Time: r.Time.Local().Format("01-02 15:04:05"),
|
||||
Region: d.regionNameString(r.Region), OK: r.Ok, Detail: detail,
|
||||
})
|
||||
}
|
||||
return out, byResult, err
|
||||
return out, err
|
||||
}
|
||||
|
||||
// evidenceKey matches evidence with the check result it belongs to.
|
||||
func evidenceKey(region string, t time.Time) string {
|
||||
return region + "@" + strconv.FormatInt(t.UnixMicro(), 10)
|
||||
}
|
||||
|
||||
// resultView is one check result.
|
||||
type resultView struct {
|
||||
Time time.Time `json:"time"`
|
||||
Region string `json:"region"`
|
||||
CheckerID uuid.UUID `json:"checker_id"`
|
||||
OK bool `json:"ok"`
|
||||
LatencyMS *int32 `json:"latency_ms"`
|
||||
StatusCode *int32 `json:"status_code,omitempty"`
|
||||
Error *string `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
// listResults pages through a monitor's check results, newest first.
|
||||
func (s *Server) listResults(c *gin.Context) {
|
||||
m, _, ok := s.evidenceMonitor(c)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
pg, ok := parsePage(c, apiPageSize)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
rows, info, err := s.resultPage(c.Request.Context(), current(c), m, pg)
|
||||
if err != nil {
|
||||
internalError(c, err)
|
||||
return
|
||||
}
|
||||
out := make([]resultView, len(rows))
|
||||
for i, r := range rows {
|
||||
out[i] = resultView{r.Time, r.Region, r.CheckerID, r.Ok, r.LatencyMs, r.StatusCode, r.Error}
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"results": out, "next_cursor": info.Next, "prev_cursor": info.Prev})
|
||||
}
|
||||
Reference in new issue
Block a user