From 9c1df68a5fb3dd510c211b8e2b4b59bbe4badd0c Mon Sep 17 00:00:00 2001 From: Ning Sun Date: Wed, 25 Jun 2025 20:25:36 +0800 Subject: [PATCH] feat: introduce /v1/health for healthcheck from external (#6388) Signed-off-by: Ning Sun --- src/servers/src/http.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/servers/src/http.rs b/src/servers/src/http.rs index c59bf63875..dd7a8804ab 100644 --- a/src/servers/src/http.rs +++ b/src/servers/src/http.rs @@ -117,7 +117,7 @@ const DEFAULT_BODY_LIMIT: ReadableSize = ReadableSize::mb(64); pub const AUTHORIZATION_HEADER: &str = "x-greptime-auth"; // TODO(fys): This is a temporary workaround, it will be improved later -pub static PUBLIC_APIS: [&str; 2] = ["/v1/influxdb/ping", "/v1/influxdb/health"]; +pub static PUBLIC_APIS: [&str; 3] = ["/v1/influxdb/ping", "/v1/influxdb/health", "/v1/health"]; #[derive(Default)] pub struct HttpServer { @@ -723,6 +723,10 @@ impl HttpServer { "/health", routing::get(handler::health).post(handler::health), ) + .route( + &format!("/{HTTP_API_VERSION}/health"), + routing::get(handler::health).post(handler::health), + ) .route( "/ready", routing::get(handler::health).post(handler::health), @@ -1299,6 +1303,16 @@ mod test { "*" ); + let res = client.get("/v1/health").send().await; + + assert_eq!(res.status(), StatusCode::OK); + assert_eq!( + res.headers() + .get(http::header::ACCESS_CONTROL_ALLOW_ORIGIN) + .expect("expect cors header origin"), + "*" + ); + let res = client .options("/health") .header("Access-Control-Request-Headers", "x-greptime-auth")