darkwing/server/api/
mod.rsmod start_controller;
mod stop_controller;
use axum::{routing::*, Json};
use self::start_controller::StartController;
use self::stop_controller::StopController;
use super::{
dtos::health_dto::{
HealthResponse, ServiceStatus, ServiceStatuses, HEALTHCHECK_S3_KEY,
},
error::AppResult,
extractors::ServiceProvider,
services::cloud_file_services::S3ClientType,
};
pub async fn metrics(
ServiceProvider(services): ServiceProvider,
) -> AppResult<String> {
Ok(services.recorder_handle.render())
}
pub async fn health() -> AppResult<Json<HealthResponse>> {
Ok(Json(HealthResponse::new(None, None)))
}
pub async fn full_health(
ServiceProvider(services): ServiceProvider,
) -> AppResult<Json<HealthResponse>> {
let primary_s3 = services
.cloud_files
.does_file_exist(HEALTHCHECK_S3_KEY, S3ClientType::Primary)
.await;
let primary_s3 = ServiceStatus {
status: primary_s3.is_ok(),
message: primary_s3.err().map(|e| e.to_string()),
};
let backup_s3 = services
.cloud_files
.does_file_exist(HEALTHCHECK_S3_KEY, S3ClientType::Backup)
.await;
let backup_s3 = ServiceStatus {
status: backup_s3.is_ok(),
message: backup_s3.err().map(|e| e.to_string()),
};
let s3_status = ServiceStatuses {
primary_s3,
backup_s3,
};
let health_response = services.status.get_health_status(s3_status).await?;
Ok(Json(health_response))
}
pub fn app() -> Router {
Router::new()
.nest("/start", StartController::app())
.nest("/stop", StopController::app())
.route("/health", get(health))
.route("/full-health", get(full_health))
}