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

A failed sidecar on purpose #599

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
45 changes: 2 additions & 43 deletions utils/sidecar.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,49 +19,8 @@

@application.route("/is_synced")
def sync_checker():
"""
Here we don't trust the /is_bootstrapped endpoint of
octez-node. We have seen it return true when the node is
in a bad state (for example, some crashed threads)
Instead, we query the head block and verify timestamp is
not too old.
"""
try:
r = requests.get("http://127.0.0.1:8732/chains/main/blocks/head/header", timeout=NODE_CONNECT_TIMEOUT)
except ConnectTimeout as e:
err = "Timeout connect to node, %s" % repr(e), 500
application.logger.error(err)
return err
except ReadTimeout as e:
err = "Timeout read from node, %s" % repr(e), 500
application.logger.error(err)
return err
except RequestException as e:
err = "Could not connect to node, %s" % repr(e), 500
application.logger.error(err)
return err

header = r.json()
if header["level"] == 0:
# when chain has not been activated, bypass age check
# and return successfully to mark as ready
# otherwise it will never activate (activation uses rpc service)
return "Chain has not been activated yet"
timestamp = r.json()["timestamp"]
block_age = datetime.datetime.utcnow() - datetime.datetime.strptime(
timestamp, "%Y-%m-%dT%H:%M:%SZ"
)
age_in_secs = block_age.total_seconds()
if age_in_secs > AGE_LIMIT_IN_SECS:
err = (
"Error: Chain head is %s secs old, older than %s"
% (age_in_secs, AGE_LIMIT_IN_SECS),
500,
)
application.logger.error(err)
return err
return "Chain is bootstrapped"

# Fail sidecar on purpose
return "Fail sidecar on purpose", 500

if __name__ == "__main__":
application.run(host="0.0.0.0", port=31732, debug=False)