Skip to content

Commit

Permalink
Merge #1297: Refactor packages: extract `axum-health-check-api-server…
Browse files Browse the repository at this point in the history
…` package

3e81d3e refactor: [#1287] extract axum-health-check-api-server package (Jose Celano)

Pull request description:

  Refactor packages:  extract `axum-health-check-api-server` package.

ACKs for top commit:
  josecelano:
    ACK 3e81d3e

Tree-SHA512: 918775dd14abe6a52e655aecd3fffda32f9e5cd522502b9155c34dcd127a9593c4b6bc6aa6abfa738c34bbc3173a0ef698e2ea5f5eba9a59b9371e5ca3d7348b
  • Loading branch information
josecelano committed Feb 19, 2025
2 parents 6415d09 + 3e81d3e commit 08b0c52
Show file tree
Hide file tree
Showing 17 changed files with 769 additions and 14 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ jobs:
cargo publish -p bittorrent-tracker-core
cargo publish -p bittorrent-udp-tracker-core
cargo publish -p bittorrent-udp-tracker-protocol
cargo publish -p torrust-axum-health-check-api-server
cargo publish -p torrust-axum-http-tracker-server
cargo publish -p torrust-axum-server
cargo publish -p torrust-torrust-server-lib
Expand All @@ -75,5 +76,3 @@ jobs:
cargo publish -p torrust-tracker-primitives
cargo publish -p torrust-tracker-test-helpers
cargo publish -p torrust-tracker-torrent-repository
18 changes: 18 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ serde_repr = "0"
serde_with = { version = "3", features = ["json"] }
thiserror = "2"
tokio = { version = "1", features = ["macros", "net", "rt-multi-thread", "signal", "sync"] }
torrust-axum-health-check-api-server = { version = "3.0.0-develop", path = "packages/axum-health-check-api-server" }
torrust-axum-http-tracker-server = { version = "3.0.0-develop", path = "packages/axum-http-tracker-server" }
torrust-axum-server = { version = "3.0.0-develop", path = "packages/axum-server" }
torrust-server-lib = { version = "3.0.0-develop", path = "packages/server-lib" }
Expand Down
1 change: 1 addition & 0 deletions cSpell.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"gecos",
"Grcov",
"hasher",
"healthcheck",
"heaptrack",
"hexlify",
"hlocalhost",
Expand Down
29 changes: 29 additions & 0 deletions packages/axum-health-check-api-server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[package]
authors.workspace = true
description = "The Torrust Bittorrent HTTP tracker."
documentation.workspace = true
edition.workspace = true
homepage.workspace = true
keywords = ["axum", "bittorrent", "healthcheck", "http", "server", "torrust", "tracker"]
license.workspace = true
name = "torrust-axum-health-check-api-server"
publish.workspace = true
readme = "README.md"
repository.workspace = true
rust-version.workspace = true
version.workspace = true

[dependencies]
axum = { version = "0", features = ["macros"] }
axum-server = { version = "0", features = ["tls-rustls-no-provider"] }
futures = "0"
hyper = "1"
serde = { version = "1", features = ["derive"] }
serde_json = { version = "1", features = ["preserve_order"] }
tokio = { version = "1", features = ["macros", "net", "rt-multi-thread", "signal", "sync"] }
torrust-axum-server = { version = "3.0.0-develop", path = "../axum-server" }
torrust-server-lib = { version = "3.0.0-develop", path = "../server-lib" }
tower-http = { version = "0", features = ["compression-full", "cors", "propagate-header", "request-id", "trace"] }
tracing = "0"

[dev-dependencies]
661 changes: 661 additions & 0 deletions packages/axum-health-check-api-server/LICENSE

Large diffs are not rendered by default.

49 changes: 49 additions & 0 deletions packages/axum-health-check-api-server/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Torrust Axum HTTP Tracker

The Torrust Tracker Health Check API.

The Torrust tracker container starts a local HTTP server on port 1313 to check all services.

It's used for the container health check.

URL: <http://127.0.0.1:1313/health_check>

Example response:

```json
{
"status": "Ok",
"message": "",
"details": [
{
"binding": "0.0.0.0:6969",
"info": "checking the udp tracker health check at: 0.0.0.0:6969",
"result": {
"Ok": "Connected"
}
},
{
"binding": "0.0.0.0:1212",
"info": "checking api health check at: http://0.0.0.0:1212/api/health_check",
"result": {
"Ok": "200 OK"
}
},
{
"binding": "0.0.0.0:7070",
"info": "checking http tracker health check at: http://0.0.0.0:7070/health_check",
"result": {
"Ok": "200 OK"
}
}
]
}
```

## Documentation

[Crate documentation](https://docs.rs/torrust-axum-health-check-api-server).

## License

The project is licensed under the terms of the [GNU AFFERO GENERAL PUBLIC LICENSE](./LICENSE).
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ use tower_http::trace::{DefaultMakeSpan, TraceLayer};
use tower_http::LatencyUnit;
use tracing::{instrument, Level, Span};

use crate::servers::health_check_api::handlers::health_check_handler;
use crate::servers::health_check_api::HEALTH_CHECK_API_LOG_TARGET;
use crate::handlers::health_check_handler;
use crate::HEALTH_CHECK_API_LOG_TARGET;

/// Starts Health Check API server.
///
Expand Down
3 changes: 1 addition & 2 deletions src/bootstrap/jobs/health_check_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@
use tokio::sync::oneshot;
use tokio::task::JoinHandle;
use torrust_axum_health_check_api_server::{server, HEALTH_CHECK_API_LOG_TARGET};
use torrust_server_lib::logging::STARTED_ON;
use torrust_server_lib::registar::ServiceRegistry;
use torrust_server_lib::signals::{Halted, Started};
use torrust_tracker_configuration::HealthCheckApi;
use tracing::instrument;

use crate::servers::health_check_api::{server, HEALTH_CHECK_API_LOG_TARGET};

/// This function starts a new Health Check API server with the provided
/// configuration.
///
Expand Down
3 changes: 1 addition & 2 deletions src/console/ci/e2e/logs_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
use bittorrent_udp_tracker_core::UDP_TRACKER_LOG_TARGET;
use regex::Regex;
use serde::{Deserialize, Serialize};
use torrust_axum_health_check_api_server::HEALTH_CHECK_API_LOG_TARGET;
use torrust_axum_http_tracker_server::HTTP_TRACKER_LOG_TARGET;
use torrust_server_lib::logging::STARTED_ON;

use crate::servers::health_check_api::HEALTH_CHECK_API_LOG_TARGET;

const INFO_THRESHOLD: &str = "INFO";

#[derive(Serialize, Deserialize, Debug, Default)]
Expand Down
1 change: 0 additions & 1 deletion src/servers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//! Servers. Services that can be started and stopped.
pub mod apis;
pub mod health_check_api;
pub mod udp;
8 changes: 4 additions & 4 deletions tests/servers/health_check_api/contract.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use torrust_axum_health_check_api_server::resources::{Report, Status};
use torrust_server_lib::registar::Registar;
use torrust_tracker_lib::servers::health_check_api::resources::{Report, Status};
use torrust_tracker_test_helpers::configuration;

use crate::common::logging;
Expand Down Expand Up @@ -32,7 +32,7 @@ async fn health_check_endpoint_should_return_status_ok_when_there_is_no_services
mod api {
use std::sync::Arc;

use torrust_tracker_lib::servers::health_check_api::resources::{Report, Status};
use torrust_axum_health_check_api_server::resources::{Report, Status};
use torrust_tracker_test_helpers::configuration;

use crate::common::logging;
Expand Down Expand Up @@ -142,7 +142,7 @@ mod api {
mod http {
use std::sync::Arc;

use torrust_tracker_lib::servers::health_check_api::resources::{Report, Status};
use torrust_axum_health_check_api_server::resources::{Report, Status};
use torrust_tracker_test_helpers::configuration;

use crate::common::logging;
Expand Down Expand Up @@ -251,7 +251,7 @@ mod http {
mod udp {
use std::sync::Arc;

use torrust_tracker_lib::servers::health_check_api::resources::{Report, Status};
use torrust_axum_health_check_api_server::resources::{Report, Status};
use torrust_tracker_test_helpers::configuration;

use crate::common::logging;
Expand Down
2 changes: 1 addition & 1 deletion tests/servers/health_check_api/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ use std::sync::Arc;

use tokio::sync::oneshot::{self, Sender};
use tokio::task::JoinHandle;
use torrust_axum_health_check_api_server::{server, HEALTH_CHECK_API_LOG_TARGET};
use torrust_server_lib::registar::Registar;
use torrust_server_lib::signals::{self, Halted, Started};
use torrust_tracker_configuration::HealthCheckApi;
use torrust_tracker_lib::servers::health_check_api::{server, HEALTH_CHECK_API_LOG_TARGET};

#[derive(Debug)]
pub enum Error {
Expand Down

0 comments on commit 08b0c52

Please sign in to comment.