Skip to content

Commit 6413191

Browse files
committed
chore(config): clamp zstd compressor level to ADP minimum
The core Agent streams a fully-resolved config, so its schema default of 1 for serializer_zstd_compressor_level arrives as a concrete value that would otherwise overwrite ADP's intended level-3 floor. Add a ZSTD_MINIMUM const in the config layer and clamp the translated value up to it, preserving ADP's harder-compression behavior instead of silently regressing to the Agent default.
1 parent f41a555 commit 6413191

2 files changed

Lines changed: 40 additions & 2 deletions

File tree

lib/agent-data-plane-config-system/src/translators/datadog_translator.rs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use agent_data_plane_config::control::ListenAddress;
2222
use agent_data_plane_config::domains::dogstatsd::{
2323
FilterAction, MapperProfile, MetricMapping, MetricTagFilterEntry, OriginTagCardinality,
2424
};
25-
use agent_data_plane_config::shared::ForwarderHttpProtocol;
25+
use agent_data_plane_config::shared::{ForwarderHttpProtocol, ZSTD_MINIMUM};
2626
use agent_data_plane_config::SalukiConfiguration;
2727
use bytesize::ByteSize;
2828
use datadog_agent_config::{drive, DatadogConfigWitness, DatadogConfiguration, TranslateError, TranslateErrors};
@@ -952,7 +952,13 @@ impl DatadogConfigWitness for DatadogTranslator<'_> {
952952
}
953953

954954
fn consume_serializer_zstd_compressor_level(&mut self, value: i64) {
955-
self.config.shared.endpoints.compression.zstd_compressor_level = value as i32;
955+
// TODO: The core Agent streams a fully-resolved config, so its schema default of `1` for
956+
// `serializer_zstd_compressor_level` arrives here as a concrete value. Without this clamp it
957+
// would silently override ADP's intended `ZSTD_MINIMUM` floor. Clamping up cannot tell an
958+
// operator who deliberately set `1` apart from the Agent's default `1`, so both are raised to
959+
// the floor. Follow-up work needs to track each value's source (user-set vs Agent default) so
960+
// we can honor an explicit low level while still applying our floor to the Agent default.
961+
self.config.shared.endpoints.compression.zstd_compressor_level = (value as i32).max(ZSTD_MINIMUM);
956962
}
957963

958964
fn consume_site(&mut self, value: String) {
@@ -1143,4 +1149,29 @@ mod tests {
11431149
// The error is still surfaced, so startup's strict gate rejects the config.
11441150
assert!(errors.is_some(), "an unknown action must record a translation error");
11451151
}
1152+
1153+
#[test]
1154+
fn zstd_compressor_level_clamps_up_to_the_minimum() {
1155+
use agent_data_plane_config::shared::ZSTD_MINIMUM;
1156+
1157+
// The Agent's schema default of `1` arrives as a concrete value; it must be raised to the
1158+
// ADP floor rather than lowering our compression level.
1159+
let datadog: DatadogConfiguration = serde_json::from_value(json!({
1160+
"serializer_zstd_compressor_level": 1,
1161+
}))
1162+
.expect("datadog source deserializes");
1163+
let (config, _) = DatadogTranslator::new(&datadog, SalukiConfiguration::default()).translate();
1164+
assert_eq!(
1165+
config.shared.endpoints.compression.zstd_compressor_level, ZSTD_MINIMUM,
1166+
"a level below the floor is clamped up to it"
1167+
);
1168+
1169+
// A level at or above the floor is used as provided.
1170+
let datadog: DatadogConfiguration = serde_json::from_value(json!({
1171+
"serializer_zstd_compressor_level": 7,
1172+
}))
1173+
.expect("datadog source deserializes");
1174+
let (config, _) = DatadogTranslator::new(&datadog, SalukiConfiguration::default()).translate();
1175+
assert_eq!(config.shared.endpoints.compression.zstd_compressor_level, 7);
1176+
}
11461177
}

lib/agent-data-plane-config/src/shared.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,13 @@ pub struct Tls {
118118
pub sslkeylogfile: String,
119119
}
120120

121+
/// Lowest zstd compression level ADP will use for payloads. ADP compresses harder than the core
122+
/// Agent, whose schema default for `serializer_zstd_compressor_level` is `1`. Because the Agent
123+
/// streams a fully-resolved config, that `1` arrives as a concrete value and would otherwise
124+
/// overwrite ADP's intended floor, so the translator clamps anything below this minimum back up to
125+
/// it.
126+
pub const ZSTD_MINIMUM: i32 = 3;
127+
121128
/// Payload compression settings applied before transmission.
122129
#[derive(Clone, Debug, Default, PartialEq, Serialize)]
123130
pub struct Compression {

0 commit comments

Comments
 (0)