From 7a7b53b1c6958f346648042de84d53f6c7357064 Mon Sep 17 00:00:00 2001 From: Doug Smith Date: Mon, 6 Nov 2023 16:13:35 -0500 Subject: [PATCH] fix(clickhouse sink): fix healthcheck uri (#19067) fix(clickhouse sink): fix healhcheck uri --- src/sinks/clickhouse/config.rs | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/sinks/clickhouse/config.rs b/src/sinks/clickhouse/config.rs index a6fad6a11cdc3..0c8cc164633f8 100644 --- a/src/sinks/clickhouse/config.rs +++ b/src/sinks/clickhouse/config.rs @@ -130,8 +130,17 @@ impl SinkConfig for ClickhouseConfig { } } +fn get_healthcheck_uri(endpoint: &Uri) -> String { + let mut uri = endpoint.to_string(); + if !uri.ends_with('/') { + uri.push('/'); + } + uri.push_str("?query=SELECT%201"); + uri +} + async fn healthcheck(client: HttpClient, endpoint: Uri, auth: Option) -> crate::Result<()> { - let uri = format!("{}/?query=SELECT%201", endpoint); + let uri = get_healthcheck_uri(&endpoint); let mut request = Request::get(uri).body(Body::empty()).unwrap(); if let Some(auth) = auth { @@ -154,4 +163,20 @@ mod tests { fn generate_config() { crate::test_util::test_generate_config::(); } + + #[test] + fn test_get_healthcheck_uri() { + assert_eq!( + get_healthcheck_uri(&"http://localhost:8123".parse().unwrap()), + "http://localhost:8123/?query=SELECT%201" + ); + assert_eq!( + get_healthcheck_uri(&"http://localhost:8123/".parse().unwrap()), + "http://localhost:8123/?query=SELECT%201" + ); + assert_eq!( + get_healthcheck_uri(&"http://localhost:8123/path/".parse().unwrap()), + "http://localhost:8123/path/?query=SELECT%201" + ); + } }