status codes on health

This commit is contained in:
Bryan Stitt 2022-06-29 18:22:53 +00:00
parent 0fbbd1b34d
commit 98e027b966
4 changed files with 16 additions and 2 deletions

View File

@ -30,7 +30,6 @@
- even after removing a bunch of the locks, the deadlock still happens. i can't reliably reproduce. i just let it run for awhile and it happens.
- running gdb shows the thread at tokio tungstenite thread is spinning near 100% cpu and none of the rest of the program is proceeding
- fixed by https://github.com/gakonst/ethers-rs/pull/1287
- [ ] quick requests/second timer until we have real stats
- [ ] rpc errors propagate too far. one subscription failing ends the app. isolate the providers more
- [ ] if web3 proxy gets an http error back, retry another node
- [ ] endpoint for health checks. if no synced servers, give a 502 error

View File

@ -315,6 +315,10 @@ impl Web3Connections {
*self.synced_connections.load().get_head_block_hash()
}
pub fn has_synced_rpcs(&self) -> bool {
self.synced_connections.load().inner.len() > 0
}
/// Send the same request to all the handles. Returning the most common success or most common error.
#[instrument(skip_all)]
pub async fn try_send_parallel_requests(

View File

@ -11,6 +11,15 @@ pub async fn index() -> impl IntoResponse {
"Hello, World!"
}
/// Health check page for load balancers to use
pub async fn health(app: Extension<Arc<Web3ProxyApp>>) -> impl IntoResponse {
if app.get_balanced_rpcs().has_synced_rpcs() {
(StatusCode::OK, "OK")
} else {
(StatusCode::SERVICE_UNAVAILABLE, ":(")
}
}
/// Very basic status page
pub async fn status(app: Extension<Arc<Web3ProxyApp>>) -> impl IntoResponse {
// TODO: what else should we include? uptime? prometheus?

View File

@ -21,8 +21,10 @@ pub async fn run(port: u16, proxy_app: Arc<Web3ProxyApp>) -> anyhow::Result<()>
.route("/", post(http_proxy::proxy_web3_rpc))
// `websocket /` goes to `proxy_web3_ws`
.route("/", get(ws_proxy::websocket_handler))
// `GET /index.html` goes to `index` (todo, somehow combine this with http_proxy::proxy_web3_rpc)
// `GET /index.html` goes to `index`
.route("/index.html", get(http::index))
// `GET /health` goes to `health`
.route("/health", get(http::health))
// `GET /status` goes to `status`
.route("/status", get(http::status))
.layer(Extension(proxy_app));