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

+69
View File
@@ -0,0 +1,69 @@
package httpapi
import (
"net/http"
"strings"
"cloudipvalidator/internal/orchestrator"
)
type diagnosticAttachRequest struct {
Items []struct {
Address string `json:"address"`
ValidatorID string `json:"validator_id"`
} `json:"items"`
Note string `json:"note"`
}
type diagnosticDetachRequest struct {
Addresses []string `json:"addresses"`
All bool `json:"all"`
}
type diagnosticResultsResponse struct {
Results []orchestrator.DiagnosticResult `json:"results"`
}
func (s *Server) handleAdminDiagnosticAttach(w http.ResponseWriter, r *http.Request) {
var req diagnosticAttachRequest
if err := readJSON(r, &req); err != nil {
writeError(w, http.StatusBadRequest, "invalid body: "+err.Error())
return
}
if len(req.Items) == 0 {
writeError(w, http.StatusBadRequest, "items must not be empty")
return
}
items := make([]orchestrator.DiagnosticItem, len(req.Items))
for i, it := range req.Items {
addr := strings.TrimSpace(it.Address)
if addr == "" {
writeError(w, http.StatusBadRequest, "address must not be empty")
return
}
items[i] = orchestrator.DiagnosticItem{Address: addr, ValidatorID: strings.TrimSpace(it.ValidatorID)}
}
writeJSON(w, http.StatusOK, diagnosticResultsResponse{Results: s.Orch.DiagnosticAttach(r.Context(), items, req.Note)})
}
func (s *Server) handleAdminDiagnosticDetach(w http.ResponseWriter, r *http.Request) {
var req diagnosticDetachRequest
if err := readJSON(r, &req); err != nil {
writeError(w, http.StatusBadRequest, "invalid body: "+err.Error())
return
}
if !req.All && len(req.Addresses) == 0 {
writeError(w, http.StatusBadRequest, "addresses or all=true is required")
return
}
writeJSON(w, http.StatusOK, diagnosticResultsResponse{Results: s.Orch.DiagnosticDetach(r.Context(), req.Addresses, req.All)})
}
func (s *Server) handleAdminDiagnosticList(w http.ResponseWriter, r *http.Request) {
holds, err := s.Orch.DiagnosticList(r.Context())
if err != nil {
writeError(w, http.StatusInternalServerError, err.Error())
return
}
writeJSON(w, http.StatusOK, holds)
}