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
@@ -327,22 +327,34 @@ type alertMonitorRef struct {
|
||||
|
||||
// firingAlertViews lists the organization's firing alerts and which
|
||||
// monitors they hold down, so alerts no monitor follows stand out.
|
||||
func (s *Server) firingAlertViews(ctx context.Context, p *principal) ([]alertView, error) {
|
||||
// firingAlertViews reads a page of firing alerts, newest first, with the
|
||||
// monitors they match.
|
||||
func (s *Server) firingAlertViews(ctx context.Context, p *principal, pg pageReq) ([]alertView, pageInfo, error) {
|
||||
now := time.Now()
|
||||
var (
|
||||
alerts []firingAlert
|
||||
rows []store.FiringAlertsPageRow
|
||||
monitors []store.AlertmanagerMonitorsRow
|
||||
)
|
||||
err := s.db.Tx(ctx, p.scope(), func(q *store.Queries) error {
|
||||
var err error
|
||||
if alerts, err = loadFiringAlerts(ctx, q, p.Org.ID, now.Add(-time.Duration(check.DefaultStaleHours)*time.Hour)); err != nil {
|
||||
if rows, err = q.FiringAlertsPage(ctx, store.FiringAlertsPageParams{
|
||||
OrgID: p.Org.ID, Since: now.Add(-time.Duration(check.DefaultStaleHours) * time.Hour),
|
||||
AfterT: pg.afterT(), AfterS: pg.afterS(), BeforeT: pg.beforeT(), BeforeS: pg.beforeS(), MaxRows: pg.fetch(),
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
monitors, err = q.AlertmanagerMonitors(ctx, &p.Org.ID)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, pageInfo{}, err
|
||||
}
|
||||
rows, info := paginate(pg, rows, func(r store.FiringAlertsPageRow) cursor { return cursor{T: r.StartsAt, S: r.Fingerprint} })
|
||||
alerts := make([]firingAlert, len(rows))
|
||||
for i, r := range rows {
|
||||
alerts[i] = firingAlert{Fingerprint: r.Fingerprint, StartsAt: r.StartsAt, UpdatedAt: r.UpdatedAt, GeneratorURL: r.GeneratorUrl}
|
||||
_ = json.Unmarshal(r.Labels, &alerts[i].Labels)
|
||||
_ = json.Unmarshal(r.Annotations, &alerts[i].Annotations)
|
||||
}
|
||||
out := make([]alertView, len(alerts))
|
||||
for i, a := range alerts {
|
||||
@@ -355,16 +367,20 @@ func (s *Server) firingAlertViews(ctx context.Context, p *principal) ([]alertVie
|
||||
}
|
||||
}
|
||||
}
|
||||
return out, nil
|
||||
return out, info, nil
|
||||
}
|
||||
|
||||
func (s *Server) listFiringAlerts(c *gin.Context) {
|
||||
out, err := s.firingAlertViews(c.Request.Context(), current(c))
|
||||
pg, ok := parsePage(c, apiPageSize)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
out, info, err := s.firingAlertViews(c.Request.Context(), current(c), pg)
|
||||
if err != nil {
|
||||
internalError(c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"alerts": out})
|
||||
c.JSON(http.StatusOK, gin.H{"alerts": out, "next_cursor": info.Next, "prev_cursor": info.Prev})
|
||||
}
|
||||
|
||||
// suggestedMatchers proposes matchers for a monitor following a: its
|
||||
@@ -384,11 +400,15 @@ func suggestedMatchers(a firingAlert) []check.Matcher {
|
||||
|
||||
func (s *Server) alertmanagerPage(c *gin.Context, p *principal, page web.Page, me web.Me) (templ.Component, error) {
|
||||
ctx := c.Request.Context()
|
||||
alerts, err := s.firingAlertViews(ctx, p)
|
||||
pg, ok := parsePage(c, consolePageSize)
|
||||
if !ok {
|
||||
return nil, errAborted
|
||||
}
|
||||
alerts, info, err := s.firingAlertViews(ctx, p, pg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
v := web.AlertmanagerView{CanManage: p.Grants.Can(authz.OrgManage)}
|
||||
v := web.AlertmanagerView{CanManage: p.Grants.Can(authz.OrgManage), Pager: pager(c, info)}
|
||||
for _, a := range alerts {
|
||||
row := web.AlertRow{
|
||||
Name: a.Labels["alertname"], Summary: a.Annotations["summary"],
|
||||
|
||||
Reference in new issue
Block a user