iota_rest_kv/routes/
health.rs

1// Copyright (c) 2025 IOTA Stiftung
2// SPDX-License-Identifier: Apache-2.0
3
4use axum::{Json, extract::State, response::IntoResponse};
5use serde::Serialize;
6
7use crate::{kv_store_client::AwsStatus, types::SharedKvStoreClient};
8
9bin_version::bin_version!();
10
11/// Represent a health status response of the REST API server.
12#[derive(Serialize)]
13pub struct HealthResponse {
14    /// Version of the binary.
15    pub version: String,
16    /// The Git hash of the binary.
17    pub git_hash: String,
18    /// The total uptime of the REST API server.
19    pub uptime: String,
20    /// The status of AWS components the REST API rely to properly function.
21    pub aws_status: AwsStatus,
22}
23
24/// Handles the health check request for the REST API server.
25///
26/// This endpoint provides information about the server's health, including
27/// the version, Git hash, uptime, and the status of dependent AWS components.
28pub async fn health(State(kv_store_client): State<SharedKvStoreClient>) -> impl IntoResponse {
29    let aws_status = kv_store_client.get_aws_health().await;
30
31    let response = HealthResponse {
32        version: VERSION.to_owned(),
33        git_hash: GIT_REVISION.to_owned(),
34        uptime: format!("{:?}", kv_store_client.get_uptime()),
35        aws_status,
36    };
37
38    Json(response)
39}