Переделать связь нод в кластере на автоматическое обнаружение #9

This commit is contained in:
2026-05-01 22:30:40 +03:00
parent 1787b0f8a3
commit f36dd3bbc1
25 changed files with 870 additions and 332 deletions

View File

@@ -100,6 +100,9 @@ eunit-verbose: ## Запустить EUnit тесты с подробным вы
test-api: test-ct
test-ct: ## Запустить Common Test для API
@echo "Cleaning old data..."
@rm -rf Mnesia.*
@rm -rf logs/test/ct/ct_run.*
@$(REBAR3) ct --sname $(SNAME)_api_test
test-ct-verbose: ## Запустить Common Test с подробным выводом
@@ -109,6 +112,28 @@ test-ct-verbose: ## Запустить Common Test с подробным выв
-logdir build \
-verbosity 50
test-remote:
@CT_MODE=remote API_HOST=http://localhost:8080 ADMIN_API_HOST=http://localhost:8445 rebar3 ct
test-remote-cluster:
@rm -rf logs/test/ct/ct_run.*
@CT_MODE=remote \
API_HOST=https://api.eventhub.local/api \
WS_HOST=wss://ws.eventhub.local \
ADMIN_API_HOST=https://admin-api.eventhub.local/api \
ADMIN_WS_HOST=wss://admin-ws.eventhub.local \
rebar3 ct
test-api-docker:
@docker build -t eventhub-tests -f docker/ApiTests.Dockerfile .
@docker run --rm \
-e CT_MODE=remote \
-e "API_HOST=http://eventhub:8080" \
-e "ADMIN_API_HOST=http://eventhub:8445" \
-e "WS_HOST=ws://eventhub:8081" \
-e "ADMIN_WS_HOST=ws://eventhub:8446" \
eventhub-tests
test-scripts: ## Запустить тесты с фильтром (make test-runner PATTERN=booking)
@chmod +x test/scripts/*.sh
@cd test/scripts && ./run_tests.sh $(PATTERN)
@@ -128,24 +153,24 @@ tsung-test: ## Запустить нагрузочный тест Tsung
@echo "Отчёт: logs/tsung/*/report.html"
wrk-register: ## Нагрузочный тест регистрации (wrk2)
@wrk -t4 -c100 -d30s -t100 -s test/wrk/scripts/wrk_register.lua http://localhost/v1/register
@wrk -t4 -c100 -d30s -t100 -s test/wrk/scripts/wrk_register.lua https://api.eventhub.local/api/v1/register
wrk-search: ## Нагрузочный тест поиска (wrk2)
@TOKEN=$$(curl -s -X POST http://localhost:8080/v1/register \
@TOKEN=$$(curl -s -X POST https://api.eventhub.local/api/v1/register \
-H "Content-Type: application/json" \
-d '{"email":"wrktest@test.com","password":"pass"}' | \
grep -o '"token":"[^"]*"' | cut -d'"' -f4); \
wrk -t4 -c100 -d30s -t200 \
-H "Authorization: Bearer $$TOKEN" \
http://localhost:8080/v1/search?type=event\&q=test
https://api.eventhub.local/api/v1/search?type=event\&q=test
curl-health:
for i in {1..120}; do curl -k -s -o /dev/null -w "%{http_code}\n" -H "Host: api.eventhub.local" https://localhost/health; done
for i in {1..2}; do curl -k -s -o /dev/null -w "%{http_code}\n" -H "Host: api.eventhub.local" https://localhost/api/health; done
wrk-health: ## Нагрузочный тест health (wrk2)
wrk -t4 -c100 -d30s -t100 \
-H "Host: api.eventhub.local" \
https://api.eventhub.local/health
https://api.eventhub.local/api/health
# ============================================================================
# CODE QUALITY
@@ -251,6 +276,38 @@ docker-clean: docker-stop ## Очистить Docker образы и volumes
@docker volume rm eventhub-data 2>/dev/null || true
@echo "✅ Docker очищен"
docker-swarm-deploy: ## Запустить кластер
RELEASE_COOKIE=$$(grep RELEASE_COOKIE docker/.env | cut -d '=' -f2) \
JWT_SECRET=$$(grep JWT_SECRET docker/.env | cut -d '=' -f2) \
docker stack deploy -c docker/docker-compose.swarm.yml eventhub
@echo "✅ Кластер запущен"
docker-swarm-stop: ## Запустить кластер
@docker stack rm eventhub
@docker volume prune -f
@echo "✅ Кластер удален"
docker-swarm-scale: ## Изменить количество реплик (например, make scale REPLICAS=5)
@echo "Масштабирование до ${REPLICAS} реплик..."
docker service scale eventhub_eventhub=${REPLICAS}
@echo "✅ Сервис масштабирован"
docker-swarm-status: ## Показать состояние кластера
@echo "Количество узлов в кластере:"
@docker exec $$(docker ps -qf "name=eventhub_eventhub" | head -n 1) /app/bin/eventhub eval 'length(nodes()).'
@echo "Список узлов:"
@docker exec $$(docker ps -qf "name=eventhub_eventhub" | head -n 1) /app/bin/eventhub eval 'nodes().'
docker-swarm-reg-admin:
@docker exec $$(docker ps -qf "name=eventhub_eventhub" | head -n 1) /app/bin/eventhub eval 'core_admin:create(<<"admin">>,<<"123456">>,superadmin).'
docker-swarm-check-admin:
@docker exec $$(docker ps -qf "name=eventhub_eventhub" | head -n 1) /app/bin/eventhub eval 'eventhub_auth:authenticate_admin_request(<<"">>,<<"admin@eventhub.local">>,<<"123456">>).'
docker-swarm-shell:
@docker exec $$(docker ps -qf "name=eventhub_eventhub" | head -n 1) /app/bin/eventhub remote_console
# ============================================================================
# UTILITIES
# ============================================================================