Show collapsible IP check cycles in the registry

This commit is contained in:
ayurishchev committed 2026-11-23 11:53:08 +03:00
1 parent 94124747ce
commit b58d5f5b82
16 files changed
+332 -36

No files matched your search

+24 -4
View File
@@ -1,6 +1,8 @@
package httpapi
import (
"database/sql"
"errors"
"fmt"
"net/http"
"net/netip"
@@ -111,11 +113,29 @@ func (s *Server) handleAdminRegistryHistory(w http.ResponseWriter, r *http.Reque
writeError(w, http.StatusInternalServerError, err.Error())
return
}
events, err := s.DB.ListEventsForRegistry(r.Context(), summary.ID)
if err != nil {
writeDBError(w, err)
return
}
cycles, err := s.DB.ListRegistryCycles(r.Context(), summary.ID)
if err != nil {
writeDBError(w, err)
return
}
currentIP, err := s.DB.GetIPByAddress(r.Context(), summary.IPAddress)
if err != nil && !errors.Is(err, sql.ErrNoRows) {
writeDBError(w, err)
return
}
writeJSON(w, http.StatusOK, struct {
Registry registryDTO `json:"registry"`
Checks []db.Check `json:"checks"`
SelfCheckFailedOn []string `json:"self_check_failed_on"`
}{registrySummaryToDTO(*summary), checks, failedOn})
Registry registryDTO `json:"registry"`
Checks []db.Check `json:"checks"`
SelfCheckFailedOn []string `json:"self_check_failed_on"`
Events []db.Event `json:"events"`
Cycles []db.RegistryCycle `json:"cycles"`
CurrentIP *db.IPQueueItem `json:"current_ip,omitempty"`
}{registrySummaryToDTO(*summary), checks, failedOn, events, cycles, currentIP})
}
func registrySummaryToDTO(s db.RegistrySummary) registryDTO {
+21 -2
View File
@@ -106,8 +106,11 @@ func TestRegistryHistoryOutlivesIPDeletion(t *testing.T) {
t.Fatalf("registry history: status=%d body=%s", resp.StatusCode, body)
}
var hist struct {
Registry registryDTO `json:"registry"`
Checks []db.Check `json:"checks"`
Registry registryDTO `json:"registry"`
Checks []db.Check `json:"checks"`
Events []db.Event `json:"events"`
Cycles []db.RegistryCycle `json:"cycles"`
CurrentIP *db.IPQueueItem `json:"current_ip"`
}
if err := json.Unmarshal(body, &hist); err != nil {
t.Fatalf("unmarshal registry history: %v", err)
@@ -121,6 +124,18 @@ func TestRegistryHistoryOutlivesIPDeletion(t *testing.T) {
if hist.Registry.InQueue {
t.Fatalf("expected registry entry to report not-in-queue after delete, got %+v", hist.Registry)
}
if hist.CurrentIP != nil || len(hist.Cycles) != 1 || hist.Cycles[0].CycleID != item.CycleID ||
hist.Cycles[0].RunID == 0 || hist.Cycles[0].Verdict != item.OverallResult || hist.Cycles[0].AggregatedAt == nil {
t.Fatalf("expected archived cycle with its own verdict and timestamp, got %+v", hist.Cycles)
}
if len(hist.Events) == 0 {
t.Fatal("expected archived events")
}
for _, event := range hist.Events {
if event.CycleID != item.CycleID || event.IPID != nil {
t.Fatalf("event should stay attached to the archived cycle, got %+v", event)
}
}
// Resubmitting starts a second, distinct cycle on the same registry
// entry rather than colliding with the first.
@@ -141,6 +156,10 @@ func TestRegistryHistoryOutlivesIPDeletion(t *testing.T) {
if !hist.Registry.InQueue {
t.Fatalf("expected registry entry to report in-queue again, got %+v", hist.Registry)
}
if hist.CurrentIP == nil || len(hist.Cycles) != 2 || hist.Cycles[0].CycleID != hist.CurrentIP.CycleID ||
hist.Cycles[1].CycleID != item.CycleID || hist.Cycles[0].RunID == hist.Cycles[1].RunID {
t.Fatalf("expected current and archived cycles from different runs, got %+v", hist.Cycles)
}
_, body = fc.do(http.MethodGet, "/api/v1/admin/registry", nil)
var all []registryDTO