Merge pull request #2256 from zed-industries/liveness-probe
Introduce Kubernetes liveness probe to ensure database works
This commit is contained in:
@@ -59,6 +59,13 @@ spec:
|
|||||||
ports:
|
ports:
|
||||||
- containerPort: 8080
|
- containerPort: 8080
|
||||||
protocol: TCP
|
protocol: TCP
|
||||||
|
livenessProbe:
|
||||||
|
httpGet:
|
||||||
|
path: /healthz
|
||||||
|
port: 8080
|
||||||
|
initialDelaySeconds: 5
|
||||||
|
periodSeconds: 5
|
||||||
|
timeoutSeconds: 5
|
||||||
readinessProbe:
|
readinessProbe:
|
||||||
httpGet:
|
httpGet:
|
||||||
path: /
|
path: /
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use axum::{routing::get, Router};
|
use axum::{routing::get, Extension, Router};
|
||||||
use collab::{db, env, executor::Executor, AppState, Config, MigrateConfig, Result};
|
use collab::{db, env, executor::Executor, AppState, Config, MigrateConfig, Result};
|
||||||
use db::Database;
|
use db::Database;
|
||||||
use std::{
|
use std::{
|
||||||
env::args,
|
env::args,
|
||||||
net::{SocketAddr, TcpListener},
|
net::{SocketAddr, TcpListener},
|
||||||
path::Path,
|
path::Path,
|
||||||
|
sync::Arc,
|
||||||
};
|
};
|
||||||
use tokio::signal::unix::SignalKind;
|
use tokio::signal::unix::SignalKind;
|
||||||
use tracing_log::LogTracer;
|
use tracing_log::LogTracer;
|
||||||
@@ -66,7 +67,12 @@ async fn main() -> Result<()> {
|
|||||||
|
|
||||||
let app = collab::api::routes(rpc_server.clone(), state.clone())
|
let app = collab::api::routes(rpc_server.clone(), state.clone())
|
||||||
.merge(collab::rpc::routes(rpc_server.clone()))
|
.merge(collab::rpc::routes(rpc_server.clone()))
|
||||||
.merge(Router::new().route("/", get(handle_root)));
|
.merge(
|
||||||
|
Router::new()
|
||||||
|
.route("/", get(handle_root))
|
||||||
|
.route("/healthz", get(handle_liveness_probe))
|
||||||
|
.layer(Extension(state.clone())),
|
||||||
|
);
|
||||||
|
|
||||||
axum::Server::from_tcp(listener)?
|
axum::Server::from_tcp(listener)?
|
||||||
.serve(app.into_make_service_with_connect_info::<SocketAddr>())
|
.serve(app.into_make_service_with_connect_info::<SocketAddr>())
|
||||||
@@ -95,6 +101,11 @@ async fn handle_root() -> String {
|
|||||||
format!("collab v{VERSION}")
|
format!("collab v{VERSION}")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn handle_liveness_probe(Extension(state): Extension<Arc<AppState>>) -> Result<String> {
|
||||||
|
state.db.get_all_users(0, 1).await?;
|
||||||
|
Ok("ok".to_string())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn init_tracing(config: &Config) -> Option<()> {
|
pub fn init_tracing(config: &Config) -> Option<()> {
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use tracing_subscriber::layer::SubscriberExt;
|
use tracing_subscriber::layer::SubscriberExt;
|
||||||
|
|||||||
Reference in New Issue
Block a user