athena_rs 0.83.0

Database gateway API
Documentation
//! Health check endpoints for Athena RS.
//!
//! This module provides endpoints to verify the service is running and healthy.

use actix_web::{HttpResponse, get, web};
use serde_json::json;

use crate::AppState;

/// API root and route listing.
///
/// Returns health status, version, backend statuses (`athena_api`, `athena_deadpool`,
/// `athena_scylladb`), and a list of available routes with methods and summaries.
#[get("/")]
pub async fn root(app_state: web::Data<AppState>) -> HttpResponse {
    let athena_deadpool = if app_state.pg_registry.list_clients().is_empty() {
        "offline"
    } else {
        "online"
    };

    let body = json!({
        "message": "athena is online",
        "version": env!("CARGO_PKG_VERSION"),
        "athena_api": "online",
        "athena_deadpool": athena_deadpool,
        "athena_scylladb": "online",
        "cargo_toml_version": env!("CARGO_PKG_VERSION"),
        "routes": [
            { "path": "/", "methods": ["GET"], "summary": "API root and route listing" },
            { "path": "/ping", "methods": ["GET"], "summary": "Health check" },
            { "path": "/clients", "methods": ["GET"], "summary": "List Athena clients (protected)" },
            { "path": "/schema/clients", "methods": ["GET"], "summary": "List Postgres clients" },
            { "path": "/schema/tables", "methods": ["GET"], "summary": "List tables" },
            { "path": "/schema/columns", "methods": ["GET"], "summary": "List columns" },
            { "path": "/schema/migrations", "methods": ["GET"], "summary": "List schema migrations (graceful fallback when table absent)" },
            { "path": "/router/registry", "methods": ["GET"], "summary": "Athena router registry" },
            { "path": "/registry", "methods": ["GET"], "summary": "API registry" },
            { "path": "/gateway/fetch", "methods": ["POST"], "summary": "Fetch data" },
            { "path": "/gateway/update", "methods": ["POST"], "summary": "Update data" },
            { "path": "/gateway/insert", "methods": ["PUT"], "summary": "Insert data" },
            { "path": "/gateway/delete", "methods": ["DELETE"], "summary": "Delete data" },
            { "path": "/gateway/query", "methods": ["POST"], "summary": "Execute SQL" },
            { "path": "/query/sql", "methods": ["POST"], "summary": "Execute SQL via driver" },
            { "path": "/pipelines", "methods": ["POST"], "summary": "Run pipeline" },
            { "path": "/admin/api-keys", "methods": ["GET", "POST"], "summary": "Manage API keys" },
            { "path": "/admin/api-keys/{id}", "methods": ["PATCH", "DELETE"], "summary": "Update or delete an API key" },
            { "path": "/admin/api-key-rights", "methods": ["GET", "POST"], "summary": "Manage API key rights" },
            { "path": "/admin/api-key-rights/{id}", "methods": ["PATCH", "DELETE"], "summary": "Update or delete an API key right" },
            { "path": "/admin/api-key-config", "methods": ["GET", "PUT"], "summary": "Manage global API key enforcement" },
            { "path": "/admin/api-key-clients", "methods": ["GET"], "summary": "List per-client API key enforcement" },
            { "path": "/admin/api-key-clients/{client_name}", "methods": ["PUT", "DELETE"], "summary": "Manage per-client API key enforcement" },
            { "path": "/openapi.yaml", "methods": ["GET"], "summary": "OpenAPI spec" },
            { "path": "/docs", "methods": ["GET"], "summary": "Documentation redirect" },
        ],
    });

    HttpResponse::Ok()
        .content_type("application/json")
        .json(body)
}

/// Health check endpoint that returns a simple pong response.
///
/// Used by load balancers, orchestrators, and monitoring systems to verify
/// that the Athena RS service is running and responding to requests.
///
/// # Returns
///
/// Returns HTTP 200 with plain text body "pong"
#[get("/ping")]
pub async fn ping() -> HttpResponse {
    HttpResponse::Ok()
        .content_type("text/plain; charset=utf-8")
        .body("pong")
}