Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

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

10 changes: 10 additions & 0 deletions devservices/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ services:
- synapse-proxy-cache:/tmp/synapse-cache
networks:
- devservices
healthcheck:
test: ["CMD", "/app/synapse", "healthcheck", "--config-file-path", "/app/proxy.yaml"]
interval: 5s
timeout: 5s
retries: 3
restart: unless-stopped

synapse-ingest-router:
Expand All @@ -37,6 +42,11 @@ services:
- synapse-ingest-router-cache:/tmp/synapse-cache
networks:
- devservices
healthcheck:
test: ["CMD", "/app/synapse", "healthcheck", "--config-file-path", "/app/ingest-router.yaml"]
interval: 5s
timeout: 5s
retries: 3
restart: unless-stopped

volumes:
Expand Down
1 change: 1 addition & 0 deletions synapse/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ locator = { path = "../locator" }
metrics = { workspace = true }
metrics-exporter-statsd = { workspace = true }
proxy = { path = "../proxy" }
reqwest = { workspace = true, features = ["blocking"] }
sentry = { workspace = true }
serde = { workspace = true }
shared = { path = "../shared" }
Expand Down
24 changes: 24 additions & 0 deletions synapse/src/healthcheck.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use crate::CliError;
use crate::config::Config;
use std::path::Path;

pub fn run(config_path: &Path) -> Result<(), CliError> {
let config = Config::from_file(config_path)?;
let port = config
.proxy
.as_ref()
.map(|c| c.admin_listener.port)
.or_else(|| config.ingest_router.as_ref().map(|c| c.admin_listener.port))
.ok_or(CliError::InvalidConfig(
"Missing proxy or ingest-router config",
))?;
let response = reqwest::blocking::get(format!("http://localhost:{port}/ready"))
.map_err(|e| CliError::HealthcheckFailed(e.to_string()))?;
if !response.status().is_success() {
return Err(CliError::HealthcheckFailed(format!(
"status {}",
response.status()
)));
}
Ok(())
}
12 changes: 12 additions & 0 deletions synapse/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use clap::{Args, Parser};
use std::path::PathBuf;

mod config;
mod healthcheck;
use config::{Config, MetricsConfig};
use metrics_exporter_statsd::StatsdBuilder;
use std::future::Future;
Expand All @@ -14,6 +15,8 @@ enum CliCommand {
Locator(LocatorArgs),
Proxy(ProxyArgs),
IngestRouter(IngestRouterArgs),
/// Probe a URL and exit 0 on a 2xx response, non-zero otherwise.
Healthcheck(HealthcheckArgs),
/// Show all metrics definitions as markdown table
ShowMetrics,
/// Sync METRICS.md with current metric definitions
Expand All @@ -28,6 +31,8 @@ enum CliError {
InvalidConfig(&'static str),
#[error("Failed to create runtime: {0}")]
RuntimeError(#[from] std::io::Error),
#[error("Healthcheck failed: {0}")]
HealthcheckFailed(String),
}

fn main() {
Expand Down Expand Up @@ -81,6 +86,7 @@ fn cli() -> Result<(), CliError> {

Ok(())
}
CliCommand::Healthcheck(args) => healthcheck::run(&args.base.config_file_path),
CliCommand::ShowMetrics => {
println!("## Locator Metrics\n");
println!(
Expand Down Expand Up @@ -242,6 +248,12 @@ struct IngestRouterArgs {
base: BaseArgs,
}

#[derive(Args, Debug)]
struct HealthcheckArgs {
#[command(flatten)]
base: BaseArgs,
}

#[cfg(test)]
mod tests {
#[test]
Expand Down
Loading