Skip to content

Commit 77ac63c

Browse files
authored
chore(clickhouse sink): refactor to new style (#17723)
Closes: #17094 Updates the clickhouse docker image to support aarch64.
1 parent 47c3da1 commit 77ac63c

File tree

9 files changed

+474
-299
lines changed

9 files changed

+474
-299
lines changed

scripts/integration/clickhouse/compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ version: '3'
22

33
services:
44
clickhouse:
5-
image: docker.io/yandex/clickhouse-server:${CONFIG_VERSION}
5+
image: docker.io/clickhouse/clickhouse-server:${CONFIG_VERSION}

scripts/integration/clickhouse/test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ env:
77
CLICKHOUSE_ADDRESS: http://clickhouse:8123
88

99
matrix:
10-
version: ['19']
10+
version: ['23']
1111

1212
# changes to these files/paths will invoke the integration test in CI
1313
# expressions are evaluated using https://github.com/micromatch/picomatch

src/sinks/clickhouse/config.rs

Lines changed: 71 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
1-
use vector_config::configurable_component;
1+
use http::{Request, StatusCode, Uri};
2+
use hyper::Body;
23

4+
use super::{
5+
service::{ClickhouseRetryLogic, ClickhouseService},
6+
sink::ClickhouseSink,
7+
};
38
use crate::{
4-
codecs::Transformer,
5-
config::{AcknowledgementsConfig, Input, SinkConfig, SinkContext},
6-
http::Auth,
9+
http::{get_http_scheme_from_uri, Auth, HttpClient, MaybeAuth},
710
sinks::{
8-
util::{
9-
BatchConfig, Compression, RealtimeSizeBasedDefaultBatchSettings, TowerRequestConfig,
10-
UriSerde,
11-
},
12-
Healthcheck, VectorSink,
11+
prelude::*,
12+
util::{RealtimeSizeBasedDefaultBatchSettings, UriSerde},
1313
},
14-
tls::TlsConfig,
1514
};
1615

17-
use super::http_sink::build_http_sink;
18-
1916
/// Configuration for the `clickhouse` sink.
2017
#[configurable_component(sink("clickhouse", "Deliver log data to a ClickHouse database."))]
2118
#[derive(Clone, Debug, Default)]
@@ -82,9 +79,41 @@ impl_generate_config_from_default!(ClickhouseConfig);
8279
#[typetag::serde(name = "clickhouse")]
8380
impl SinkConfig for ClickhouseConfig {
8481
async fn build(&self, cx: SinkContext) -> crate::Result<(VectorSink, Healthcheck)> {
85-
// later we can build different sink(http, native) here
86-
// according to the clickhouseConfig
87-
build_http_sink(self, cx).await
82+
let endpoint = self.endpoint.with_default_parts().uri;
83+
let protocol = get_http_scheme_from_uri(&endpoint);
84+
85+
let auth = self.auth.choose_one(&self.endpoint.auth)?;
86+
87+
let tls_settings = TlsSettings::from_options(&self.tls)?;
88+
let client = HttpClient::new(tls_settings, &cx.proxy)?;
89+
90+
let service = ClickhouseService::new(
91+
client.clone(),
92+
auth.clone(),
93+
&endpoint,
94+
self.database.as_deref(),
95+
self.table.as_str(),
96+
self.skip_unknown_fields,
97+
self.date_time_best_effort,
98+
)?;
99+
100+
let request_limits = self.request.unwrap_with(&Default::default());
101+
let service = ServiceBuilder::new()
102+
.settings(request_limits, ClickhouseRetryLogic::default())
103+
.service(service);
104+
105+
let batch_settings = self.batch.into_batcher_settings()?;
106+
let sink = ClickhouseSink::new(
107+
batch_settings,
108+
self.compression,
109+
self.encoding.clone(),
110+
service,
111+
protocol,
112+
);
113+
114+
let healthcheck = Box::pin(healthcheck(client, endpoint, auth));
115+
116+
Ok((VectorSink::from_event_streamsink(sink), healthcheck))
88117
}
89118

90119
fn input(&self) -> Input {
@@ -95,3 +124,30 @@ impl SinkConfig for ClickhouseConfig {
95124
&self.acknowledgements
96125
}
97126
}
127+
128+
async fn healthcheck(client: HttpClient, endpoint: Uri, auth: Option<Auth>) -> crate::Result<()> {
129+
// TODO: check if table exists?
130+
let uri = format!("{}/?query=SELECT%201", endpoint);
131+
let mut request = Request::get(uri).body(Body::empty()).unwrap();
132+
133+
if let Some(auth) = auth {
134+
auth.apply(&mut request);
135+
}
136+
137+
let response = client.send(request).await?;
138+
139+
match response.status() {
140+
StatusCode::OK => Ok(()),
141+
status => Err(HealthcheckError::UnexpectedStatus { status }.into()),
142+
}
143+
}
144+
145+
#[cfg(test)]
146+
mod tests {
147+
use super::*;
148+
149+
#[test]
150+
fn generate_config() {
151+
crate::test_util::test_generate_config::<ClickhouseConfig>();
152+
}
153+
}

src/sinks/clickhouse/http_sink.rs

Lines changed: 0 additions & 250 deletions
This file was deleted.

0 commit comments

Comments
 (0)