diff --git a/rust/cyclotron-fetch/src/config.rs b/rust/cyclotron-fetch/src/config.rs index 4f981359823a6..668e32e491491 100644 --- a/rust/cyclotron-fetch/src/config.rs +++ b/rust/cyclotron-fetch/src/config.rs @@ -32,22 +32,39 @@ pub struct Config { #[envconfig(default = "false")] pub allow_internal_ips: bool, - pub worker_id: Option, // Default to a UUID - pub job_poll_interval_seconds: Option, // Defaults to 1 - pub concurrent_requests_limit: Option, // Defaults to 1000 - pub fetch_timeout_seconds: Option, // Defaults to 30 - pub max_retry_attempts: Option, // Defaults to 10 - pub queue_served: Option, // Default to "fetch" - pub batch_size: Option, // Defaults to 1000 - pub max_response_bytes: Option, // Defaults to 1MB - pub retry_backoff_base_ms: Option, // Defaults to 4000 + #[envconfig(default = "default_worker_id")] + pub worker_id: String, + + #[envconfig(default = "1")] + pub job_poll_interval_seconds: i64, + + #[envconfig(default = "1000")] + pub concurrent_requests_limit: u32, + + #[envconfig(default = "30")] + pub fetch_timeout_seconds: i64, + + #[envconfig(default = "10")] + pub max_retry_attempts: u32, + + #[envconfig(default = "fetch")] + pub queue_served: String, + + #[envconfig(default = "1000")] + pub batch_size: usize, + + #[envconfig(default = "1000000")] + pub max_response_bytes: usize, + + #[envconfig(default = "4000")] + pub retry_backoff_base_ms: i64, +} + +#[allow(dead_code)] +fn default_worker_id() -> String { + Uuid::now_v7().to_string() } -// I do this instead of using envconfig's defaults because -// envconfig doesn't support defaults provided by functions, -// which is frustrating when I want to use UUIDs, and if I'm -// going to break out one field, I might as well break out -// everything into "AppConfig" and "PoolConfig" #[derive(Debug, Clone)] pub struct AppConfig { pub host: String, @@ -66,27 +83,18 @@ pub struct AppConfig { impl Config { pub fn to_components(self) -> (AppConfig, PoolConfig) { - let worker_id = self.worker_id.unwrap_or_else(|| Uuid::now_v7().to_string()); - let job_poll_interval_seconds = self.job_poll_interval_seconds.unwrap_or(1); - let concurrent_requests_limit = self.concurrent_requests_limit.unwrap_or(1000); - let fetch_timeout_seconds = self.fetch_timeout_seconds.unwrap_or(30); - let max_retry_attempts = self.max_retry_attempts.unwrap_or(10); - let queue_served = self.queue_served.unwrap_or_else(|| "fetch".to_string()); - let app_config = AppConfig { host: self.host, port: self.port, - worker_id, - job_poll_interval: Duration::seconds(job_poll_interval_seconds as i64), - concurrent_requests_limit, - fetch_timeout: Duration::seconds(fetch_timeout_seconds as i64), - max_retry_attempts, - queue_served, - batch_size: self.batch_size.unwrap_or(1000), - max_response_bytes: self.max_response_bytes.unwrap_or(1024 * 1024), - retry_backoff_base: Duration::milliseconds( - self.retry_backoff_base_ms.unwrap_or(4000) as i64 - ), + worker_id: self.worker_id, + job_poll_interval: Duration::seconds(self.job_poll_interval_seconds), + concurrent_requests_limit: self.concurrent_requests_limit, + fetch_timeout: Duration::seconds(self.fetch_timeout_seconds), + max_retry_attempts: self.max_retry_attempts, + queue_served: self.queue_served, + batch_size: self.batch_size, + max_response_bytes: self.max_response_bytes, + retry_backoff_base: Duration::milliseconds(self.retry_backoff_base_ms), allow_internal_ips: self.allow_internal_ips, }; diff --git a/rust/cyclotron-janitor/src/config.rs b/rust/cyclotron-janitor/src/config.rs index 12f3b0796db02..4169d9df9b789 100644 --- a/rust/cyclotron-janitor/src/config.rs +++ b/rust/cyclotron-janitor/src/config.rs @@ -35,7 +35,8 @@ pub struct Config { // Generally, this should be equivalent to a "shard id", as only one janitor should be running // per shard - pub janitor_id: Option, + #[envconfig(default = "default_janitor_id")] + pub janitor_id: String, #[envconfig(default = "10")] pub janitor_max_touches: i16, @@ -44,6 +45,11 @@ pub struct Config { pub janitor_stall_timeout_seconds: u16, } +#[allow(dead_code)] +fn default_worker_id() -> String { + Uuid::now_v7().to_string() +} + impl Config { pub fn get_janitor_config(&self) -> JanitorConfig { let pool_config = PoolConfig { @@ -58,10 +64,7 @@ impl Config { let settings = JanitorSettings { stall_timeout: Duration::seconds(self.janitor_stall_timeout_seconds as i64), max_touches: self.janitor_max_touches, - id: self - .janitor_id - .clone() - .unwrap_or_else(|| Uuid::now_v7().to_string()), + id: self.janitor_id.clone(), }; JanitorConfig { diff --git a/rust/feature-flags/src/v0_endpoint.rs b/rust/feature-flags/src/v0_endpoint.rs index 65136e5c42772..95d4c3a813685 100644 --- a/rust/feature-flags/src/v0_endpoint.rs +++ b/rust/feature-flags/src/v0_endpoint.rs @@ -71,7 +71,7 @@ pub async fn flags( tracing::Span::current().record("method", method.as_str()); tracing::Span::current().record("path", path.as_str().trim_end_matches('/')); tracing::Span::current().record("ip", ip.to_string()); - tracing::Span::current().record("sent_at", &sent_at.to_string()); + tracing::Span::current().record("sent_at", sent_at.to_string()); tracing::debug!("request headers: {:?}", headers);