forked from vectordotdev/vector
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(chronicle-sink): add support for compression to Google Chronicle…
… sink (vectordotdev#21272) * feat(chronicle): add support for compression to Google Chronicle sink * docs(chronicle-compression): add changelog documentation * feat(chronicle_compression): add configurable gzip compression level * docs(chronicle_compression): update documentation for CHronicle compression with configurable compression levels * docs(chronicle-compression): implement configurable schema generation for the compression level config * docs(chronicle_compression): write custom configuration implementation for Chronicle Compression * style(chronicle_compression): tidy up chronicle sink code * fix(chronicle_compression): fix compression configuration * refactor(chronicle-compression): remove some of the duplication ofthe chronicle compressiontype re * style(chronicle-compression): fix formatting error * Update changelog.d/chronicle_compression_support.enhancement.md --------- Co-authored-by: Matt Searle <matt.searle@10xbanking.com> Co-authored-by: Pavlos Rontidis <pavlos.rontidis@gmail.com>
- Loading branch information
1 parent
4d1f3fd
commit 17466c6
Showing
6 changed files
with
189 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Add Gzip compression support to the`gcp_chronicle_unstructured` sink. See official documentation [here](https://cloud.google.com/chronicle/docs/reference/ingestion-api#frequently_asked_questions). | ||
|
||
authors: chocpanda |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
use serde::{de, ser}; | ||
use serde_json::Value; | ||
use std::{cell::RefCell, collections::BTreeSet}; | ||
use vector_lib::configurable::ToValue; | ||
|
||
use indexmap::IndexMap; | ||
use vector_lib::configurable::attributes::CustomAttribute; | ||
use vector_lib::configurable::{ | ||
schema::{ | ||
apply_base_metadata, generate_one_of_schema, generate_struct_schema, | ||
get_or_generate_schema, SchemaGenerator, SchemaObject, | ||
}, | ||
Configurable, GenerateError, Metadata, | ||
}; | ||
|
||
use crate::sinks::util::buffer::compression::{ | ||
generate_string_schema, CompressionLevel, ALGORITHM_NAME, ENUM_TAGGING_MODE, LEVEL_NAME, | ||
}; | ||
use crate::sinks::util::Compression; | ||
|
||
/// Compression configuration. | ||
#[derive(Clone, Copy, Debug, Derivative, Eq, PartialEq)] | ||
#[derivative(Default)] | ||
pub enum ChronicleCompression { | ||
/// No compression. | ||
#[derivative(Default)] | ||
None, | ||
|
||
/// [Gzip][gzip] compression. | ||
/// | ||
/// [gzip]: https://www.gzip.org/ | ||
Gzip(CompressionLevel), | ||
} | ||
|
||
impl From<ChronicleCompression> for Compression { | ||
fn from(compression: ChronicleCompression) -> Self { | ||
match compression { | ||
ChronicleCompression::None => Compression::None, | ||
ChronicleCompression::Gzip(compression_level) => Compression::Gzip(compression_level), | ||
} | ||
} | ||
} | ||
|
||
impl TryFrom<Compression> for ChronicleCompression { | ||
type Error = String; | ||
|
||
fn try_from(compression: Compression) -> Result<Self, Self::Error> { | ||
match compression { | ||
Compression::None => Ok(ChronicleCompression::None), | ||
Compression::Gzip(compression_level) => { | ||
Ok(ChronicleCompression::Gzip(compression_level)) | ||
} | ||
_ => Err("Compression type is not supported by Chronicle".to_string()), | ||
} | ||
} | ||
} | ||
|
||
// Schema generation largely copied from `src/sinks/util/buffer/compression` | ||
impl Configurable for ChronicleCompression { | ||
fn metadata() -> Metadata { | ||
Compression::metadata() | ||
} | ||
|
||
fn generate_schema(gen: &RefCell<SchemaGenerator>) -> Result<SchemaObject, GenerateError> { | ||
// First, we'll create the string-only subschemas for each algorithm, and wrap those up | ||
// within a one-of schema. | ||
let mut string_metadata = Metadata::with_description("Compression algorithm."); | ||
string_metadata.add_custom_attribute(CustomAttribute::kv(ENUM_TAGGING_MODE, "external")); | ||
|
||
let none_string_subschema = generate_string_schema("None", None, "No compression."); | ||
let gzip_string_subschema = generate_string_schema( | ||
"Gzip", | ||
Some("[Gzip][gzip] compression."), | ||
"[gzip]: https://www.gzip.org/", | ||
); | ||
|
||
let mut all_string_oneof_subschema = | ||
generate_one_of_schema(&[none_string_subschema, gzip_string_subschema]); | ||
apply_base_metadata(&mut all_string_oneof_subschema, string_metadata); | ||
|
||
let compression_level_schema = | ||
get_or_generate_schema(&CompressionLevel::as_configurable_ref(), gen, None)?; | ||
|
||
let mut required = BTreeSet::new(); | ||
required.insert(ALGORITHM_NAME.to_string()); | ||
|
||
let mut properties = IndexMap::new(); | ||
properties.insert( | ||
ALGORITHM_NAME.to_string(), | ||
all_string_oneof_subschema.clone(), | ||
); | ||
properties.insert(LEVEL_NAME.to_string(), compression_level_schema); | ||
|
||
let mut full_subschema = generate_struct_schema(properties, required, None); | ||
let mut full_metadata = | ||
Metadata::with_description("Compression algorithm and compression level."); | ||
full_metadata.add_custom_attribute(CustomAttribute::flag("docs::hidden")); | ||
apply_base_metadata(&mut full_subschema, full_metadata); | ||
|
||
Ok(generate_one_of_schema(&[ | ||
all_string_oneof_subschema, | ||
full_subschema, | ||
])) | ||
} | ||
} | ||
|
||
impl ToValue for ChronicleCompression { | ||
fn to_value(&self) -> Value { | ||
serde_json::to_value(Compression::from(*self)) | ||
.expect("Could not convert compression settings to JSON") | ||
} | ||
} | ||
|
||
impl<'de> de::Deserialize<'de> for ChronicleCompression { | ||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> | ||
where | ||
D: de::Deserializer<'de>, | ||
{ | ||
Compression::deserialize(deserializer) | ||
.and_then(|x| ChronicleCompression::try_from(x).map_err(de::Error::custom)) | ||
} | ||
} | ||
|
||
impl ser::Serialize for ChronicleCompression { | ||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | ||
where | ||
S: ser::Serializer, | ||
{ | ||
Compression::serialize(&Compression::from(*self), serializer) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
#[cfg(feature = "sinks-gcp-chronicle")] | ||
pub mod chronicle_unstructured; | ||
pub mod compression; | ||
pub mod partitioner; | ||
pub mod sink; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters