-
Notifications
You must be signed in to change notification settings - Fork 2.1k
feat(vector sink): Add zstd compression support #24917
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
Open
jpds
wants to merge
6
commits into
vectordotdev:master
Choose a base branch
from
jpds:feat-vector-sink-zstd-compression
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+312
−33
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
76ba138
chore(deps): enable tonic zstd feature
jpds 07f5825
feat(vector sink): add zstd compression support
jpds 045a5f6
feat(vector source): accept zstd compressed requests
jpds b5fa87a
docs: add changelog entry for vector sink zstd compression
jpds bb9b198
fix(vector source): support zstd decompression in gRPC layer
jpds b31f8f8
docs: add deprecation entry for vector sink boolean compression syntax
jpds File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
33 changes: 33 additions & 0 deletions
33
changelog.d/23030_vector_sink_zstd_compression.enhancement.md
This file contains hidden or 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,33 @@ | ||
| The `vector` sink now supports `zstd` compression in addition to `gzip`. This provides better | ||
| compression ratios and performance for Vector-to-Vector communication. | ||
|
|
||
| The compression configuration has been enhanced to support multiple algorithms while maintaining | ||
| full backward compatibility: | ||
|
|
||
| ## Legacy boolean syntax (still supported) | ||
|
|
||
| ```yaml | ||
| sinks: | ||
| my_vector: | ||
| type: vector | ||
| address: "localhost:6000" | ||
| compression: true # Uses gzip (default) | ||
| # or | ||
| compression: false # No compression | ||
| ``` | ||
|
|
||
| ## New string syntax | ||
|
|
||
| ```yaml | ||
| sinks: | ||
| my_vector: | ||
| type: vector | ||
| address: "localhost:6000" | ||
| compression: "zstd" # Use zstd compression | ||
| # Supported values: "none", "gzip", "zstd" | ||
| ``` | ||
|
|
||
| The Vector source automatically accepts both gzip and zstd compressed data, enabling seamless | ||
| communication between Vector instances using different compression algorithms. | ||
|
|
||
| authors: jpds | ||
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -128,3 +128,4 @@ impl<T> From<Vec<T>> for OneOrMany<T> { | |
| Self::Many(value) | ||
| } | ||
| } | ||
|
|
||
This file contains hidden or 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,144 @@ | ||
| use serde::{Deserialize, Deserializer, de}; | ||
| use vector_lib::configurable::configurable_component; | ||
|
|
||
| /// Compression configuration for the Vector sink. | ||
| /// | ||
| /// Only `gzip` and `zstd` are supported as compression algorithms for the | ||
| /// Vector sink's gRPC transport. Compression levels are not configurable | ||
| /// as the underlying tonic library does not support them. | ||
| #[configurable_component] | ||
| #[derive(Clone, Copy, Debug, Default, Eq, PartialEq)] | ||
| #[serde(rename_all = "snake_case")] | ||
| #[configurable(metadata( | ||
| docs::enum_tag_description = "The compression algorithm to use for sending." | ||
| ))] | ||
| pub enum VectorCompression { | ||
| /// No compression. | ||
| #[default] | ||
| None, | ||
|
|
||
| /// [Gzip][gzip] compression. | ||
| /// | ||
| /// [gzip]: https://www.gzip.org/ | ||
| Gzip, | ||
|
|
||
| /// [Zstandard][zstd] compression. | ||
| /// | ||
| /// [zstd]: https://facebook.github.io/zstd/ | ||
| Zstd, | ||
| } | ||
|
|
||
| impl VectorCompression { | ||
| /// Returns the corresponding `tonic::codec::CompressionEncoding`, if any. | ||
| pub const fn as_tonic_encoding(self) -> Option<tonic::codec::CompressionEncoding> { | ||
| match self { | ||
| VectorCompression::None => Option::None, | ||
| VectorCompression::Gzip => Some(tonic::codec::CompressionEncoding::Gzip), | ||
| VectorCompression::Zstd => Some(tonic::codec::CompressionEncoding::Zstd), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Enables deserializing compression from a bool (legacy) or string (new). | ||
| /// | ||
| /// For backward compatibility: | ||
| /// - `true` maps to `VectorCompression::Gzip` | ||
| /// - `false` maps to `VectorCompression::None` | ||
| /// | ||
| /// New syntax: | ||
| /// - `"none"`, `"gzip"`, `"zstd"` as strings | ||
| pub fn bool_or_vector_compression<'de, D>(deserializer: D) -> Result<VectorCompression, D::Error> | ||
| where | ||
| D: Deserializer<'de>, | ||
| { | ||
| struct BoolOrVectorCompression; | ||
|
|
||
| impl<'de> de::Visitor<'de> for BoolOrVectorCompression { | ||
| type Value = VectorCompression; | ||
|
|
||
| fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { | ||
| formatter | ||
| .write_str("boolean (deprecated) or string (\"none\", \"gzip\", or \"zstd\")") | ||
| } | ||
|
|
||
| fn visit_bool<E>(self, value: bool) -> Result<VectorCompression, E> | ||
| where | ||
| E: de::Error, | ||
| { | ||
| if value { | ||
| Ok(VectorCompression::Gzip) | ||
| } else { | ||
| Ok(VectorCompression::None) | ||
| } | ||
| } | ||
|
|
||
| fn visit_str<E>(self, value: &str) -> Result<VectorCompression, E> | ||
| where | ||
| E: de::Error, | ||
| { | ||
| VectorCompression::deserialize(de::value::StrDeserializer::new(value)) | ||
| } | ||
| } | ||
|
|
||
| deserializer.deserialize_any(BoolOrVectorCompression) | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| #[derive(Deserialize)] | ||
| struct TestConfig { | ||
| #[serde(deserialize_with = "bool_or_vector_compression")] | ||
| compression: VectorCompression, | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_legacy_true() { | ||
| let json = r#"{"compression": true}"#; | ||
| let result: TestConfig = serde_json::from_str(json).unwrap(); | ||
| assert_eq!(result.compression, VectorCompression::Gzip); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_legacy_false() { | ||
| let json = r#"{"compression": false}"#; | ||
| let result: TestConfig = serde_json::from_str(json).unwrap(); | ||
| assert_eq!(result.compression, VectorCompression::None); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_string_gzip() { | ||
| let json = r#"{"compression": "gzip"}"#; | ||
| let result: TestConfig = serde_json::from_str(json).unwrap(); | ||
| assert_eq!(result.compression, VectorCompression::Gzip); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_string_zstd() { | ||
| let json = r#"{"compression": "zstd"}"#; | ||
| let result: TestConfig = serde_json::from_str(json).unwrap(); | ||
| assert_eq!(result.compression, VectorCompression::Zstd); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_string_none() { | ||
| let json = r#"{"compression": "none"}"#; | ||
| let result: TestConfig = serde_json::from_str(json).unwrap(); | ||
| assert_eq!(result.compression, VectorCompression::None); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_unsupported_algorithm_rejected() { | ||
| let json = r#"{"compression": "snappy"}"#; | ||
| let result = serde_json::from_str::<TestConfig>(json); | ||
| assert!(result.is_err()); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_object_syntax_rejected() { | ||
| let json = r#"{"compression": {"algorithm": "zstd", "level": 3}}"#; | ||
| let result = serde_json::from_str::<TestConfig>(json); | ||
| assert!(result.is_err()); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.