Files
cloud-ip-validator/docs/changes/2026-11-03_00-28_diagnostic-mode-summary.md
ayurishchevandClaude Opus 5.5 55d383bd34 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>
2026-11-03 07:01:24 +03:00

33 lines
2.6 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Итог: диагностический режим в control-api
План: [2026-11-03_00-28_diagnostic-mode-plan.md](2026-11-03_00-28_diagnostic-mode-plan.md)
## Что сделано
- **API** (admin-токен, описание в `docs/API.md`):
- `POST /api/v1/admin/diagnostics/attach` — привязать адреса к валидаторам (указанным или свободным), ответ по каждому адресу: `attached` / `rejected` с причиной;
- `POST /api/v1/admin/diagnostics/detach` — отвязать адреса или все (`{"all":true}`);
- `GET /api/v1/admin/diagnostics` — удерживаемые адреса.
- **Хранение**: миграция `0014_diagnostic_holds.sql`; привязка переживает перезапуск control-api, снимается только явно.
- **Валидатор** на диагностике — в состоянии `diagnostic`: заданий не получает, не переводится в `unreachable`, его порты не освобождаются при «очистить всё» и удалении адресов, удалить такой валидатор нельзя.
- **Адрес** на диагностике не выдаётся из очереди.
- **Отказы**: нет floating IP, привязан к чужому порту, адрес в активной проверке, уже на диагностике, валидатор не найден/занят, нет свободных валидаторов. Ошибка облака откатывает захват валидатора.
- **События** `diagnostic_attached` / `diagnostic_detached`; в дашборде — бейдж состояния `diagnostic`.
## Проверка
`go test ./internal/...` — без ошибок. Новые тесты: привязка/отвязка (адрес не выдаётся из очереди, heartbeat и сверка не меняют `diagnostic`), отказы, откат при ошибке облака, поиск зависших и освобождение портов не трогают такой валидатор.
## Пример
```bash
curl -H "Authorization: Bearer $ADMIN" -X POST http://localhost:8081/api/v1/admin/diagnostics/attach \
-d '{"items":[{"address":"37.139.32.23","validator_id":"vkiplab-v1"}],"note":"traceroute TCP 443"}'
curl -H "Authorization: Bearer $ADMIN" -X POST http://localhost:8081/api/v1/admin/diagnostics/detach \
-d '{"addresses":["37.139.32.23"]}'
```
## Не входит
Раздел в admin-dashboard для привязки/отвязки.