Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] enhancement(sinks clickhouse): support native protocol #14787

Closed
Closed
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
6b90b1b
tmp
caibirdme Sep 29, 2022
5c137ae
Merge branch 'vectordotdev:master' into feature-native-ch-proto
caibirdme Sep 29, 2022
642583a
tmp
caibirdme Sep 30, 2022
8d2097a
Merge branch 'feature-native-ch-proto' of github.com:caibirdme/vector…
caibirdme Sep 30, 2022
5c4aa7a
v0.0.1
caibirdme Oct 9, 2022
e7688c6
Merge branch 'master' of github.com:vectordotdev/vector into feature-…
caibirdme Oct 9, 2022
61b2921
add ut for parser
caibirdme Oct 10, 2022
cba2337
Merge branch 'master' of https://github.com/vectordotdev/vector into …
caibirdme Oct 11, 2022
7643bdb
Merge branch 'master' of https://github.com/vectordotdev/vector into …
caibirdme Oct 12, 2022
46cb796
add into_map
caibirdme Oct 12, 2022
0576bb8
resolve conflict
caibirdme Oct 25, 2022
5c5b9de
fix code style
caibirdme Oct 25, 2022
d8d85b9
fix style
caibirdme Oct 25, 2022
89b0cac
fix type
caibirdme Oct 26, 2022
c451d73
Merge branch 'master' of github.com:vectordotdev/vector into feature-…
caibirdme Oct 26, 2022
f8e8ce5
fix clippy style issues
caibirdme Oct 26, 2022
69f1db0
fix style issue
caibirdme Oct 26, 2022
9535fa3
Merge branch 'master' of github.com:vectordotdev/vector into feature-…
caibirdme Oct 26, 2022
7c5691a
remove unimplemented
caibirdme Oct 28, 2022
06fcd55
Merge branch 'master' of https://github.com/vectordotdev/vector into …
caibirdme Oct 28, 2022
47319e3
ut check consume all str&add genrate_config test
caibirdme Oct 29, 2022
de1ee75
Merge branch 'master' of https://github.com/vectordotdev/vector into …
caibirdme Oct 29, 2022
9b9a1be
update clickhouse cue
caibirdme Oct 29, 2022
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
51 changes: 42 additions & 9 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ bytes = { version = "1.2.1", default-features = false, features = ["serde"] }
bytesize = { version = "1.1.0", default-features = false }
chrono = { version = "0.4.22", default-features = false, features = ["serde"] }
chrono-tz = { version = "0.6", default-features = false, features = ["serde"], optional = true }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to avoid chrono-tz version 0.7 that we are using elsewhere?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is due to the issue in clickhouse-rs: suharev7/clickhouse-rs#158

I suggest for now leaving it as is before fixing it in the upstream. Then, we will be able to (hopefully easily) update the chrono-tz library. According to the linked issue, I do not know, how easily fix the current code to work with the latest chrono-tz (and I support clickhouse-rs does not work with it well anyway).

cidr-utils = { version = "0.5.7", default-features = false }
clap = { version = "4.0.12", default-features = false, features = ["derive", "error-context", "env", "help", "std", "string", "usage", "wrap_help"] }
cidr-utils = { version = "0.5.8", default-features = false }
clap = { version = "4.0.18", default-features = false, features = ["derive", "error-context", "env", "help", "std", "string", "usage", "wrap_help"] }
clickhouse-rs = { git = "https://github.com/suharev7/clickhouse-rs", rev="e40016b", features = ["tokio_io", "tls"], optional = true }
colored = { version = "2.0.0", default-features = false }
csv = { version = "1.1", default-features = false }
Expand Down
30 changes: 18 additions & 12 deletions src/sinks/clickhouse/config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::collections::BTreeMap;
use vector_config::configurable_component;
use crate::{
codecs::Transformer,
config::{AcknowledgementsConfig, Input, SinkConfig, SinkContext},
Expand All @@ -13,11 +11,10 @@ use crate::{
},
tls::TlsConfig,
};
use std::collections::BTreeMap;
use vector_config::configurable_component;

use super::{
http_sink::build_http_sink,
native_sink::build_native_sink,
};
use super::{http_sink::build_http_sink, native::build_native_sink};

/// Configuration for the `clickhouse` sink.
#[configurable_component(sink("clickhouse"))]
Expand All @@ -33,16 +30,16 @@ pub struct ClickhouseConfig {

/// The database that contains the table that data will be inserted into.
pub database: Option<String>,
/// Enable using clickhouse native protocol rather than the default jsoneachrow over http.
/// If true`, ClickHouse Native Protocol is used. Defaults to `false`, using `JSONEachRow` over HTTP.
#[serde(default)]
pub use_native_proto: bool,

/// Sets `input_format_skip_unknown_fields`, allowing Clickhouse to discard fields not present in the table schema.
#[serde(default)]
pub skip_unknown_fields: bool,
/// table column names like {"col1":"String", "col_2":"Nullable(UInt16)", ...}
/// SQL table column definition. For example: {"col1":"String", "col_2":"Nullable(UInt16)", ...}
#[serde(default)]
pub table_def: BTreeMap<String, String>,
pub sql_table_col_def: BTreeMap<String, String>,

#[configurable(derived)]
#[serde(default = "Compression::gzip_default")]
Expand Down Expand Up @@ -83,8 +80,7 @@ impl_generate_config_from_default!(ClickhouseConfig);
#[async_trait::async_trait]
impl SinkConfig for ClickhouseConfig {
async fn build(&self, cx: SinkContext) -> crate::Result<(VectorSink, Healthcheck)> {
// later we can build different sink(http, native) here
// according to the clickhouseConfig
// Determine the sink to build from the config.
if !self.use_native_proto {
build_http_sink(self, cx).await
} else {
Expand All @@ -99,4 +95,14 @@ impl SinkConfig for ClickhouseConfig {
fn acknowledgements(&self) -> &AcknowledgementsConfig {
&self.acknowledgements
}
}
}

#[cfg(test)]
mod tests {
use super::ClickhouseConfig;

#[test]
fn generate_config() {
crate::test_util::test_generate_config::<ClickhouseConfig>();
}
}
Loading