-
Notifications
You must be signed in to change notification settings - Fork 20
[SVLS-9189] feat(logs): add config param DD_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
Open
lym953
wants to merge
2
commits into
main
Choose a base branch
from
yiming.luo/durable-log-buffer-size
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. | ||
| held_logs_max_keys: 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,7 @@ impl LambdaProcessor { | |
|
|
||
| let processing_rules = &datadog_config.logs_config_processing_rules; | ||
| let logs_enabled = datadog_config.serverless_logs_enabled; | ||
| let held_logs_max_keys = datadog_config.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. nit: rename held_logs_max_keys to durable_function_log_buffer_size or sth. similar for better readability. |
||
| let rules = LambdaProcessor::compile_rules(processing_rules); | ||
| LambdaProcessor { | ||
| function_arn, | ||
|
|
@@ -160,6 +159,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), | ||
| held_logs_max_keys, | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -684,7 +684,7 @@ impl LambdaProcessor { | |
| /// arrives. | ||
| fn hold_log(&mut self, request_id: String, log: IntakeLog) { | ||
| if !self.held_logs.contains_key(&request_id) { | ||
| while self.held_logs.len() >= HELD_LOGS_MAX_KEYS { | ||
| while self.held_logs.len() >= self.held_logs_max_keys { | ||
| // 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 +723,16 @@ impl LambdaProcessor { | |
| return; | ||
| } | ||
|
|
||
| // When the buffer is disabled, skip holding and send logs immediately without | ||
| // durable execution context enrichment. | ||
| if self.held_logs_max_keys == 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 +2579,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.held_logs_max_keys = 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 +2605,7 @@ mod tests { | |
| (None, serde_json::Value::Null), | ||
| ] { | ||
| let mut processor = make_processor_for_durable_arn_tests(); | ||
| processor.held_logs_max_keys = 50; | ||
| processor.is_durable_function = Some(true); | ||
| processor.invocation_context.request_id = "req-end".to_string(); | ||
| processor.insert_to_durable_context_map( | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Wondering if this should include the
LAMBDAprefix, since we're gonna migrate to the config package from serverless-components eventually,that way it makes it more descriptive that its for the lambda product