Skip to content

Commit 08b0c52

Browse files
committed
Merge #1297: Refactor packages: extract axum-health-check-api-server 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
2 parents 6415d09 + 3e81d3e commit 08b0c52

File tree

17 files changed

+769
-14
lines changed

17 files changed

+769
-14
lines changed

.github/workflows/deployment.yaml

+1-2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ jobs:
6161
cargo publish -p bittorrent-tracker-core
6262
cargo publish -p bittorrent-udp-tracker-core
6363
cargo publish -p bittorrent-udp-tracker-protocol
64+
cargo publish -p torrust-axum-health-check-api-server
6465
cargo publish -p torrust-axum-http-tracker-server
6566
cargo publish -p torrust-axum-server
6667
cargo publish -p torrust-torrust-server-lib
@@ -75,5 +76,3 @@ jobs:
7576
cargo publish -p torrust-tracker-primitives
7677
cargo publish -p torrust-tracker-test-helpers
7778
cargo publish -p torrust-tracker-torrent-repository
78-
79-

Cargo.lock

+18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ serde_repr = "0"
7070
serde_with = { version = "3", features = ["json"] }
7171
thiserror = "2"
7272
tokio = { version = "1", features = ["macros", "net", "rt-multi-thread", "signal", "sync"] }
73+
torrust-axum-health-check-api-server = { version = "3.0.0-develop", path = "packages/axum-health-check-api-server" }
7374
torrust-axum-http-tracker-server = { version = "3.0.0-develop", path = "packages/axum-http-tracker-server" }
7475
torrust-axum-server = { version = "3.0.0-develop", path = "packages/axum-server" }
7576
torrust-server-lib = { version = "3.0.0-develop", path = "packages/server-lib" }

cSpell.json

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
"gecos",
6464
"Grcov",
6565
"hasher",
66+
"healthcheck",
6667
"heaptrack",
6768
"hexlify",
6869
"hlocalhost",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
[package]
2+
authors.workspace = true
3+
description = "The Torrust Bittorrent HTTP tracker."
4+
documentation.workspace = true
5+
edition.workspace = true
6+
homepage.workspace = true
7+
keywords = ["axum", "bittorrent", "healthcheck", "http", "server", "torrust", "tracker"]
8+
license.workspace = true
9+
name = "torrust-axum-health-check-api-server"
10+
publish.workspace = true
11+
readme = "README.md"
12+
repository.workspace = true
13+
rust-version.workspace = true
14+
version.workspace = true
15+
16+
[dependencies]
17+
axum = { version = "0", features = ["macros"] }
18+
axum-server = { version = "0", features = ["tls-rustls-no-provider"] }
19+
futures = "0"
20+
hyper = "1"
21+
serde = { version = "1", features = ["derive"] }
22+
serde_json = { version = "1", features = ["preserve_order"] }
23+
tokio = { version = "1", features = ["macros", "net", "rt-multi-thread", "signal", "sync"] }
24+
torrust-axum-server = { version = "3.0.0-develop", path = "../axum-server" }
25+
torrust-server-lib = { version = "3.0.0-develop", path = "../server-lib" }
26+
tower-http = { version = "0", features = ["compression-full", "cors", "propagate-header", "request-id", "trace"] }
27+
tracing = "0"
28+
29+
[dev-dependencies]

packages/axum-health-check-api-server/LICENSE

+661
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Torrust Axum HTTP Tracker
2+
3+
The Torrust Tracker Health Check API.
4+
5+
The Torrust tracker container starts a local HTTP server on port 1313 to check all services.
6+
7+
It's used for the container health check.
8+
9+
URL: <http://127.0.0.1:1313/health_check>
10+
11+
Example response:
12+
13+
```json
14+
{
15+
"status": "Ok",
16+
"message": "",
17+
"details": [
18+
{
19+
"binding": "0.0.0.0:6969",
20+
"info": "checking the udp tracker health check at: 0.0.0.0:6969",
21+
"result": {
22+
"Ok": "Connected"
23+
}
24+
},
25+
{
26+
"binding": "0.0.0.0:1212",
27+
"info": "checking api health check at: http://0.0.0.0:1212/api/health_check",
28+
"result": {
29+
"Ok": "200 OK"
30+
}
31+
},
32+
{
33+
"binding": "0.0.0.0:7070",
34+
"info": "checking http tracker health check at: http://0.0.0.0:7070/health_check",
35+
"result": {
36+
"Ok": "200 OK"
37+
}
38+
}
39+
]
40+
}
41+
```
42+
43+
## Documentation
44+
45+
[Crate documentation](https://docs.rs/torrust-axum-health-check-api-server).
46+
47+
## License
48+
49+
The project is licensed under the terms of the [GNU AFFERO GENERAL PUBLIC LICENSE](./LICENSE).

src/servers/health_check_api/server.rs packages/axum-health-check-api-server/src/server.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ use tower_http::trace::{DefaultMakeSpan, TraceLayer};
2626
use tower_http::LatencyUnit;
2727
use tracing::{instrument, Level, Span};
2828

29-
use crate::servers::health_check_api::handlers::health_check_handler;
30-
use crate::servers::health_check_api::HEALTH_CHECK_API_LOG_TARGET;
29+
use crate::handlers::health_check_handler;
30+
use crate::HEALTH_CHECK_API_LOG_TARGET;
3131

3232
/// Starts Health Check API server.
3333
///

src/bootstrap/jobs/health_check_api.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,13 @@
1616
1717
use tokio::sync::oneshot;
1818
use tokio::task::JoinHandle;
19+
use torrust_axum_health_check_api_server::{server, HEALTH_CHECK_API_LOG_TARGET};
1920
use torrust_server_lib::logging::STARTED_ON;
2021
use torrust_server_lib::registar::ServiceRegistry;
2122
use torrust_server_lib::signals::{Halted, Started};
2223
use torrust_tracker_configuration::HealthCheckApi;
2324
use tracing::instrument;
2425

25-
use crate::servers::health_check_api::{server, HEALTH_CHECK_API_LOG_TARGET};
26-
2726
/// This function starts a new Health Check API server with the provided
2827
/// configuration.
2928
///

src/console/ci/e2e/logs_parser.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
use bittorrent_udp_tracker_core::UDP_TRACKER_LOG_TARGET;
33
use regex::Regex;
44
use serde::{Deserialize, Serialize};
5+
use torrust_axum_health_check_api_server::HEALTH_CHECK_API_LOG_TARGET;
56
use torrust_axum_http_tracker_server::HTTP_TRACKER_LOG_TARGET;
67
use torrust_server_lib::logging::STARTED_ON;
78

8-
use crate::servers::health_check_api::HEALTH_CHECK_API_LOG_TARGET;
9-
109
const INFO_THRESHOLD: &str = "INFO";
1110

1211
#[derive(Serialize, Deserialize, Debug, Default)]

src/servers/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
//! Servers. Services that can be started and stopped.
22
pub mod apis;
3-
pub mod health_check_api;
43
pub mod udp;

tests/servers/health_check_api/contract.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
use torrust_axum_health_check_api_server::resources::{Report, Status};
12
use torrust_server_lib::registar::Registar;
2-
use torrust_tracker_lib::servers::health_check_api::resources::{Report, Status};
33
use torrust_tracker_test_helpers::configuration;
44

55
use crate::common::logging;
@@ -32,7 +32,7 @@ async fn health_check_endpoint_should_return_status_ok_when_there_is_no_services
3232
mod api {
3333
use std::sync::Arc;
3434

35-
use torrust_tracker_lib::servers::health_check_api::resources::{Report, Status};
35+
use torrust_axum_health_check_api_server::resources::{Report, Status};
3636
use torrust_tracker_test_helpers::configuration;
3737

3838
use crate::common::logging;
@@ -142,7 +142,7 @@ mod api {
142142
mod http {
143143
use std::sync::Arc;
144144

145-
use torrust_tracker_lib::servers::health_check_api::resources::{Report, Status};
145+
use torrust_axum_health_check_api_server::resources::{Report, Status};
146146
use torrust_tracker_test_helpers::configuration;
147147

148148
use crate::common::logging;
@@ -251,7 +251,7 @@ mod http {
251251
mod udp {
252252
use std::sync::Arc;
253253

254-
use torrust_tracker_lib::servers::health_check_api::resources::{Report, Status};
254+
use torrust_axum_health_check_api_server::resources::{Report, Status};
255255
use torrust_tracker_test_helpers::configuration;
256256

257257
use crate::common::logging;

tests/servers/health_check_api/environment.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ use std::sync::Arc;
33

44
use tokio::sync::oneshot::{self, Sender};
55
use tokio::task::JoinHandle;
6+
use torrust_axum_health_check_api_server::{server, HEALTH_CHECK_API_LOG_TARGET};
67
use torrust_server_lib::registar::Registar;
78
use torrust_server_lib::signals::{self, Halted, Started};
89
use torrust_tracker_configuration::HealthCheckApi;
9-
use torrust_tracker_lib::servers::health_check_api::{server, HEALTH_CHECK_API_LOG_TARGET};
1010

1111
#[derive(Debug)]
1212
pub enum Error {

0 commit comments

Comments
 (0)