-
Notifications
You must be signed in to change notification settings - Fork 20
[SVLS-9189] feat(logs): add config param DD_LAMBDA_DURABLE_FUNCTION_LOG_BUFFER_SIZE #1239
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
base: main
Are you sure you want to change the base?
Changes from all commits
2c5ce6c
f72a2d5
192655b
947c6a4
47442b3
fe0be91
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -60,15 +60,13 @@ pub struct LambdaProcessor { | |
| durable_context_map: HashMap<String, DurableExecutionContext>, | ||
| // Insertion order for FIFO eviction when map reaches capacity | ||
| durable_context_order: VecDeque<String>, | ||
| // Max number of request ID keys in held_logs. 0 disables holding entirely. | ||
| lambda_durable_function_log_buffer_size: usize, | ||
| } | ||
|
|
||
| // Matches `lifecycle::invocation::ContextBuffer` default capacity: sized to absorb async | ||
| // event backlog where invocation contexts may arrive out of order. | ||
| const DURABLE_CONTEXT_MAP_CAPACITY: usize = 500; | ||
| // Kept intentionally small: at shutdown, all held logs are flushed without durable context. | ||
| // A large cap would mean a large batch sent in one shot, increasing the risk of the final | ||
| // flush timing out when the tracer is not installed. | ||
| const HELD_LOGS_MAX_KEYS: usize = 50; | ||
|
|
||
| const OOM_ERRORS: [&str; 7] = [ | ||
| "fatal error: runtime: out of memory", // Go | ||
|
|
@@ -143,6 +141,8 @@ impl LambdaProcessor { | |
|
|
||
| let processing_rules = &datadog_config.logs_config_processing_rules; | ||
| let logs_enabled = datadog_config.serverless_logs_enabled; | ||
| let lambda_durable_function_log_buffer_size = | ||
| datadog_config.lambda_durable_function_log_buffer_size; | ||
| let rules = LambdaProcessor::compile_rules(processing_rules); | ||
| LambdaProcessor { | ||
| function_arn, | ||
|
|
@@ -160,6 +160,7 @@ impl LambdaProcessor { | |
| held_logs_order: VecDeque::new(), | ||
| durable_context_map: HashMap::with_capacity(DURABLE_CONTEXT_MAP_CAPACITY), | ||
| durable_context_order: VecDeque::with_capacity(DURABLE_CONTEXT_MAP_CAPACITY), | ||
| lambda_durable_function_log_buffer_size, | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -682,9 +683,15 @@ impl LambdaProcessor { | |
| /// its logs are drained to `ready_logs` without durable context tags. This ensures logs are | ||
| /// always eventually sent to Datadog even if the tracer is not installed and context never | ||
| /// arrives. | ||
| /// | ||
| /// Callers must ensure `self.lambda_durable_function_log_buffer_size > 0` before invoking | ||
| /// this function. A safety net at the top returns early if the invariant is violated. | ||
| fn hold_log(&mut self, request_id: String, log: IntakeLog) { | ||
| if self.lambda_durable_function_log_buffer_size == 0 { | ||
| return; | ||
| } | ||
| if !self.held_logs.contains_key(&request_id) { | ||
| while self.held_logs.len() >= HELD_LOGS_MAX_KEYS { | ||
| while self.held_logs.len() >= self.lambda_durable_function_log_buffer_size { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in case self.lambda_durable_function_log_buffer_size == 0, this check will always be true, while could lead to infinite loop. Is this an expected behavior?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The caller already ensures
|
||
| // Evict the oldest key to ready_logs (without durable context tags). | ||
| if let Some(oldest) = self.held_logs_order.pop_front() | ||
| && let Some(evicted) = self.held_logs.remove(&oldest) | ||
|
|
@@ -723,6 +730,16 @@ impl LambdaProcessor { | |
| return; | ||
| } | ||
|
|
||
| // When the buffer is disabled, skip holding and send logs immediately without | ||
| // durable execution context enrichment. | ||
| if self.lambda_durable_function_log_buffer_size == 0 { | ||
| if let Ok(serialized_log) = serde_json::to_string(&log) { | ||
| drop(log); | ||
| self.ready_logs.push(serialized_log); | ||
| } | ||
| return; | ||
| } | ||
|
|
||
| match self.is_durable_function { | ||
| // We don't yet know if this is a durable function. Hold the log until we know. | ||
| None => { | ||
|
|
@@ -2569,6 +2586,7 @@ mod tests { | |
| #[tokio::test] | ||
| async fn test_function_log_without_execution_arn_is_held_in_durable_mode() { | ||
| let mut processor = make_processor_for_durable_arn_tests(); | ||
| processor.lambda_durable_function_log_buffer_size = 50; | ||
| processor.is_durable_function = Some(true); | ||
| // Simulate a known request_id with no durable context yet | ||
| processor.invocation_context.request_id = "req-123".to_string(); | ||
|
|
@@ -2594,6 +2612,7 @@ mod tests { | |
| (None, serde_json::Value::Null), | ||
| ] { | ||
| let mut processor = make_processor_for_durable_arn_tests(); | ||
| processor.lambda_durable_function_log_buffer_size = 50; | ||
| processor.is_durable_function = Some(true); | ||
| processor.invocation_context.request_id = "req-end".to_string(); | ||
| processor.insert_to_durable_context_map( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR title and message both mentioned DD_DURABLE_FUNCTION_LOG_BUFFER_SIZE which is different from above comment. Did I miss anything?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. PR title and message were outdated. Updated.