Add Floating IP scanning and a durable address registry with configurable history depth

Adds POST /api/v1/admin/ips/scan (plus an optional periodic ticker) to
discover free Floating IPs in the OpenStack project and feed them straight
into the check queue. More importantly, decouples check/event history from
ip_queue's lifecycle: a new ip_registry table (migration 0007) gives every
address ever submitted a durable identity, so deleting it from the queue no
longer destroys its history — it's still reachable via the new
GET /api/v1/admin/registry[/{ip}] endpoints and the dashboard's /registry
pages, with retention depth configurable in check cycles per address
(history_retention_cycles, 0 = unlimited).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
ayurishchevandClaude Sonnet 5 committed 2026-09-23 09:52:01 +03:00
1 parent 78b20fa5be
commit 582b44f314
47 files changed
+1781 -107

No files matched your search

+68 -5
View File
@@ -230,27 +230,44 @@ func TestSettingsGetAndPut(t *testing.T) {
t.Fatalf("expected default 0 in the form, got:\n%s", page)
}
body := postForm(t, ts, "PUT", "/settings", map[string][]string{"fip_settle_seconds": {"15"}})
if !strings.Contains(body, `value="15"`) {
t.Fatalf("expected updated value 15 in re-rendered form, got:\n%s", body)
body := postForm(t, ts, "PUT", "/settings", map[string][]string{
"fip_settle_seconds": {"15"}, "history_retention_cycles": {"10"},
})
if !strings.Contains(body, `value="15"`) || !strings.Contains(body, `value="10"`) {
t.Fatalf("expected updated values 15/10 in re-rendered form, got:\n%s", body)
}
if fake.fipSettleSeconds != 15 {
t.Fatalf("expected fake control-api settings updated, got %d", fake.fipSettleSeconds)
}
if fake.historyRetentionCycles != 10 {
t.Fatalf("expected fake control-api history_retention_cycles updated, got %d", fake.historyRetentionCycles)
}
// A control-api validation error (negative value here) surfaces via
// the banner, not a crash.
body = postForm(t, ts, "PUT", "/settings", map[string][]string{"fip_settle_seconds": {"-1"}})
body = postForm(t, ts, "PUT", "/settings", map[string][]string{
"fip_settle_seconds": {"-1"}, "history_retention_cycles": {"10"},
})
if !strings.Contains(body, "alert-warning") {
t.Fatalf("expected client error banner for invalid value, got:\n%s", body)
}
// A non-numeric value is caught by the dashboard itself before it ever
// reaches control-api.
body = postForm(t, ts, "PUT", "/settings", map[string][]string{"fip_settle_seconds": {"not-a-number"}})
body = postForm(t, ts, "PUT", "/settings", map[string][]string{
"fip_settle_seconds": {"not-a-number"}, "history_retention_cycles": {"10"},
})
if !strings.Contains(body, "alert-warning") {
t.Fatalf("expected client error banner for non-numeric value, got:\n%s", body)
}
// Same for a non-numeric retention value.
body = postForm(t, ts, "PUT", "/settings", map[string][]string{
"fip_settle_seconds": {"15"}, "history_retention_cycles": {"not-a-number"},
})
if !strings.Contains(body, "alert-warning") {
t.Fatalf("expected client error banner for non-numeric retention value, got:\n%s", body)
}
}
func TestSettingsPageShowsInboundChecks(t *testing.T) {
@@ -463,6 +480,52 @@ func TestTargetsAndCheckTypesRoundTrip(t *testing.T) {
}
}
func TestIPsScan(t *testing.T) {
fake, caURL := newFakeControlAPI(t)
fake.scanFreeAddresses = []string{"5.5.5.5"}
ts := newTestServer(t, caURL)
body := postForm(t, ts, "POST", "/ips/scan", nil)
if !strings.Contains(body, "5.5.5.5") {
t.Fatalf("expected scanned address in re-rendered table, got:\n%s", body)
}
if len(fake.ips) != 1 || fake.ips[0].IPAddress != "5.5.5.5" {
t.Fatalf("expected fake control-api queue to contain the scanned address, got %+v", fake.ips)
}
}
func TestRegistryPageAndDetail(t *testing.T) {
fake, caURL := newFakeControlAPI(t)
now := time.Now()
fake.registry["9.9.9.9"] = registryItem{
IPAddress: "9.9.9.9", FirstSeenAt: now, LastSeenAt: now,
TotalCycles: 2, LastResult: "pass", InQueue: false,
}
fake.registryChecks["9.9.9.9"] = []check{
{CycleID: 2, Source: "egress", CheckType: "https", Target: "https://example.test", Success: true, CheckedAt: now},
{CycleID: 1, Source: "egress", CheckType: "https", Target: "https://example.test", Success: false, CheckedAt: now},
}
ts := newTestServer(t, caURL)
page := get(t, ts, "/registry")
if !strings.Contains(page, "9.9.9.9") || !strings.Contains(page, "/registry/9.9.9.9") {
t.Fatalf("expected registry list to show the address with a detail link, got:\n%s", page)
}
detail := get(t, ts, "/registry/9.9.9.9")
if !strings.Contains(detail, "9.9.9.9") {
t.Fatalf("expected detail page to show the address, got:\n%s", detail)
}
if !strings.Contains(detail, "https://example.test") {
t.Fatalf("expected detail page to list retained checks, got:\n%s", detail)
}
notFound := get(t, ts, "/registry/1.2.3.4")
if !strings.Contains(notFound, "alert-warning") {
t.Fatalf("expected client error banner for unknown registry address, got:\n%s", notFound)
}
}
func TestControlAPIUnreachable(t *testing.T) {
// Point the dashboard at an address nothing listens on, rather than a
// closed httptest.Server, to get a deterministic connection-refused