Skip to content

Commit 4143951

Browse files
committed
compile-time ensure build_s3_config receives a resolved config as arg
1 parent 41ca763 commit 4143951

1 file changed

Lines changed: 17 additions & 10 deletions

File tree

dial9-tokio-telemetry/src/config.rs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,14 @@ struct ParsedS3Config {
262262
prefix: Option<String>,
263263
}
264264

265+
#[derive(Debug)]
266+
#[cfg_attr(not(feature = "worker-s3"), allow(dead_code))]
267+
struct ResolvedS3Config {
268+
bucket: String,
269+
service_name: Option<String>,
270+
prefix: String,
271+
}
272+
265273
#[derive(Debug)]
266274
struct ResolvedEnvConfig {
267275
enabled: bool,
@@ -277,9 +285,8 @@ struct ResolvedEnvConfig {
277285
// Optional config: None means do not set a runtime name.
278286
runtime_name: Option<String>,
279287

280-
// Optional integration: None means do not configure S3 upload. When Some,
281-
// env-owned S3 defaults have already been applied.
282-
s3: Option<ParsedS3Config>,
288+
// Optional integration: None means do not configure S3 upload.
289+
s3: Option<ResolvedS3Config>,
283290

284291
cpu_profile_enabled: bool,
285292

@@ -362,10 +369,10 @@ fn resolve_env_config(parsed: ParsedEnvConfig) -> ResolvedEnvConfig {
362369
.task_tracking_enabled
363370
.unwrap_or(DEFAULT_TASK_TRACKING_ENABLED),
364371
runtime_name: parsed.runtime_name,
365-
s3: parsed.s3.map(|mut s3| {
366-
s3.prefix
367-
.get_or_insert_with(|| DEFAULT_S3_PREFIX.to_string());
368-
s3
372+
s3: parsed.s3.map(|s3| ResolvedS3Config {
373+
bucket: s3.bucket,
374+
service_name: s3.service_name,
375+
prefix: s3.prefix.unwrap_or_else(|| DEFAULT_S3_PREFIX.to_string()),
369376
}),
370377
cpu_profile_enabled: parsed
371378
.cpu_profile_enabled
@@ -543,11 +550,11 @@ fn apply_runtime_env<M>(
543550
}
544551

545552
#[cfg(feature = "worker-s3")]
546-
fn build_s3_config(config: ParsedS3Config) -> crate::background_task::s3::S3Config {
553+
fn build_s3_config(config: ResolvedS3Config) -> crate::background_task::s3::S3Config {
547554
crate::background_task::s3::S3Config::builder()
548555
.bucket(config.bucket)
549556
.service_name(config.service_name.unwrap_or_else(default_service_name))
550-
.maybe_prefix(config.prefix)
557+
.prefix(config.prefix)
551558
.build()
552559
}
553560

@@ -1062,7 +1069,7 @@ mod tests {
10621069
&FakeEnv::default().with("DIAL9_S3_BUCKET", "b"),
10631070
));
10641071
let s3 = resolved.s3.expect("s3 config should be resolved");
1065-
assert_eq!(s3.prefix.as_deref(), Some(DEFAULT_S3_PREFIX));
1072+
assert_eq!(s3.prefix, DEFAULT_S3_PREFIX);
10661073

10671074
let config = build_s3_config(s3);
10681075

0 commit comments

Comments
 (0)