control-api: reduce SQLite disk writes; add diagnostic mode

Disk writes:
- SQLite pragmas in DSN: wal_autocheckpoint=10000, journal_size_limit=64MB, cache_size=64MB
- migration 0013: drop redundant idx_checks_registry_cycle
- results batched: UpsertChecksIfOpen in one transaction; agent flushes every 5s and before complete
- heartbeat kept in memory, persisted on state change or every 60s; startup grace for stale sweeps

Diagnostic mode:
- POST /api/v1/admin/diagnostics/attach|detach, GET /api/v1/admin/diagnostics
- migration 0014: diagnostic_holds; validator state "diagnostic"
- held addresses are not queued, held validators skip sweeps, port release and delete

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ayurishchevandClaude Opus 5.5 committed 2026-11-03 07:01:24 +03:00
1 parent d0ab6b94f9
commit 55d383bd34
41 files changed
+1214 -94

No files matched your search

+17 -14
View File
@@ -36,7 +36,7 @@ func (s *Server) handleProberHeartbeat(w http.ResponseWriter, r *http.Request) {
siteID := r.PathValue("site_id")
var req heartbeatRequest
_ = readJSON(r, &req) // heartbeat body is informational only; tolerate empty/missing
if err := s.DB.SiteHeartbeat(r.Context(), siteID); err != nil {
if err := s.Orch.SiteHeartbeat(r.Context(), siteID); err != nil {
writeError(w, http.StatusNotFound, "unknown site_id: "+siteID)
return
}
@@ -97,8 +97,7 @@ func (s *Server) handleProberResults(w http.ResponseWriter, r *http.Request) {
return
}
completed := map[int64]bool{}
dropped := map[int64]int{}
checks := make([]db.Check, 0, len(req.Results))
for _, res := range req.Results {
item, err := s.DB.GetIP(r.Context(), res.IPID)
if err != nil {
@@ -109,21 +108,25 @@ func (s *Server) handleProberResults(w http.ResponseWriter, r *http.Request) {
if err != nil {
checkedAt = db.Now()
}
written, err := s.Orch.RecordCheckIfOpen(r.Context(), db.Check{
checks = append(checks, db.Check{
IPID: item.ID, IPAddress: item.IPAddress, AttemptNumber: item.AttemptNumber,
Source: db.InboundSource(siteIndex), CheckType: res.CheckType, Target: res.IPAddress,
Success: res.Success, LatencyMS: res.LatencyMS, Detail: res.Detail, CheckedAt: checkedAt,
})
if err != nil {
writeError(w, http.StatusInternalServerError, err.Error())
return
}
if !written {
dropped[item.ID]++
continue
}
if res.Complete {
completed[res.IPID] = true
}
written, err := s.Orch.RecordChecksIfOpen(r.Context(), checks)
if err != nil {
writeError(w, http.StatusInternalServerError, err.Error())
return
}
completed := map[int64]bool{}
dropped := map[int64]int{}
for i, ok := range written {
switch {
case !ok:
dropped[checks[i].IPID]++
case req.Results[i].Complete:
completed[checks[i].IPID] = true
}
}
for ipID := range completed {