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:
1 parent
d0ab6b94f9
commit
55d383bd34
41 files changed
+1214
-94
No files matched your search
@@ -240,7 +240,32 @@ func TestMigration0010MarksRowsAfterVerdict(t *testing.T) {
|
||||
t.Errorf("ssh: after_verdict=%d recorded=%s created=%s", a, rec, cr)
|
||||
}
|
||||
var ver int
|
||||
if err := d.QueryRowContext(ctx, `PRAGMA user_version`).Scan(&ver); err != nil || ver != 12 {
|
||||
if err := d.QueryRowContext(ctx, `PRAGMA user_version`).Scan(&ver); err != nil || ver != 14 {
|
||||
t.Errorf("user_version=%d err=%v", ver, err)
|
||||
}
|
||||
}
|
||||
|
||||
// A batch is written in one transaction; a row for a finished address is
|
||||
// dropped without affecting the others.
|
||||
func TestUpsertChecksIfOpenBatch(t *testing.T) {
|
||||
d, ctx := newTestDB(t)
|
||||
open := checkingIP(t, d, "1.2.3.4")
|
||||
done := checkingIP(t, d, "5.6.7.8")
|
||||
if _, err := d.ExecContext(ctx, `UPDATE ip_queue SET state='done' WHERE id=?`, done.ID); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
written, err := d.UpsertChecksIfOpen(ctx, []Check{
|
||||
checkOf(open, "icmp", true), checkOf(open, "ssh", false), checkOf(done, "icmp", true),
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(written) != 3 || !written[0] || !written[1] || written[2] {
|
||||
t.Fatalf("written = %v, want [true true false]", written)
|
||||
}
|
||||
var n int
|
||||
d.QueryRowContext(ctx, `SELECT COUNT(*) FROM checks`).Scan(&n)
|
||||
if n != 2 {
|
||||
t.Fatalf("%d rows stored, want 2", n)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user