From 21ced3913fd70f86d2ba66c3745f83c4ab82ab42 Mon Sep 17 00:00:00 2001 From: Jawad Tariq Date: Thu, 14 Dec 2023 11:16:26 -0500 Subject: [PATCH] feat: add sequencer health check Signed-off-by: Jawad Tariq --- subnet-incal.yml | 5 +++++ subnet-topos.yml | 5 +++++ tests/utils.sh | 11 +++-------- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/subnet-incal.yml b/subnet-incal.yml index 264c2e5..e2c4696 100644 --- a/subnet-incal.yml +++ b/subnet-incal.yml @@ -175,6 +175,7 @@ services: condition: service_healthy entrypoint: "" command: bash -c " + apt-get update && apt-get install -y net-tools && source /contracts/.env && cp -vr /data/data-1/consensus /tmp/node_config/node/sequencer-incal/consensus && cp -vr /data/data-1/libp2p /tmp/node_config/node/sequencer-incal/libp2p && @@ -182,6 +183,10 @@ services: cp -v /data/genesis.json /tmp/node_config/subnet/incal/genesis.json && echo Topos core contract address=$(printenv TOPOS_CORE_PROXY_CONTRACT_ADDRESS), set manually in config && topos node up --name sequencer-incal --home /tmp/node_config --no-edge-process" + healthcheck: + test: ["CMD-SHELL", "test $(netstat -ntu | grep ':8545' | wc -l) -gt 0"] + interval: 1s + retries: 10 environment: - RUST_LOG=info,topos=debug - TOOLCHAIN_VERSION=stable diff --git a/subnet-topos.yml b/subnet-topos.yml index d87b1fb..cc93b5d 100644 --- a/subnet-topos.yml +++ b/subnet-topos.yml @@ -235,6 +235,7 @@ services: condition: service_completed_successfully entrypoint: "" command: bash -c " + apt-get update && apt-get install -y net-tools && source /contracts/.env && mkdir -p /data/node/sequencer-topos/consensus -p /data/node/sequencer-topos/libp2p -p /data/subnet/topos-sequencer/ && cp -vr /data/node/node-1/consensus /data/node/sequencer-topos/ && @@ -242,6 +243,10 @@ services: cp -vr /data/subnet/topos/genesis.json /data/subnet/topos-sequencer/genesis.json && echo \"Topos Core contract address:\" $(printenv TOPOS_CORE_PROXY_CONTRACT_ADDRESS), set manually in config && topos node up --name sequencer-topos --home /data/ --no-edge-process" + healthcheck: + test: ["CMD-SHELL", "test $(netstat -ntu | grep ':8545' | wc -l) -gt 0"] + interval: 1s + retries: 10 environment: - RUST_LOG=info,topos=debug - TOOLCHAIN_VERSION=stable diff --git a/tests/utils.sh b/tests/utils.sh index 09cc938..8b1ee59 100644 --- a/tests/utils.sh +++ b/tests/utils.sh @@ -21,18 +21,13 @@ stop_network () { check_network_health () { # Check if all relevant containers are healthy - # TODO: Add healcheck for sequencers, currenly only tce and polygon edge nodes are checked - SERVICE_NAMES=$(docker compose config --dry-run --services | grep -e node) + SERVICE_NAMES=$(docker compose config --dry-run --services | grep -e node -e sequencer) EXPECTED=$(docker compose ps -aq $SERVICE_NAMES | wc -l) COUNT=$(docker inspect --format "{{.State.Health.Status }}" $(docker compose ps -aq $SERVICE_NAMES) | grep "^healthy$"|wc -l) - echo "Number of Healthy containers: $COUNT" if [[ $COUNT -eq $EXPECTED ]]; then - echo "All expected containers healthy" - return 0 + echo 0 else - echo "Unhealthy containers" - docker compose -f tools/docker-compose.yml ps -a peer boot - return 1 + echo 1 fi }