Skip to content

Commit da87aa3

Browse files
authored
feat: svix bridge-health-endpoint (#1903)
## Motivation There is no health enpoint in svix bridge so this PR adds a health endpoint to svix bridge ## Solution Work in progress
1 parent 0ea3f2b commit da87aa3

File tree

1 file changed

+22
-1
lines changed
  • bridge/svix-bridge/src/webhook_receiver

1 file changed

+22
-1
lines changed

bridge/svix-bridge/src/webhook_receiver/mod.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::{net::SocketAddr, sync::Arc, time::Duration};
33
use axum::{
44
extract::{Path, State},
55
http,
6-
routing::post,
6+
routing::{get, post},
77
Router,
88
};
99
use svix_bridge_types::{
@@ -37,13 +37,34 @@ fn router() -> Router<InternalState> {
3737
"/webhook/:integration_id/",
3838
post(route).put(route).get(route).patch(route),
3939
)
40+
.route("/health", get(health_handler))
4041
}
42+
static START_TIME: once_cell::sync::Lazy<std::time::Instant> =
43+
once_cell::sync::Lazy::new(std::time::Instant::now);
4144

45+
fn get_uptime_seconds() -> u64 {
46+
START_TIME.elapsed().as_secs()
47+
}
48+
#[derive(serde::Serialize)]
49+
struct HealthResponse {
50+
pub status: &'static str,
51+
pub version: &'static str,
52+
pub uptime: u64,
53+
}
54+
async fn health_handler() -> impl axum::response::IntoResponse {
55+
let health_response = HealthResponse {
56+
status: "OK",
57+
version: env!("CARGO_PKG_VERSION"),
58+
uptime: get_uptime_seconds(),
59+
};
60+
axum::Json(health_response)
61+
}
4262
pub async fn run(
4363
listen_addr: SocketAddr,
4464
routes: Vec<WebhookReceiverConfig>,
4565
transformer_tx: TransformerTx,
4666
) -> std::io::Result<()> {
67+
once_cell::sync::Lazy::force(&START_TIME);
4768
let state = InternalState::from_receiver_configs(routes, transformer_tx)
4869
.await
4970
.map_err(std::io::Error::other)?;

0 commit comments

Comments
 (0)