Skip to content

Commit

Permalink
Use Full-Upstream header
Browse files Browse the repository at this point in the history
Signed-off-by: Dylan Schultz <[email protected]>
  • Loading branch information
dylanschultzie committed Jul 9, 2024
1 parent 6a73fd1 commit b70ace5
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 12 deletions.
5 changes: 3 additions & 2 deletions app/common.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
def parse_request(req) -> tuple:
port = req.headers.get("Port")
host = req.headers.get("Host")
# port = req.headers.get("Port")
host = req.headers.get("Full-Upstream")
ip_address = host.split(":")[0]
port = host.split(":")[1]
return ip_address, port
4 changes: 2 additions & 2 deletions app/cosmos/cosmos.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
from datetime import datetime, timedelta, timezone


def cosmos_health(ip: str, port: str, acceptable_time_delta: int = 60) -> tuple:
def cosmos_health(host: str, acceptable_time_delta: int = 60) -> tuple:
acceptable_time_delta = timedelta(seconds=acceptable_time_delta)

url = f"http://{ip}:{port}/status"
url = f"http://{host}/status"
response = requests.post(url)

if response.status_code != 200:
Expand Down
4 changes: 2 additions & 2 deletions app/evm/ethereum.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
import requests


def ethereum_health(ip: str, port: str, acceptable_time_delta: int = 60):
def ethereum_health(host: str, acceptable_time_delta: int = 60):
acceptable_time_delta = timedelta(seconds=acceptable_time_delta)

# Get latest block data
payload = {"jsonrpc": "2.0", "method": "eth_getBlockByNumber", "params": ["latest", False], "id": 1}
headers = {"Content-Type": "application/json"}
url = f"http://{ip}:{port}"
url = f"http://{host}"
response = requests.post(url, headers=headers, json=payload)

if response.status_code != 200:
Expand Down
8 changes: 4 additions & 4 deletions app/routes.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# routes.py
from flask import Blueprint, request
from app.common import parse_request
from app.health_check_functions import switch

api = Blueprint("api", __name__)


@api.route("/health", methods=["GET"])
def health_check():
ip, port = parse_request(request)
rpc_type = port[-2:]
host = request.headers.get("Full-Upstream")
rpc_type = host[-2:]
health_check_function = switch.get(rpc_type)

if health_check_function:
message, status = health_check_function(ip, port)
message, status = health_check_function(host)
else:
message, status = "Unknown RPC type", 400

Expand Down
2 changes: 0 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ services:
image: lavender5/rpc_health_checker:master
container_name: health
restart: unless-stopped
env_file:
- ".env"
ports:
- "53336:53336"
network_mode: "host"

0 comments on commit b70ace5

Please sign in to comment.