athena_rs 3.18.0

Hyper performant polyglot Database driver
Documentation
//! Shared payload composition for `/` and `/health` endpoints.
//!
//! This module centralizes construction of root and health response bodies so
//! route handlers can focus on HTTP flow and provisioning inspection.

use serde_json::{Map, Value, json};

use crate::AppState;
use crate::api::health_capabilities::local_capabilities;
use crate::api::health_routes_catalog::advertised_routes;
use crate::api::health_status::{
    athena_deadpool_status, gateway_auth_store_status, gateway_benchmark_client_status,
};
use crate::provisioning::LocalProvisionDependencyStatus;

/// Builds the JSON body for `GET /` root health metadata.
pub(super) fn build_root_health_payload(
    app_state: &AppState,
    provisioning_status: &LocalProvisionDependencyStatus,
) -> Value {
    let mut body = base_health_payload(app_state);
    body.insert("routes".to_string(), json!(advertised_routes()));
    body.insert(
        "provisioning".to_string(),
        provisioning_json(provisioning_status),
    );
    Value::Object(body)
}

/// Builds the JSON body for `GET /health` local diagnostics.
pub(super) fn build_health_payload(
    app_state: &AppState,
    provisioning_status: &LocalProvisionDependencyStatus,
) -> Value {
    let mut body = base_health_payload(app_state);
    body.insert("status".to_string(), json!("ok"));
    body.insert(
        "provisioning".to_string(),
        provisioning_json(provisioning_status),
    );
    Value::Object(body)
}

/// Builds common health metadata shared by root and `/health` responses.
fn base_health_payload(app_state: &AppState) -> Map<String, Value> {
    let mut body = Map::new();
    body.insert("message".to_string(), json!("athena is online"));
    body.insert("version".to_string(), json!(env!("CARGO_PKG_VERSION")));
    body.insert("athena_api".to_string(), json!("online"));
    body.insert(
        "athena_deadpool".to_string(),
        json!(athena_deadpool_status(app_state)),
    );
    body.insert("athena_scylladb".to_string(), json!("online"));
    body.insert(
        "gateway_auth_store".to_string(),
        json!(gateway_auth_store_status(app_state)),
    );
    body.insert(
        "gateway_benchmark_client".to_string(),
        json!(gateway_benchmark_client_status(app_state)),
    );
    body.insert(
        "cargo_toml_version".to_string(),
        json!(env!("CARGO_PKG_VERSION")),
    );
    body.insert("capabilities".to_string(), json!(local_capabilities()));
    body
}

/// Builds provisioning diagnostics JSON for local Docker runtime health.
fn provisioning_json(provisioning_status: &LocalProvisionDependencyStatus) -> Value {
    json!({
        "local_docker": provisioning_status.docker_runtime_access,
    })
}