Skip to content

Commit

Permalink
Update API healthchecks (#778)
Browse files Browse the repository at this point in the history
* Chore - add vault healthcheck

* Chore - add vault healthcheck

* Chore - add vault healthcheck
  • Loading branch information
ns212 authored May 22, 2023
1 parent 65b0748 commit 8ff52df
Showing 1 changed file with 73 additions and 18 deletions.
91 changes: 73 additions & 18 deletions api/health.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import dateutil.parser
from datetime import datetime
from dateutil.tz import tzutc
from flask import Flask, jsonify
from flask import Flask, jsonify, abort


class Oracle:
Expand Down Expand Up @@ -80,30 +80,85 @@ def isHealthy(self):
return status["chainHeightDiff"] < 3 and status["secondsDiff"] < 7200 # 2hrs


KSM_URL = "https://api-kusama.interlay.io/graphql/graphql"
INTR_URL = "https://api.interlay.io/graphql/graphql"

app = Flask(__name__)

class Vault:
def __init__(self, baseUrl) -> None:
self.baseUrl = baseUrl

@app.route("/_health/ksm/oracle", methods=["GET"])
def get_ksm_oracle_health():
return jsonify(Oracle(KSM_URL, "KSM").isHealthy())
def _latestVaults(self):
q = """
query MyQuery {
vaults(limit: 10, orderBy: registrationBlock_active_DESC) {
id
registrationTimestamp
}
}
"""
payload = {"query": q, "variables": None}
resp = requests.post(self.baseUrl, json=payload)
return resp.json()["data"]["vaults"]

def isHealthy(self):
vaults = self._latestVaults()
return len(self._latestVaults()) > 0

@app.route("/_health/ksm/relay", methods=["GET"])
def get_ksm_relayer_health():
return jsonify(Relayer(KSM_URL).isHealthy())

KSM_URL = "https://api-kusama.interlay.io/graphql/graphql"
INTR_URL = "https://api.interlay.io/graphql/graphql"
TESTNET_INTR = "https://api-testnet.interlay.io/graphql/graphql"
TESTNET_KINT = "https://api-dev-kintsugi.interlay.io/graphql/graphql"

@app.route("/_health/intr/oracle", methods=["GET"])
def get_intr_oracle_health():
return jsonify(Oracle(INTR_URL, "DOT").isHealthy())
app = Flask(__name__)


@app.route("/_health/intr/relay", methods=["GET"])
def get_intr_relayer_health():
return jsonify(Relayer(INTR_URL).isHealthy())
@app.route("/_health/<chain>/oracle", methods=["GET"])
def get_oracle_health(chain):
def oracle():
if chain == "kint":
return Oracle(KSM_URL, "KSM")
elif chain == "intr":
return Oracle(INTR_URL, "DOT")
elif chain == "testnet_kint":
return Oracle(TESTNET_KINT, "KSM")
elif chain == "testnet_intr":
return Oracle(TESTNET_INTR, "DOT")
else:
abort(404)

return jsonify(oracle().isHealthy())


@app.route("/_health/<chain>/relay", methods=["GET"])
def get_relay_health(chain):
def relay():
if chain == "kint":
return Relayer(KSM_URL)
elif chain == "intr":
return Relayer(INTR_URL)
elif chain == "testnet_kint":
return Relayer(TESTNET_KINT)
elif chain == "testnet_intr":
return Relayer(TESTNET_INTR)
else:
abort(404)

return jsonify(relay().isHealthy())


@app.route("/_health/<chain>/vault", methods=["GET"])
def get_vault_health(chain):
def vault():
if chain == "kint":
return Vault(KSM_URL)
elif chain == "intr":
return Vault(INTR_URL)
elif chain == "testnet_kint":
return Vault(TESTNET_KINT)
elif chain == "testnet_intr":
return Vault(TESTNET_INTR)
else:
abort(404)

return jsonify(vault().isHealthy())


if __name__ == "__main__":
Expand Down

2 comments on commit 8ff52df

@vercel
Copy link

@vercel vercel bot commented on 8ff52df May 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 8ff52df May 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.