Skip to content

Commit

Permalink
chore: add /ready api for health checking (#5124)
Browse files Browse the repository at this point in the history
* chore: add ready endpoint for health checking

* chore: add test
  • Loading branch information
shuiyisong authored Dec 11, 2024
1 parent 7c69ca0 commit 3d1b8c4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
13 changes: 9 additions & 4 deletions src/servers/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -638,10 +638,15 @@ impl HttpServer {
router.clone()
};

router = router.route(
"/health",
routing::get(handler::health).post(handler::health),
);
router = router
.route(
"/health",
routing::get(handler::health).post(handler::health),
)
.route(
"/ready",
routing::get(handler::health).post(handler::health),
);

router = router.route("/status", routing::get(handler::status));

Expand Down
33 changes: 19 additions & 14 deletions tests-integration/tests/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -757,21 +757,26 @@ pub async fn test_health_api(store_type: StorageType) {
let (app, _guard) = setup_test_http_app_with_frontend(store_type, "health_api").await;
let client = TestClient::new(app);

// we can call health api with both `GET` and `POST` method.
let res_post = client.post("/health").send().await;
assert_eq!(res_post.status(), StatusCode::OK);
let res_get = client.get("/health").send().await;
assert_eq!(res_get.status(), StatusCode::OK);

// both `GET` and `POST` method return same result
let body_text = res_post.text().await;
assert_eq!(body_text, res_get.text().await);

// currently health api simply returns an empty json `{}`, which can be deserialized to an empty `HealthResponse`
assert_eq!(body_text, "{}");
async fn health_api(client: &TestClient, endpoint: &str) {
// we can call health api with both `GET` and `POST` method.
let res_post = client.post(endpoint).send().await;
assert_eq!(res_post.status(), StatusCode::OK);
let res_get = client.get(endpoint).send().await;
assert_eq!(res_get.status(), StatusCode::OK);

// both `GET` and `POST` method return same result
let body_text = res_post.text().await;
assert_eq!(body_text, res_get.text().await);

// currently health api simply returns an empty json `{}`, which can be deserialized to an empty `HealthResponse`
assert_eq!(body_text, "{}");

let body = serde_json::from_str::<HealthResponse>(&body_text).unwrap();
assert_eq!(body, HealthResponse {});
}

let body = serde_json::from_str::<HealthResponse>(&body_text).unwrap();
assert_eq!(body, HealthResponse {});
health_api(&client, "/health").await;
health_api(&client, "/ready").await;
}

pub async fn test_status_api(store_type: StorageType) {
Expand Down

0 comments on commit 3d1b8c4

Please sign in to comment.