Skip to content

Commit d2c3cd8

Browse files
authored
chore(deps): upgrade dogstatsd (#1020)
## Overview Continuation of #1018 removing unnecessary mut lock on callers for dogstatsd
1 parent 3ea5aca commit d2c3cd8

3 files changed

Lines changed: 159 additions & 0 deletions

File tree

env.rs

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,24 @@ pub struct EnvConfig {
277277
#[serde(deserialize_with = "deserialize_optional_string")]
278278
pub statsd_metric_namespace: Option<String>,
279279

280+
/// @env `DD_DOGSTATSD_SO_RCVBUF`
281+
/// Size of the receive buffer for `DogStatsD` UDP packets, in bytes (`SO_RCVBUF`).
282+
/// Increase to reduce packet loss under high-throughput metric bursts.
283+
#[serde(deserialize_with = "deserialize_option_lossless")]
284+
pub dogstatsd_so_rcvbuf: Option<usize>,
285+
286+
/// @env `DD_DOGSTATSD_BUFFER_SIZE`
287+
/// Maximum size of a single read from any transport (UDP or named pipe), in bytes.
288+
/// Defaults to 8192.
289+
#[serde(deserialize_with = "deserialize_option_lossless")]
290+
pub dogstatsd_buffer_size: Option<usize>,
291+
292+
/// @env `DD_DOGSTATSD_QUEUE_SIZE`
293+
/// Internal queue capacity between the socket reader and metric processor.
294+
/// Defaults to 1024. Increase if the processor can't keep up with burst traffic.
295+
#[serde(deserialize_with = "deserialize_option_lossless")]
296+
pub dogstatsd_queue_size: Option<usize>,
297+
280298
// OTLP
281299
//
282300
// - APM / Traces
@@ -554,6 +572,11 @@ fn merge_config(config: &mut Config, env_config: &EnvConfig) {
554572
config.statsd_metric_namespace = parse_metric_namespace(namespace);
555573
}
556574

575+
// DogStatsD
576+
merge_option!(config, env_config, dogstatsd_so_rcvbuf);
577+
merge_option!(config, env_config, dogstatsd_buffer_size);
578+
merge_option!(config, env_config, dogstatsd_queue_size);
579+
557580
// OTLP
558581
merge_option_to_value!(config, env_config, otlp_config_traces_enabled);
559582
merge_option_to_value!(
@@ -830,6 +853,11 @@ mod tests {
830853
);
831854
jail.set_env("DD_OTLP_CONFIG_LOGS_ENABLED", "true");
832855

856+
// DogStatsD
857+
jail.set_env("DD_DOGSTATSD_SO_RCVBUF", "1048576");
858+
jail.set_env("DD_DOGSTATSD_BUFFER_SIZE", "65507");
859+
jail.set_env("DD_DOGSTATSD_QUEUE_SIZE", "2048");
860+
833861
// AWS Lambda
834862
jail.set_env(
835863
"DD_API_KEY_SECRET_ARN",
@@ -984,6 +1012,9 @@ mod tests {
9841012
otlp_config_traces_probabilistic_sampler_sampling_percentage: Some(50),
9851013
otlp_config_logs_enabled: true,
9861014
statsd_metric_namespace: None,
1015+
dogstatsd_so_rcvbuf: Some(1048576),
1016+
dogstatsd_buffer_size: Some(65507),
1017+
dogstatsd_queue_size: Some(2048),
9871018
api_key_secret_arn: "arn:aws:secretsmanager:region:account:secret:datadog-api-key"
9881019
.to_string(),
9891020
kms_api_key: "test-kms-key".to_string(),
@@ -1170,4 +1201,43 @@ mod tests {
11701201
Ok(())
11711202
});
11721203
}
1204+
1205+
#[test]
1206+
fn test_dogstatsd_config_from_env() {
1207+
figment::Jail::expect_with(|jail| {
1208+
jail.clear_env();
1209+
jail.set_env("DD_DOGSTATSD_SO_RCVBUF", "1048576");
1210+
jail.set_env("DD_DOGSTATSD_BUFFER_SIZE", "65507");
1211+
jail.set_env("DD_DOGSTATSD_QUEUE_SIZE", "2048");
1212+
1213+
let mut config = Config::default();
1214+
let env_config_source = EnvConfigSource;
1215+
env_config_source
1216+
.load(&mut config)
1217+
.expect("Failed to load config");
1218+
1219+
assert_eq!(config.dogstatsd_so_rcvbuf, Some(1048576));
1220+
assert_eq!(config.dogstatsd_buffer_size, Some(65507));
1221+
assert_eq!(config.dogstatsd_queue_size, Some(2048));
1222+
Ok(())
1223+
});
1224+
}
1225+
1226+
#[test]
1227+
fn test_dogstatsd_config_defaults_to_none() {
1228+
figment::Jail::expect_with(|jail| {
1229+
jail.clear_env();
1230+
1231+
let mut config = Config::default();
1232+
let env_config_source = EnvConfigSource;
1233+
env_config_source
1234+
.load(&mut config)
1235+
.expect("Failed to load config");
1236+
1237+
assert_eq!(config.dogstatsd_so_rcvbuf, None);
1238+
assert_eq!(config.dogstatsd_buffer_size, None);
1239+
assert_eq!(config.dogstatsd_queue_size, None);
1240+
Ok(())
1241+
});
1242+
}
11731243
}

mod.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,17 @@ pub struct Config {
303303
// Metrics
304304
pub metrics_config_compression_level: i32,
305305
pub statsd_metric_namespace: Option<String>,
306+
/// Size of the receive buffer for `DogStatsD` UDP packets, in bytes (`SO_RCVBUF`).
307+
/// Increase to reduce packet loss under high-throughput metric bursts.
308+
/// If None, uses the OS default.
309+
pub dogstatsd_so_rcvbuf: Option<usize>,
310+
/// Maximum size of a single read from any transport (UDP or named pipe), in bytes.
311+
/// Defaults to 8192. For UDP, the client must batch metrics into packets of
312+
/// this size for the increase to take effect.
313+
pub dogstatsd_buffer_size: Option<usize>,
314+
/// Internal queue capacity between the socket reader and metric processor.
315+
/// Defaults to 1024. Increase if the processor can't keep up with burst traffic.
316+
pub dogstatsd_queue_size: Option<usize>,
306317

307318
// OTLP
308319
//
@@ -421,6 +432,14 @@ impl Default for Config {
421432
metrics_config_compression_level: 3,
422433
statsd_metric_namespace: None,
423434

435+
// DogStatsD
436+
// Defaults to None, which uses the OS default.
437+
dogstatsd_so_rcvbuf: None,
438+
// Defaults to 8192 internally.
439+
dogstatsd_buffer_size: None,
440+
// Defaults to 1024 internally.
441+
dogstatsd_queue_size: None,
442+
424443
// OTLP
425444
otlp_config_traces_enabled: true,
426445
otlp_config_traces_span_name_as_resource_name: false,

yaml.rs

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,17 @@ pub struct YamlConfig {
9393
// Metrics
9494
pub metrics_config: MetricsConfig,
9595

96+
// DogStatsD
97+
/// Size of the receive buffer for `DogStatsD` UDP packets, in bytes (`SO_RCVBUF`).
98+
#[serde(deserialize_with = "deserialize_option_lossless")]
99+
pub dogstatsd_so_rcvbuf: Option<usize>,
100+
/// Maximum size of a single read from any transport (UDP or named pipe), in bytes.
101+
#[serde(deserialize_with = "deserialize_option_lossless")]
102+
pub dogstatsd_buffer_size: Option<usize>,
103+
/// Internal queue capacity between the socket reader and metric processor.
104+
#[serde(deserialize_with = "deserialize_option_lossless")]
105+
pub dogstatsd_queue_size: Option<usize>,
106+
96107
// OTLP
97108
pub otlp_config: Option<OtlpConfig>,
98109

@@ -477,6 +488,11 @@ fn merge_config(config: &mut Config, yaml_config: &YamlConfig) {
477488
compression_level
478489
);
479490

491+
// DogStatsD
492+
merge_option!(config, yaml_config, dogstatsd_so_rcvbuf);
493+
merge_option!(config, yaml_config, dogstatsd_buffer_size);
494+
merge_option!(config, yaml_config, dogstatsd_queue_size);
495+
480496
// APM
481497
merge_hashmap!(config, yaml_config, service_mapping);
482498
merge_string!(config, apm_dd_url, yaml_config.apm_config, apm_dd_url);
@@ -814,6 +830,10 @@ trace_aws_service_representation_enabled: true
814830
metrics_config:
815831
compression_level: 3
816832
833+
dogstatsd_so_rcvbuf: 1048576
834+
dogstatsd_buffer_size: 65507
835+
dogstatsd_queue_size: 2048
836+
817837
# OTLP
818838
otlp_config:
819839
receiver:
@@ -1009,6 +1029,9 @@ api_security_sample_delay: 60 # Seconds
10091029
apm_filter_tags_regex_require: None,
10101030
apm_filter_tags_regex_reject: None,
10111031
statsd_metric_namespace: None,
1032+
dogstatsd_so_rcvbuf: Some(1048576),
1033+
dogstatsd_buffer_size: Some(65507),
1034+
dogstatsd_queue_size: Some(2048),
10121035
};
10131036

10141037
// Assert that
@@ -1017,4 +1040,51 @@ api_security_sample_delay: 60 # Seconds
10171040
Ok(())
10181041
});
10191042
}
1043+
1044+
#[test]
1045+
fn test_yaml_dogstatsd_config() {
1046+
figment::Jail::expect_with(|jail| {
1047+
jail.clear_env();
1048+
jail.create_file(
1049+
"datadog.yaml",
1050+
r#"
1051+
dogstatsd_so_rcvbuf: 524288
1052+
dogstatsd_buffer_size: 16384
1053+
dogstatsd_queue_size: 512
1054+
"#,
1055+
)?;
1056+
let mut config = Config::default();
1057+
let yaml_config_source = YamlConfigSource {
1058+
path: Path::new("datadog.yaml").to_path_buf(),
1059+
};
1060+
yaml_config_source
1061+
.load(&mut config)
1062+
.expect("Failed to load config");
1063+
1064+
assert_eq!(config.dogstatsd_so_rcvbuf, Some(524288));
1065+
assert_eq!(config.dogstatsd_buffer_size, Some(16384));
1066+
assert_eq!(config.dogstatsd_queue_size, Some(512));
1067+
Ok(())
1068+
});
1069+
}
1070+
1071+
#[test]
1072+
fn test_yaml_dogstatsd_config_defaults_to_none() {
1073+
figment::Jail::expect_with(|jail| {
1074+
jail.clear_env();
1075+
jail.create_file("datadog.yaml", "")?;
1076+
let mut config = Config::default();
1077+
let yaml_config_source = YamlConfigSource {
1078+
path: Path::new("datadog.yaml").to_path_buf(),
1079+
};
1080+
yaml_config_source
1081+
.load(&mut config)
1082+
.expect("Failed to load config");
1083+
1084+
assert_eq!(config.dogstatsd_so_rcvbuf, None);
1085+
assert_eq!(config.dogstatsd_buffer_size, None);
1086+
assert_eq!(config.dogstatsd_queue_size, None);
1087+
Ok(())
1088+
});
1089+
}
10201090
}

0 commit comments

Comments
 (0)