Files
microdao-daarion/docs/runbook/sofiia-redis-smoke.md
2026-03-02 09:11:45 -08:00

91 lines
3.1 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.
# Sofiia Console Redis Smoke
Мета: швидко перевірити distributed idempotency для `sofiia-console` з Redis, включно з replay між двома інстансами BFF.
## 1) Підняти Redis
```bash
docker compose -f docker-compose.redis-smoke.yml up -d
```
## 2) Запустити sofiia-console з env
```bash
cd services/sofiia-console
export SOFIIA_IDEMPOTENCY_BACKEND=redis
export SOFIIA_REDIS_URL=redis://127.0.0.1:6379/0
export SOFIIA_REDIS_PREFIX=sofiia:idem:
export SOFIIA_IDEMPOTENCY_TTL_S=900
export ENV=dev
python3 -m uvicorn app.main:app --host 0.0.0.0 --port 8002
```
## 3) Smoke curl: 1 send + replay
```bash
CHAT_ID=$(curl -s -X POST "http://127.0.0.1:8002/api/chats" \
-H "Content-Type: application/json" \
-d '{"agent_id":"sofiia","node_id":"NODA2","source":"web","external_chat_ref":"redis-smoke"}' | jq -r '.chat.chat_id')
curl -s -X POST "http://127.0.0.1:8002/api/chats/${CHAT_ID}/send" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: redis-smoke-key-1" \
-d '{"text":"ping"}'
curl -s -X POST "http://127.0.0.1:8002/api/chats/${CHAT_ID}/send" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: redis-smoke-key-1" \
-d '{"text":"ping"}'
```
Очікування: другий виклик повертає `idempotency.replayed=true` і той самий `message.message_id`.
## Перевірка між двома інстансами BFF (A/B)
1. Інстанс A:
```bash
cd services/sofiia-console
export SOFIIA_IDEMPOTENCY_BACKEND=redis
export SOFIIA_REDIS_URL=redis://127.0.0.1:6379/0
export SOFIIA_REDIS_PREFIX=sofiia:idem:
export SOFIIA_IDEMPOTENCY_TTL_S=900
export ENV=dev
python3 -m uvicorn app.main:app --host 0.0.0.0 --port 8002
```
2. Інстанс B (в іншому терміналі, той самий env, інший порт):
```bash
cd services/sofiia-console
export SOFIIA_IDEMPOTENCY_BACKEND=redis
export SOFIIA_REDIS_URL=redis://127.0.0.1:6379/0
export SOFIIA_REDIS_PREFIX=sofiia:idem:
export SOFIIA_IDEMPOTENCY_TTL_S=900
export ENV=dev
python3 -m uvicorn app.main:app --host 0.0.0.0 --port 8003
```
3. Записати перший send через A, повторити через B з тим самим `Idempotency-Key`:
```bash
CHAT_ID=$(curl -s -X POST "http://127.0.0.1:8002/api/chats" \
-H "Content-Type: application/json" \
-d '{"agent_id":"sofiia","node_id":"NODA2","source":"web","external_chat_ref":"redis-smoke-ab"}' | jq -r '.chat.chat_id')
A=$(curl -s -X POST "http://127.0.0.1:8002/api/chats/${CHAT_ID}/send" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: redis-shared-key-1" \
-d '{"text":"ping-from-a"}')
B=$(curl -s -X POST "http://127.0.0.1:8003/api/chats/${CHAT_ID}/send" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: redis-shared-key-1" \
-d '{"text":"ping-from-b"}')
echo "$A" | jq '{message_id: .message.message_id, replayed: .idempotency.replayed, node_id}'
echo "$B" | jq '{message_id: .message.message_id, replayed: .idempotency.replayed, node_id}'
```
Очікування:
- `A.idempotency.replayed == false`
- `B.idempotency.replayed == true`
- `A.message.message_id == B.message.message_id`