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

Update proxy upstream limits, add heartbeat #68

Merged
merged 1 commit into from
Jul 4, 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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ JSON-RPC endpoints for SKALE chains. It is based on NGINX.

- `ETH_ENDPOINT` - endpoint of the Ethereum network where `skale-manager` contracts are deployed

#### Optional environment variables

- `HEARTBEAT_URL` - URL for healthcheck endpoint (optional)

## License

[![License](https://img.shields.io/github/license/skalenetwork/skale-proxy.svg)](LICENSE)
Expand Down
6 changes: 3 additions & 3 deletions config/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ http {

limit_req zone=one burst=100;

proxy_read_timeout 180s;
proxy_connect_timeout 60s;
proxy_send_timeout 180s;
proxy_read_timeout 60s;
proxy_connect_timeout 30s;
proxy_send_timeout 60s;

location / {
proxy_http_version 1.1;
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ services:
skale-proxy:
environment:
ETH_ENDPOINT: ${ETH_ENDPOINT}
HEARTBEAT_URL: ${HEARTBEAT_URL}
image: skale-proxy:latest
container_name: proxy_admin
build:
Expand Down
2 changes: 2 additions & 0 deletions proxy/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

MONITOR_INTERVAL = os.getenv('MONITOR_INTERVAL', 60 * 60 * 2)

HEARTBEAT_URL = os.getenv('HEARTBEAT_URL')

NGINX_WWW_FOLDER = os.path.join(PROJECT_PATH, 'www')
CHAINS_INFO_FILEPATH = os.path.join(NGINX_WWW_FOLDER, 'chains.json')

Expand Down
36 changes: 36 additions & 0 deletions proxy/heartbeat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# -*- coding: utf-8 -*-
#
# This file is part of SKALE Proxy
#
# Copyright (C) 2024-Present SKALE Labs
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

import logging
import requests

logger = logging.getLogger(__name__)


def send_heartbeat(heartbeat_url):
if heartbeat_url is None:
logger.info('HEARTBEAT_URL is not set on the proxy')
try:
response = requests.get(heartbeat_url)
if response.status_code == 200:
logger.info('Heartbeat signal is successfully sent')
else:
logger.warning(f'Failed to send heartbeat signal: {response.status_code}')
except Exception as e:
logger.error(f'Failed to send heartbeat signal: {e}')
4 changes: 3 additions & 1 deletion proxy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@
from proxy.nginx import update_nginx_configs
from proxy.endpoints import generate_endpoints
from proxy.helper import init_default_logger, write_json
from proxy.heartbeat import send_heartbeat
from proxy.str_formatters import arguments_list_string
from proxy.config import (
CHAINS_INFO_FILEPATH, MONITOR_INTERVAL, ENDPOINT, SM_ABI_FILEPATH,
TMP_CHAINS_FOLDER, TMP_UPSTREAMS_FOLDER
TMP_CHAINS_FOLDER, TMP_UPSTREAMS_FOLDER, HEARTBEAT_URL
)


Expand All @@ -48,6 +49,7 @@ def main():
schains_endpoints = generate_endpoints(ENDPOINT, SM_ABI_FILEPATH)
write_json(CHAINS_INFO_FILEPATH, schains_endpoints)
update_nginx_configs(schains_endpoints)
send_heartbeat(HEARTBEAT_URL)
logger.info(f'Proxy iteration done, sleeping for {MONITOR_INTERVAL}s...')
sleep(MONITOR_INTERVAL)

Expand Down
Loading