Runs (migration 0011): a run groups the cycles of one launch. It opens when an address enters an idle queue, takes everything submitted or re-checked while it is open and is finalized when all its addresses are done; a re-check after that opens a new run, so results of different runs never mix. check_runs, run_results (one result per address and run, with the verdict and the expected and stored check counts), subnets, run_id on ip_queue and checks. Existing data is split into runs at pauses of more than an hour; ingress checks get the validator that held the address (also at write time from now on). Analytics (internal/analytics): figures computed from the stored checks of the latest cycle of each address in the run, as facts next to the verdict: summary, reasons of partial, data quality, subnets, targets and the subnet x target matrix by check type, ingress by site, error classes, validators, and the address lists behind the indicators and error classes. API: analytics runs, report, lists (JSON or CSV), subnet list; run and subnet filters for the registry. Dashboard: /analytics matching the approved mockup (run selector, indicators with address lists and CSV, error-class dialogs, drill-down to the registry), subnet list on /settings. Sidebar: the control-api link state, theme toggle and logout moved to the top, the three dots next to the logo removed, sections grouped. Rebuilt bin/control-api and bin/admin-dashboard to match. Plan, summary and the updated README, API, USAGE, DASHBOARD and ADMIN_CLEANUP docs are in docs/. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
103 lines
3.1 KiB
Go
103 lines
3.1 KiB
Go
package dashboard
|
|
|
|
import (
|
|
"net/http"
|
|
"net/netip"
|
|
"net/url"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
type registryPageData struct {
|
|
PageData
|
|
Items []registryItem
|
|
Query string
|
|
StatusFilter string
|
|
Run int64 // drill-down from the analytics page
|
|
Subnet string
|
|
Page, PerPage int
|
|
Total int
|
|
Pager pagerData
|
|
PerPageOptions []int
|
|
}
|
|
|
|
type registryDetailData struct {
|
|
PageData
|
|
History registryHistoryResponse
|
|
}
|
|
|
|
// handleRegistryPage lists every address ever submitted to the check
|
|
// queue, with a summary of its accumulated check history — the durable
|
|
// record that survives an address being deleted from /ips and later
|
|
// re-added. See internal/db/migrations/0007_ip_registry.sql. Optional
|
|
// ?q=&status= query params narrow the list by address substring and by
|
|
// LastResult, and ?page=&per_page= select a page — all applied server-side
|
|
// (control-api's ListRegistryPage), so only the visible rows are transferred.
|
|
func (s *Server) handleRegistryPage(w http.ResponseWriter, r *http.Request) {
|
|
q := strings.TrimSpace(r.URL.Query().Get("q"))
|
|
status := r.URL.Query().Get("status")
|
|
if !containsStr(ipResults, status) {
|
|
status = ""
|
|
}
|
|
perPage := parsePerPage(r.URL.Query().Get("per_page"))
|
|
page := parsePage(r.URL.Query().Get("page"))
|
|
run, _ := strconv.ParseInt(r.URL.Query().Get("run"), 10, 64)
|
|
if run < 0 {
|
|
run = 0
|
|
}
|
|
subnet := strings.TrimSpace(r.URL.Query().Get("subnet"))
|
|
if _, err := netip.ParsePrefix(subnet); err != nil {
|
|
subnet = ""
|
|
}
|
|
query := registryQuery{Q: q, LastResult: status, Run: run, Subnet: subnet, Limit: perPage, Offset: (page - 1) * perPage}
|
|
|
|
res, err := s.CA.ListRegistryPage(r.Context(), query)
|
|
if err == nil {
|
|
if clamped := clampPage(page, res.Total, perPage); clamped != page {
|
|
page = clamped
|
|
query.Offset = (page - 1) * perPage
|
|
res, err = s.CA.ListRegistryPage(r.Context(), query)
|
|
}
|
|
}
|
|
params := url.Values{}
|
|
if q != "" {
|
|
params.Set("q", q)
|
|
}
|
|
if status != "" {
|
|
params.Set("status", status)
|
|
}
|
|
if run > 0 {
|
|
params.Set("run", strconv.FormatInt(run, 10))
|
|
}
|
|
if subnet != "" {
|
|
params.Set("subnet", subnet)
|
|
}
|
|
data := registryPageData{
|
|
Run: run,
|
|
Subnet: subnet,
|
|
Items: res.Items,
|
|
Query: q,
|
|
StatusFilter: status,
|
|
Page: page,
|
|
PerPage: perPage,
|
|
Total: res.Total,
|
|
Pager: newPager("/registry", "registry-table-wrap", params, page, perPage, res.Total),
|
|
PerPageOptions: perPageOptions,
|
|
}
|
|
data.ActiveNav = "registry"
|
|
data.Banner = bannerFor(err)
|
|
s.renderPage(w, r, "registry_page", data)
|
|
}
|
|
|
|
// handleRegistryDetail shows one address's full retained check history
|
|
// across every cycle it has ever run, not just the current attempt — see
|
|
// ip_detail_content in ip_detail.html for the attempt-scoped equivalent.
|
|
func (s *Server) handleRegistryDetail(w http.ResponseWriter, r *http.Request) {
|
|
ip := r.PathValue("ip")
|
|
history, err := s.CA.GetRegistryHistory(r.Context(), ip)
|
|
data := registryDetailData{History: history}
|
|
data.ActiveNav = "registry"
|
|
data.Banner = bannerFor(err)
|
|
s.renderPage(w, r, "registry_detail_page", data)
|
|
}
|