2022-10-18 00:47:58 +03:00
|
|
|
//! Used by admins for health checks and inspecting global statistics.
|
|
|
|
//!
|
|
|
|
//! For ease of development, users can currently access these endponts.
|
|
|
|
//! They will eventually move to another port.
|
|
|
|
|
2022-08-16 22:29:00 +03:00
|
|
|
use crate::app::Web3ProxyApp;
|
2022-09-10 05:59:07 +03:00
|
|
|
use axum::{http::StatusCode, response::IntoResponse, Extension, Json};
|
2022-10-27 03:12:42 +03:00
|
|
|
use axum_macros::debug_handler;
|
2022-09-10 05:59:07 +03:00
|
|
|
use moka::future::ConcurrentCacheExt;
|
|
|
|
use serde_json::json;
|
2022-09-09 06:53:16 +03:00
|
|
|
use std::sync::Arc;
|
2022-06-05 22:58:47 +03:00
|
|
|
|
2022-10-18 00:47:58 +03:00
|
|
|
/// Health check page for load balancers to use.
|
2022-10-20 01:26:33 +03:00
|
|
|
#[debug_handler]
|
2022-11-12 11:24:32 +03:00
|
|
|
|
2022-07-07 06:22:09 +03:00
|
|
|
pub async fn health(Extension(app): Extension<Arc<Web3ProxyApp>>) -> impl IntoResponse {
|
2022-09-12 17:33:55 +03:00
|
|
|
// TODO: also check that the head block is not too old
|
2022-08-10 08:56:09 +03:00
|
|
|
if app.balanced_rpcs.synced() {
|
2022-06-29 21:22:53 +03:00
|
|
|
(StatusCode::OK, "OK")
|
|
|
|
} else {
|
|
|
|
(StatusCode::SERVICE_UNAVAILABLE, ":(")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-18 00:47:58 +03:00
|
|
|
/// Prometheus metrics.
|
|
|
|
///
|
2022-09-10 05:59:07 +03:00
|
|
|
/// TODO: when done debugging, remove this and only allow access on a different port
|
2022-10-20 01:26:33 +03:00
|
|
|
#[debug_handler]
|
2022-11-12 11:24:32 +03:00
|
|
|
|
2022-09-10 05:59:07 +03:00
|
|
|
pub async fn prometheus(Extension(app): Extension<Arc<Web3ProxyApp>>) -> impl IntoResponse {
|
|
|
|
app.prometheus_metrics()
|
|
|
|
}
|
|
|
|
|
2022-10-18 00:47:58 +03:00
|
|
|
/// Very basic status page.
|
|
|
|
///
|
2022-08-05 22:22:23 +03:00
|
|
|
/// TODO: replace this with proper stats and monitoring
|
2022-10-20 01:26:33 +03:00
|
|
|
#[debug_handler]
|
2022-11-12 11:24:32 +03:00
|
|
|
|
2022-07-07 06:22:09 +03:00
|
|
|
pub async fn status(Extension(app): Extension<Arc<Web3ProxyApp>>) -> impl IntoResponse {
|
2022-09-10 05:59:07 +03:00
|
|
|
app.pending_transactions.sync();
|
2022-11-01 21:54:39 +03:00
|
|
|
app.rpc_secret_key_cache.sync();
|
2022-09-10 05:59:07 +03:00
|
|
|
|
2022-09-12 17:33:55 +03:00
|
|
|
// TODO: what else should we include? uptime, cache hit rates, cpu load
|
2022-09-10 05:59:07 +03:00
|
|
|
let body = json!({
|
|
|
|
"pending_transactions_count": app.pending_transactions.entry_count(),
|
|
|
|
"pending_transactions_size": app.pending_transactions.weighted_size(),
|
2022-11-01 21:54:39 +03:00
|
|
|
"user_cache_count": app.rpc_secret_key_cache.entry_count(),
|
|
|
|
"user_cache_size": app.rpc_secret_key_cache.weighted_size(),
|
2022-09-10 05:59:07 +03:00
|
|
|
"balanced_rpcs": app.balanced_rpcs,
|
|
|
|
"private_rpcs": app.private_rpcs,
|
|
|
|
});
|
|
|
|
|
|
|
|
Json(body)
|
2022-06-05 22:58:47 +03:00
|
|
|
}
|