Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(deployment): add healthcheck for backend #564

Merged
merged 3 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ TOTALVALIDATORS = 10
NUMVALIDATORS = 4
LOGCONFIG = 'dev' # dev/prod
FLASK_LOG_LEVEL = 'ERROR' # DEBUG/INFO/WARNING/ERROR/CRITICAL
DISABLE_INFO_LOGS_ENDPOINTS = '["eth_getTransactionByHash","gen_getContractSchemaForCode","gen_getContractSchema"]'
DISABLE_INFO_LOGS_ENDPOINTS = '["ping", "eth_getTransactionByHash","gen_getContractSchemaForCode","gen_getContractSchema"]'

# JsonRPC server details
RPCPROTOCOL = 'http'
Expand Down
34 changes: 34 additions & 0 deletions backend/healthcheck.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""
File used to check the health of the backend API.
We only check that the API is responding, and that the response is valid.
"""

import json
import requests
import argparse

parser = argparse.ArgumentParser(description="Check the health of the backend API.")
parser.add_argument(
"--port",
type=str,
nargs="?",
help="The port number for the API",
)

args = parser.parse_args()

response = requests.post(
f"http://localhost:{args.port}/api",
data=json.dumps(
{
"jsonrpc": "2.0",
"method": "ping",
"params": [],
"id": 1,
}
),
headers={"Content-Type": "application/json"},
)
assert response.status_code == 200
print(response.json())
assert response.json() == {"id": 1, "jsonrpc": "2.0", "result": "OK"}
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ services:
- ./examples:/app/src/assets/examples
- ./frontend/src:/app/src
depends_on:
- jsonrpc
jsonrpc:
condition: service_healthy
expose:
- "${FRONTEND_PORT}"

Expand Down
2 changes: 2 additions & 0 deletions docker/Dockerfile.backend
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ ENV HUGGINGFACE_HUB_CACHE /home/backend-user/.cache/huggingface
COPY ../.env .
COPY backend $path/backend

HEALTHCHECK --interval=1s --timeout=1s --retries=15 --start-period=1s CMD python backend/healthcheck.py --port ${FLASK_SERVER_PORT}

###########START NEW IMAGE : DEBUGGER ###################
FROM base AS debug
RUN --mount=type=cache,target=/root/.cache/pip \
Expand Down
Loading