web3-proxy/web3_proxy/src/frontend/http.rs

38 lines
1.4 KiB
Rust
Raw Normal View History

2022-08-16 22:29:00 +03:00
use crate::app::Web3ProxyApp;
2022-06-05 22:58:47 +03:00
use axum::{http::StatusCode, response::IntoResponse, Extension, Json};
2022-09-07 07:11:47 +03:00
use moka::future::ConcurrentCacheExt;
2022-06-05 22:58:47 +03:00
use serde_json::json;
2022-09-07 06:54:16 +03:00
use std::sync::{atomic, Arc};
2022-09-09 00:01:36 +03:00
use tracing::instrument;
2022-06-05 22:58:47 +03:00
2022-06-29 21:22:53 +03:00
/// Health check page for load balancers to use
2022-09-09 00:01:36 +03:00
#[instrument(skip_all)]
2022-07-07 06:22:09 +03:00
pub async fn health(Extension(app): Extension<Arc<Web3ProxyApp>>) -> impl IntoResponse {
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-06-05 22:58:47 +03:00
/// Very basic status page
2022-08-05 22:22:23 +03:00
/// TODO: replace this with proper stats and monitoring
2022-09-09 00:01:36 +03:00
#[instrument(skip_all)]
2022-07-07 06:22:09 +03:00
pub async fn status(Extension(app): Extension<Arc<Web3ProxyApp>>) -> impl IntoResponse {
2022-09-09 00:01:36 +03:00
// // TODO: what else should we include? uptime?
// app.pending_transactions.sync();
// app.user_cache.sync();
// let body = json!({
// "total_queries": app.total_queries.load(atomic::Ordering::Acquire),
// "pending_transactions_count": app.pending_transactions.entry_count(),
// "pending_transactions_size": app.pending_transactions.weighted_size(),
// "user_cache_count": app.user_cache.entry_count(),
// "user_cache_size": app.user_cache.weighted_size(),
// "balanced_rpcs": app.balanced_rpcs,
// "private_rpcs": app.private_rpcs,
// });
// Json(body)
// TODO: only expose this on a different port
app.prometheus_metrics().unwrap()
2022-06-05 22:58:47 +03:00
}