11use crate :: server:: app_state:: AppState ;
22use crate :: server:: error:: { AppError , AppStatus } ;
33use crate :: server:: extractor:: RequestExtractor ;
4+ use crate :: server:: model:: { BackendStatus , ServiceStatus } ;
45use crate :: server:: response:: { ApiError , ApiResponse } ;
56use axum:: Router ;
67use axum:: extract:: State ;
@@ -16,6 +17,7 @@ pub fn router(metrics_handle: PrometheusHandle) -> Router<Arc<AppState>> {
1617 . route ( "/healthy" , get ( healthy) )
1718 . route ( "/ready" , get ( redis) )
1819 . route ( "/redis" , get ( redis) )
20+ . route ( "/status" , get ( status) )
1921 . route (
2022 "/metrics" ,
2123 get ( move || {
@@ -43,3 +45,34 @@ async fn redis(RequestExtractor(request): RequestExtractor, State(state): State<
4345 . map_err ( |r| AppError :: new ( AppStatus :: NO_REDIS , r) )
4446 . map_err ( |e| ApiError :: internal_server ( e, request) )
4547}
48+
49+ #[ instrument( skip_all) ]
50+ async fn status ( State ( state) : State < Arc < AppState > > ) -> ApiResponse < BackendStatus > {
51+ let mut services = Vec :: new ( ) ;
52+
53+ // Redis
54+ match state. redis_connection . clone ( ) {
55+ Some ( mut con) => match con. ping ( ) . await {
56+ Ok ( _) => services. push ( ServiceStatus :: healthy ( "redis" ) ) ,
57+ Err ( e) => services. push ( ServiceStatus :: unhealthy ( "redis" , e. to_string ( ) ) ) ,
58+ } ,
59+ None => services. push ( ServiceStatus :: unhealthy ( "redis" , "未配置" ) ) ,
60+ }
61+
62+ // Loki
63+ match std:: env:: var ( "LOKI_URL" ) {
64+ Ok ( url) if !url. is_empty ( ) => services. push ( ServiceStatus :: healthy ( "loki" ) ) ,
65+ _ => services. push ( ServiceStatus :: unhealthy ( "loki" , "未配置 LOKI_URL" ) ) ,
66+ }
67+
68+ // Tempo (OTLP)
69+ match std:: env:: var ( "OTLP_GRPC" ) {
70+ Ok ( url) if !url. is_empty ( ) => services. push ( ServiceStatus :: healthy ( "tempo" ) ) ,
71+ _ => services. push ( ServiceStatus :: unhealthy ( "tempo" , "未配置 OTLP_GRPC" ) ) ,
72+ }
73+
74+ ApiResponse :: ok ( BackendStatus {
75+ version : env ! ( "CARGO_PKG_VERSION" ) . to_string ( ) ,
76+ services,
77+ } )
78+ }
0 commit comments