New external site management. New external prober heartbeat feature.
This commit is contained in:
1 parent
42f584dd3c
commit
ef24cc9858
38 files changed
+1058
-158
No files matched your search
@@ -623,3 +623,110 @@ func TestInboundChecksReflectedInProberAssignmentsWithoutRestart(t *testing.T) {
|
||||
t.Fatalf("expected updated {[8080] false} without restart, got %+v", assignments)
|
||||
}
|
||||
}
|
||||
|
||||
// TestProberRegisterSetsHostnameAndIdleState proves POST
|
||||
// /api/v1/probers/register persists the calling prober's hostname and
|
||||
// flips the site's state to idle, visible via GET
|
||||
// /api/v1/admin/config/sites — the prober-availability analog of
|
||||
// validator registration.
|
||||
func TestProberRegisterSetsHostnameAndIdleState(t *testing.T) {
|
||||
fc, _, _, _ := newConfigTestHarness(t)
|
||||
|
||||
fc.do(http.MethodPut, "/api/v1/admin/config/sites/1", putSiteRequest{SiteID: "site-1"})
|
||||
|
||||
resp, body := fc.do(http.MethodGet, "/api/v1/admin/config/sites", nil)
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
t.Fatalf("get sites: status=%d body=%s", resp.StatusCode, body)
|
||||
}
|
||||
var sites []siteDTO
|
||||
if err := json.Unmarshal(body, &sites); err != nil {
|
||||
t.Fatalf("unmarshal sites: %v", err)
|
||||
}
|
||||
if len(sites) != 1 || sites[0].State != "unregistered" {
|
||||
t.Fatalf("expected freshly-created slot unregistered, got %+v", sites)
|
||||
}
|
||||
|
||||
resp, body = fc.do(http.MethodPost, "/api/v1/probers/register", registerProberRequest{SiteID: "site-1", Hostname: "probe-host-1"})
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
t.Fatalf("register prober: status=%d body=%s", resp.StatusCode, body)
|
||||
}
|
||||
|
||||
resp, body = fc.do(http.MethodGet, "/api/v1/admin/config/sites", nil)
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
t.Fatalf("get sites after register: status=%d body=%s", resp.StatusCode, body)
|
||||
}
|
||||
if err := json.Unmarshal(body, &sites); err != nil {
|
||||
t.Fatalf("unmarshal sites: %v", err)
|
||||
}
|
||||
if sites[0].State != "idle" || sites[0].Hostname != "probe-host-1" {
|
||||
t.Fatalf("expected {state:idle, hostname:probe-host-1}, got %+v", sites[0])
|
||||
}
|
||||
if sites[0].LastHeartbeatAt == nil {
|
||||
t.Fatalf("expected last_heartbeat_at stamped")
|
||||
}
|
||||
}
|
||||
|
||||
// TestProberHeartbeat404UnknownSite proves the heartbeat endpoint rejects
|
||||
// an unconfigured site_id, mirroring the validator heartbeat's 404.
|
||||
func TestProberHeartbeat404UnknownSite(t *testing.T) {
|
||||
fc, _, _, _ := newConfigTestHarness(t)
|
||||
resp, body := fc.do(http.MethodPost, "/api/v1/probers/unknown-site/heartbeat", nil)
|
||||
if resp.StatusCode != http.StatusNotFound {
|
||||
t.Fatalf("expected 404 for unknown site_id, status=%d body=%s", resp.StatusCode, body)
|
||||
}
|
||||
}
|
||||
|
||||
// TestSweepStaleSiteHeartbeatsMarksUnreachable is the end-to-end proof that
|
||||
// a prober that stops heartbeating gets marked unreachable by the sweep,
|
||||
// visible via the admin API — the prober-side analog of
|
||||
// TestFIPSettleDelayGatesAssignmentEndpoint's wire-level style.
|
||||
func TestSweepStaleSiteHeartbeatsMarksUnreachable(t *testing.T) {
|
||||
fc, d, orch, _ := newConfigTestHarness(t)
|
||||
ctx := context.Background()
|
||||
|
||||
fc.do(http.MethodPut, "/api/v1/admin/config/sites/1", putSiteRequest{SiteID: "site-1"})
|
||||
resp, body := fc.do(http.MethodPost, "/api/v1/probers/register", registerProberRequest{SiteID: "site-1", Hostname: "probe-host-1"})
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
t.Fatalf("register prober: status=%d body=%s", resp.StatusCode, body)
|
||||
}
|
||||
|
||||
// Backdate last_heartbeat_at past HeartbeatTimeoutSeconds (30s, per
|
||||
// newConfigTestHarness) directly in the DB, rather than sleeping 30+
|
||||
// real seconds in the test.
|
||||
old := db.Now().Add(-time.Hour).UTC().Format(time.RFC3339Nano)
|
||||
if _, err := d.ExecContext(ctx, `UPDATE sites SET last_heartbeat_at=? WHERE site_id=?`, old, "site-1"); err != nil {
|
||||
t.Fatalf("backdate heartbeat: %v", err)
|
||||
}
|
||||
|
||||
if err := orch.SweepStaleSiteHeartbeats(ctx); err != nil {
|
||||
t.Fatalf("sweep stale site heartbeats: %v", err)
|
||||
}
|
||||
|
||||
resp, body = fc.do(http.MethodGet, "/api/v1/admin/config/sites", nil)
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
t.Fatalf("get sites: status=%d body=%s", resp.StatusCode, body)
|
||||
}
|
||||
var sites []siteDTO
|
||||
if err := json.Unmarshal(body, &sites); err != nil {
|
||||
t.Fatalf("unmarshal sites: %v", err)
|
||||
}
|
||||
if len(sites) != 1 || sites[0].State != "unreachable" {
|
||||
t.Fatalf("expected site-1 marked unreachable after sweep, got %+v", sites)
|
||||
}
|
||||
|
||||
// A fresh heartbeat brings it back to idle.
|
||||
resp, body = fc.do(http.MethodPost, "/api/v1/probers/site-1/heartbeat", nil)
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
t.Fatalf("heartbeat: status=%d body=%s", resp.StatusCode, body)
|
||||
}
|
||||
resp, body = fc.do(http.MethodGet, "/api/v1/admin/config/sites", nil)
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
t.Fatalf("get sites after heartbeat: status=%d body=%s", resp.StatusCode, body)
|
||||
}
|
||||
if err := json.Unmarshal(body, &sites); err != nil {
|
||||
t.Fatalf("unmarshal sites: %v", err)
|
||||
}
|
||||
if sites[0].State != "idle" {
|
||||
t.Fatalf("expected site-1 back to idle after heartbeat, got %+v", sites)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user