Skip to content

Commit

Permalink
added relayer readiness probe
Browse files Browse the repository at this point in the history
  • Loading branch information
sampocs committed Aug 28, 2024
1 parent 8185fe5 commit 5ab3a0f
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 19 deletions.
17 changes: 1 addition & 16 deletions integration-tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,7 @@ check-empty-namespace:
if [ $$POD_COUNT -eq 0 ]; then exit 0; else exit 1; fi

wait-for-startup:
@echo "---" && sleep 1
@printf "Waiting for network to startup..."
@elapsed=0; \
while true; do \
not_ready_pods=$$($(KUBECTL) get pods --no-headers -n $(K8S_NAMESPACE) | grep -v '1/1 *Running' | wc -l); \
if [ $$not_ready_pods -eq 0 ]; then \
printf "Ready! 🚀\n"; \
break; \
fi; \
if [ $$elapsed -eq 30 ]; then \
printf "\nThe network's taking longer than expected to startup. Please investigate\n"; \
exit 1; \
fi; \
sleep 1 && printf "."; \
elapsed=$$((elapsed + 1)); \
done
@bash network/scripts/network-readiness.sh $(K8S_NAMESPACE)

python-install:
conda create --name $(VENV_NAME) python=3.11 -y
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/network/scripts/init-chain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ update_stride_genesis() {
$BINARY add-consumer-section --validator-public-keys $validator_public_keys
jq_inplace '.app_state.ccvconsumer.params.unbonding_period |= "'$UNBONDING_TIME'"' $genesis_json

jq_inplace '.app_state.airdrop.params.period_length_seconds |= "'${AIRDROP_PERIOD_LENGTH}'"' $genesis_json
jq_inplace '.app_state.airdrop.params.period_length_seconds |= "'${AIRDROP_PERIOD_SECONDS}'"' $genesis_json
}

# Genesis updates specific to non-stride chains
Expand Down
28 changes: 28 additions & 0 deletions integration-tests/network/scripts/network-readiness.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

set -eu

namespace="$1"

echo "---" && sleep 1
printf "Waiting for network to startup..."

# TODO: fix this
trap 'printf "\nInterrupted by user.\n"; exit' INT

elapsed=0
while true; do
not_ready_pods=$(kubectl get pods --no-headers -n $namespace | grep -v '1/1 *Running' | wc -l)

if [[ $not_ready_pods -eq 0 ]]; then
printf "Ready! 🚀\n"
break
fi
if [[ $elapsed -eq 60 ]]; then
printf "\nThe network's taking longer than expected to startup. Please investigate via `kubectl get pods`\n"
exit 1
fi

sleep 2 && printf "."
elapsed=$((elapsed + 1))
done
45 changes: 45 additions & 0 deletions integration-tests/network/scripts/relayer-readiness.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash

set -e

relayer_type="$1"

chain_id="${CHAIN_NAME_A}-test-1"
relayer_config_file=${HOME}/.relayer/config/config.yaml
hermes_config_file=${HOME}/.hermes/config.toml

if [[ "$relayer_type" == "relayer" ]]; then
if [[ ! -f $relayer_config_file ]]; then
echo "Config not initialized yet"
exit 1
fi
if ! rly q channels "$CHAIN_NAME_A" 2>/dev/null | grep -q STATE_OPEN; then
echo "Source channel not open yet"
exit 1
fi
if ! rly q channels "$CHAIN_NAME_B" 2>/dev/null | grep -q STATE_OPEN; then
echo "Destination channel not open yet"
exit 1
fi
exit 0

elif [[ "$relayer_type" == "hermes" ]]; then
if [[ ! -f $hermes_config_file ]]; then
echo "Config not initialized yet"
exit 1
fi
open_channels=$(hermes query channels --chain "$chain_id" --show-counterparty 2>/dev/null | grep -o "channel-" | wc -l)
if [[ "$open_channels" == "0" ]]; then
echo "Source channel not open yet"
exit 1
fi
if [[ "$open_channels" == "1" ]]; then
echo "Destination channel not open yet"
exit 1
fi
exit 0

else
echo "ERROR: Unsupported relayer type $relayer_type"
exit 1
fi
3 changes: 2 additions & 1 deletion integration-tests/network/scripts/start-hermes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ CHAIN_ID_B=${CHAIN_NAME_B}-test-1
wait_for_node $CHAIN_NAME_A
wait_for_node $CHAIN_NAME_B

hermes_config_file=${HOME}/.hermes/config.toml

restore_keys() {
mnemonic_a=$(jq -r '.relayers[$index].mnemonic' --argjson index "$CHAIN_A_MNEMONIC_INDEX" ${KEYS_FILE})
mnemonic_b=$(jq -r '.relayers[$index].mnemonic' --argjson index "$CHAIN_B_MNEMONIC_INDEX" ${KEYS_FILE})
Expand All @@ -35,7 +37,6 @@ create_path() {
main() {
# The config is mounted from a configmap which is read-only by default
# In order to make it writeable, we need to copy it to a new location
hermes_config_file=${HOME}/.hermes/config.toml
mkdir -p $(dirname $hermes_config_file)
cp configs/hermes.toml ${hermes_config_file}

Expand Down
6 changes: 6 additions & 0 deletions integration-tests/network/templates/relayer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ spec:
value: "{{ $chainMnemonicIndexA }}"
- name: CHAIN_B_MNEMONIC_INDEX
value: "{{ $chainMnemonicIndexB }}"
readinessProbe:
exec:
command: ["bash", "scripts/relayer-readiness.sh", "{{ $relayer.type }}"]
periodSeconds: 2
initialDelaySeconds: 30
timeoutSeconds: 10
resources:
limits:
cpu: "200m"
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/network/templates/validator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ spec:
command: ["bash", "scripts/create-validator.sh"]
readinessProbe:
exec:
command: ["bash", "scripts/readiness.sh"]
command: ["bash", "scripts/node-readiness.sh"]
periodSeconds: 10
env:
{{- include "chain.env" $chain | nindent 10 }}
Expand Down

0 comments on commit 5ab3a0f

Please sign in to comment.