Skip to content

enhancement(datadog_logs sink): default to zstd compression #19456

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
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ opendal = { version = "0.53", default-features = false, features = ["services-we

# Tower
tower = { version = "0.5.2", default-features = false, features = ["buffer", "limit", "retry", "timeout", "util", "balance", "discover"] }
tower-http = { version = "0.4.4", default-features = false, features = ["compression-full", "decompression-gzip", "trace"] }
tower-http = { version = "0.4.4", default-features = false, features = ["compression-full", "decompression-full", "trace"] }
# Serde
serde.workspace = true
serde-toml-merge = { version = "0.3.9", default-features = false }
Expand Down
5 changes: 5 additions & 0 deletions changelog.d/datadog-logs-zstd.enhancement.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
The Datadog Logs sink now defaults to zstd compression instead of gzip. This results in less
resource and higher throughput. You can explicitly set the compression to `gzip` to restore the
previous behavior.

authors: jszwedko
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ sinks:
inputs: [ "parse_message" ]
endpoint: "http://localhost:8080"
default_api_key: "DEADBEEF"
compression: "gzip"
healthcheck:
enabled: false
buffer:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ sinks:
inputs: [ "parse_message" ]
endpoint: "http://localhost:8080"
default_api_key: "DEADBEEF"
compression: "gzip"
healthcheck:
enabled: false
buffer:
Expand Down
23 changes: 18 additions & 5 deletions src/components/validation/resources/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ use std::{
};

use axum::{
error_handling::HandleErrorLayer,
response::IntoResponse,
routing::{MethodFilter, MethodRouter},
Router,
BoxError, Router,
};
use bytes::{BufMut as _, BytesMut};
use http::{Method, Request, StatusCode, Uri};
Expand All @@ -19,6 +20,8 @@ use tokio::{
sync::{mpsc, oneshot, Mutex, Notify},
};
use tokio_util::codec::Decoder;
use tower::ServiceBuilder;
use tower_http::decompression::RequestDecompressionLayer;

use crate::components::validation::{
sync::{Configuring, TaskCoordinator},
Expand Down Expand Up @@ -485,12 +488,22 @@ where
}
});

let router = Router::new().route(&request_path, method_router).fallback(
|req: Request<Body>| async move {
let router = Router::new()
.layer(
ServiceBuilder::new()
.layer(HandleErrorLayer::new(|error: BoxError| async move {
(
StatusCode::INTERNAL_SERVER_ERROR,
format!("Unhandled server error: {}", error),
)
}))
.layer(RequestDecompressionLayer::new()),
)
.route(&request_path, method_router)
.fallback(|req: Request<Body>| async move {
error!(?req, "Component sent request the server could not route.");
StatusCode::NOT_FOUND
},
);
});

// Now actually run/drive the HTTP server and process requests until we're told to shutdown.
http_server_started.mark_as_done();
Expand Down
10 changes: 8 additions & 2 deletions src/sinks/datadog/logs/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,16 @@ impl SinkBatchSettings for DatadogLogsDefaultBatchSettings {

/// Configuration for the `datadog_logs` sink.
#[configurable_component(sink("datadog_logs", "Publish log events to Datadog."))]
#[derive(Clone, Debug, Default)]
#[derive(Clone, Debug, Derivative)]
#[derivative(Default)]
#[serde(deny_unknown_fields)]
pub struct DatadogLogsConfig {
#[serde(flatten)]
pub local_dd_common: LocalDatadogCommonConfig,

#[configurable(derived)]
#[serde(default)]
#[derivative(Default(value = "default_compression()"))]
#[serde(default = "default_compression")]
pub compression: Option<Compression>,

#[configurable(derived)]
Expand All @@ -75,6 +77,10 @@ pub struct DatadogLogsConfig {
pub conforms_as_agent: bool,
}

const fn default_compression() -> Option<Compression> {
Some(Compression::zstd_default())
}

impl GenerateConfig for DatadogLogsConfig {
fn generate_config() -> toml::Value {
toml::from_str(indoc! {r#"
Expand Down
39 changes: 21 additions & 18 deletions website/cue/reference/components/sinks/base/datadog_logs.cue
Original file line number Diff line number Diff line change
Expand Up @@ -69,28 +69,31 @@ base: components: sinks: datadog_logs: configuration: {
All compression algorithms use the default compression level unless otherwise specified.
"""
required: false
type: string: enum: {
gzip: """
[Gzip][gzip] compression.
type: string: {
default: "zstd"
enum: {
gzip: """
[Gzip][gzip] compression.

[gzip]: https://www.gzip.org/
"""
none: "No compression."
snappy: """
[Snappy][snappy] compression.
[gzip]: https://www.gzip.org/
"""
none: "No compression."
snappy: """
[Snappy][snappy] compression.

[snappy]: https://github.com/google/snappy/blob/main/docs/README.md
"""
zlib: """
[Zlib][zlib] compression.
[snappy]: https://github.com/google/snappy/blob/main/docs/README.md
"""
zlib: """
[Zlib][zlib] compression.

[zlib]: https://zlib.net/
"""
zstd: """
[Zstandard][zstd] compression.
[zlib]: https://zlib.net/
"""
zstd: """
[Zstandard][zstd] compression.

[zstd]: https://facebook.github.io/zstd/
"""
[zstd]: https://facebook.github.io/zstd/
"""
}
}
}
conforms_as_agent: {
Expand Down
Loading