-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: [#508] add container healthcheck for API
- Loading branch information
1 parent
0ef4e34
commit 48ac64f
Showing
10 changed files
with
94 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
//! API handlers for the [`stats`](crate::servers::apis::v1::context::health_check) | ||
//! API context. | ||
|
||
use axum::Json; | ||
|
||
use super::resources::{Report, Status}; | ||
|
||
/// Endpoint for container health check. | ||
pub async fn health_check_handler() -> Json<Report> { | ||
Json(Report { status: Status::Ok }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
//! API health check endpoint. | ||
//! | ||
//! It is used to check is the service is running. Especially for containers. | ||
//! | ||
//! # Endpoints | ||
//! | ||
//! - [Health Check](#health-check) | ||
//! | ||
//! # Health Check | ||
//! | ||
//! `GET /health_check` | ||
//! | ||
//! Returns the API status. | ||
//! | ||
//! **Example request** | ||
//! | ||
//! ```bash | ||
//! curl "http://127.0.0.1:1212/health_check" | ||
//! ``` | ||
//! | ||
//! **Example response** `200` | ||
//! | ||
//! ```json | ||
//! { | ||
//! "status": "Ok", | ||
//! } | ||
//! ``` | ||
//! | ||
//! **Resource** | ||
//! | ||
//! Refer to the API [`Stats`](crate::servers::apis::v1::context::health_check::resources::Report) | ||
//! resource for more information about the response attributes. | ||
pub mod handlers; | ||
pub mod resources; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
//! API resources for the [`stats`](crate::servers::apis::v1::context::health_check) | ||
//! API context. | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq)] | ||
pub enum Status { | ||
Ok, | ||
Error, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq)] | ||
pub struct Report { | ||
pub status: Status, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use torrust_tracker::servers::apis::v1::context::health_check::resources::{Report, Status}; | ||
use torrust_tracker_test_helpers::configuration; | ||
|
||
use crate::servers::api::test_environment::running_test_environment; | ||
use crate::servers::api::v1::client::get; | ||
|
||
#[tokio::test] | ||
async fn health_check_endpoint_should_return_status_ok_if_api_is_running() { | ||
let test_env = running_test_environment(configuration::ephemeral()).await; | ||
|
||
let url = format!("http://{}/health_check", test_env.get_connection_info().bind_address); | ||
|
||
let response = get(&url, None).await; | ||
|
||
assert_eq!(response.status(), 200); | ||
assert_eq!(response.headers().get("content-type").unwrap(), "application/json"); | ||
assert_eq!(response.json::<Report>().await.unwrap(), Report { status: Status::Ok }); | ||
|
||
test_env.stop().await; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pub mod auth_key; | ||
pub mod health_check; | ||
pub mod stats; | ||
pub mod torrent; | ||
pub mod whitelist; |