diff --git a/crates/service/web/storyteller_web/src/http_server/endpoints/service/health_check_handler.rs b/crates/service/web/storyteller_web/src/http_server/endpoints/service/health_check_handler.rs index d2b769902f..c661797dfb 100644 --- a/crates/service/web/storyteller_web/src/http_server/endpoints/service/health_check_handler.rs +++ b/crates/service/web/storyteller_web/src/http_server/endpoints/service/health_check_handler.rs @@ -30,6 +30,7 @@ pub struct HealthCheckResponse { pub last_db_time: Option, pub healthy_check_consecutive_count: Option, pub unhealthy_check_consecutive_count: Option, + pub server_build_sha: String, } @@ -79,6 +80,7 @@ pub async fn get_health_check_handler( last_db_time: health_check_status.last_db_time, healthy_check_consecutive_count: health_check_status.healthy_check_consecutive_count, unhealthy_check_consecutive_count: health_check_status.unhealthy_check_consecutive_count, + server_build_sha: server_state.server_info.build_sha.clone(), }; let body = serde_json::to_string(&response) diff --git a/crates/service/web/storyteller_web/src/main.rs b/crates/service/web/storyteller_web/src/main.rs index 9a5769a17f..7bdc64445b 100644 --- a/crates/service/web/storyteller_web/src/main.rs +++ b/crates/service/web/storyteller_web/src/main.rs @@ -60,7 +60,7 @@ use crate::configs::static_api_tokens::{StaticApiTokenConfig, StaticApiTokens, S use crate::http_server::middleware::ip_filter_middleware::IpFilter; use crate::http_server::web_utils::redis_rate_limiter::RedisRateLimiter; use crate::routes::add_routes; -use crate::server_state::{ServerState, EnvConfig, TwitchOauthSecrets, TwitchOauth, RedisRateLimiters, InMemoryCaches, StripeSettings}; +use crate::server_state::{ServerState, EnvConfig, TwitchOauthSecrets, TwitchOauth, RedisRateLimiters, InMemoryCaches, StripeSettings, ServerInfo}; use crate::threads::db_health_checker_thread::db_health_check_status::HealthCheckStatus; use crate::threads::db_health_checker_thread::db_health_checker_thread::db_health_checker_thread; use crate::threads::ip_banlist_set::IpBanlistSet; @@ -339,6 +339,12 @@ async fn main() -> AnyhowResult<()> { stripe::Client::new(api_secret) }; + // NB: Docker creates this file within container builds. + let build_sha = std::fs::read_to_string("/GIT_SHA") + .unwrap_or(String::from("unknown")) + .trim() + .to_string(); + let server_state = ServerState { env_config: EnvConfig { num_workers, @@ -348,6 +354,9 @@ async fn main() -> AnyhowResult<()> { cookie_http_only, website_homepage_redirect, }, + server_info: ServerInfo { + build_sha, + }, stripe: StripeSettings { config: stripe_configs, client: stripe_client, @@ -419,7 +428,6 @@ pub async fn serve(server_state: ServerState) -> AnyhowResult<()> HttpServer::new(move || { // NB: Safe to clone due to internal arc let ip_banlist = server_state_arc.ip_banlist.clone(); - let build_sha = std::fs::read_to_string("/GIT_SHA").unwrap_or(String::from("unknown")); // NB: Dynamic dispatch needs to be wrapped with Arc. let product_lookup : Arc = Arc::new(StripeInternalSubscriptionProductLookupImpl {}); @@ -446,7 +454,7 @@ pub async fn serve(server_state: ServerState) -> AnyhowResult<()> .wrap(build_cors_config(server_state_arc.server_environment.clone())) .wrap(DefaultHeaders::new() .header("X-Backend-Hostname", &hostname) - .header("X-Build-Sha", build_sha.trim())) + .header("X-Build-Sha", server_state_arc.server_info.build_sha.clone())) .wrap(IpFilter::new(ip_banlist)) .wrap(Logger::new(&log_format) .exclude("/liveness") diff --git a/crates/service/web/storyteller_web/src/server_state.rs b/crates/service/web/storyteller_web/src/server_state.rs index 00326273e6..62e12fca5c 100644 --- a/crates/service/web/storyteller_web/src/server_state.rs +++ b/crates/service/web/storyteller_web/src/server_state.rs @@ -25,6 +25,8 @@ pub struct ServerState { /// Configuration from ENV vars. pub env_config: EnvConfig, + pub server_info: ServerInfo, + pub stripe: StripeSettings, pub hostname: String, @@ -77,6 +79,11 @@ pub struct EnvConfig { pub website_homepage_redirect: String, } +#[derive(Clone)] +pub struct ServerInfo { + pub build_sha: String, +} + /// Necessary to run the OAuth flow. #[derive(Clone)] pub struct TwitchOauth {