Skip to content

Commit

Permalink
feat(health): add health check endpoint at /healthz
Browse files Browse the repository at this point in the history
  • Loading branch information
enchantednatures committed Jan 16, 2025
1 parent 05aec6f commit 703f1a8
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 1 deletion.
15 changes: 15 additions & 0 deletions crates/atuin-server/src/handlers/health.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use axum::{http, response::IntoResponse, Json};

use serde::Serialize;

#[derive(Serialize)]
pub struct HealthResponse {
pub status: &'static str,
}

pub async fn health_check() -> impl IntoResponse {
(
http::StatusCode::OK,
Json(HealthResponse { status: "healthy" }),
)
}
1 change: 1 addition & 0 deletions crates/atuin-server/src/handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use axum::{extract::State, http, response::IntoResponse, Json};

use crate::router::AppState;

pub mod health;
pub mod history;
pub mod record;
pub mod status;
Expand Down
1 change: 1 addition & 0 deletions crates/atuin-server/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ pub struct AppState<DB: Database> {
pub fn router<DB: Database>(database: DB, settings: Settings<DB::Settings>) -> Router {
let routes = Router::new()
.route("/", get(handlers::index))
.route("/healthz", get(handlers::health::health_check))
.route("/sync/count", get(handlers::history::count))
.route("/sync/history", get(handlers::history::list))
.route("/sync/calendar/:focus", get(handlers::history::calendar))
Expand Down
5 changes: 5 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ services:
ATUIN_OPEN_REGISTRATION: "true"
ATUIN_DB_URI: postgres://$ATUIN_DB_USERNAME:$ATUIN_DB_PASSWORD@db/$ATUIN_DB_NAME
RUST_LOG: info,atuin_server=debug
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8888/healthz"]
interval: 10s
timeout: 5s
retries: 3
postgresql:
image: postgres:14
restart: unless-stopped
Expand Down
19 changes: 18 additions & 1 deletion k8s/atuin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,31 @@ spec:
image: ghcr.io/atuinsh/atuin:latest
name: atuin
ports:
- containerPort: 8888
- containerPort: &port 8888
resources:
limits:
cpu: 250m
memory: 1Gi
requests:
cpu: 250m
memory: 1Gi
startupProbe:
httpGet:
path: /healthz
port: *port
failureThreshold: 30
periodSeconds: 10
livenessProbe:
httpGet:
path: /healthz
port: *port
initialDelaySeconds: 3
periodSeconds: 3
readinessProbe:
tcpSocket:
port: *port
initialDelaySeconds: 15
periodSeconds: 10
volumeMounts:
- mountPath: /config
name: atuin-claim0
Expand Down

0 comments on commit 703f1a8

Please sign in to comment.