-
Notifications
You must be signed in to change notification settings - Fork 281
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(gateway): add HTTP health check (#4120)
This adds the same kind of HTTP health-check that is already present in the relay to the gateway. The health-check returns 200 OK for as long as the gateway is active. The gateway automatically shuts down on fatal errors (like authentication failures with the portal). To enable this, I've extracted a crate `http-health-check` that shares this code between the relay and the gateway. Resolves: #2465. --------- Signed-off-by: Thomas Eizinger <thomas@eizinger.io> Co-authored-by: Reactor Scram <ReactorScram@users.noreply.github.com>
- Loading branch information
1 parent
4c77aae
commit 9767bdd
Showing
10 changed files
with
66 additions
and
25 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,12 @@ | ||
[package] | ||
name = "http-health-check" | ||
# mark:automatic-version | ||
version = "1.0.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
axum = { version = "0.7.3", default-features = false, features = ["http1", "tokio"] } | ||
tokio = { version = "1.36.0", features = ["net"] } | ||
clap = { version = "4.5.2", features = ["derive", "env"] } |
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,27 @@ | ||
use axum::routing::get; | ||
use axum::Router; | ||
use std::net::SocketAddr; | ||
|
||
/// Runs an HTTP server that always responds to `GET /healthz` with 200 OK. | ||
/// | ||
/// To signal an unhealthy state, simply stop the task. | ||
pub async fn serve(addr: impl Into<SocketAddr>) -> std::io::Result<()> { | ||
let addr = addr.into(); | ||
|
||
let service = Router::new() | ||
.route("/healthz", get(|| async { "" })) | ||
.into_make_service(); | ||
|
||
axum::serve(tokio::net::TcpListener::bind(addr).await?, service).await?; | ||
|
||
Ok(()) | ||
} | ||
|
||
#[derive(clap::Args, Debug, Clone)] | ||
pub struct HealthCheckArgs { | ||
/// The address of the local interface where we should serve our health-check endpoint. | ||
/// | ||
/// The actual health-check endpoint will be at `http://<health_check_addr>/healthz`. | ||
#[arg(long, env, hide = true, default_value = "0.0.0.0:8080")] | ||
pub health_check_addr: SocketAddr, | ||
} |
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 was deleted.
Oops, something went wrong.
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