-
Notifications
You must be signed in to change notification settings - Fork 13
Add functions to SendDataBuilder #1140
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
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1140 +/- ##
==========================================
+ Coverage 71.29% 71.36% +0.07%
==========================================
Files 343 343
Lines 52536 52567 +31
==========================================
+ Hits 37453 37516 +63
+ Misses 15083 15051 -32
🚀 New features to boost your workflow:
|
/// # Returns | ||
/// | ||
/// A mutable reference to the target endpoint. | ||
pub fn get_target_mut(&mut self) -> &mut Endpoint { |
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.
You really shouldn't be changing the target for the SendData object. This was just discussed with @shreyamalpani for #1134 and #1139
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.
Could you elaborate why? I don't see enough discussion in those two PRs.
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.
I'm reading the discussion in Slack https://dd.slack.com/archives/C01TCF143GB/p1752081547534679
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 send_with_retry module uses the endpoint. It's creates inconsistent behavior if the endpoint changes between retries.
The coalesce_send_data function sorts and deduplicates SendData based on endpoint properties. Changing the endpoints can lead to invalid deduplication and/or merged payloads being sent to the wrong destination.
send_data also has async code that uses the endpoint. Changing them can cause unexpected behavior and race conditions.
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.
Thanks for the context! Will it still be a concern if we only expose set_api_key()
? From a quick look at your code pointers, I see url
, timeout_ms
and test_token
used, but not api_key
.
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.
Changing the API key wouldn't impact the coalesce_send_data
function, but it would impact send_with_retry
which calls to_request_builder()
which uses the api key. Changing just the API key can cause another issue; I don't think it's a particularly good design, but send_data
determines whether to serialize to msgpack or proto based on the presence of an API key. If that switches from None
to Some
while the url remains the same it can lead to runtime errors.
If you need to lazily add the api key, I'd suggest adding a with_api_key()
function to SendDataBuilder.
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.
Sure! I limited all the changes to SendDataBuilder
. Could you take a look?
BenchmarksComparisonBenchmark execution time: 2025-07-16 16:52:13 Comparing candidate commit 6c28f32 in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 52 metrics, 2 unstable metrics. CandidateCandidate benchmark detailsGroup 1
Group 2
Group 3
Group 4
Group 5
Group 6
Group 7
Group 8
Group 9
Group 10
Group 11
Group 12
Group 13
BaselineOmitted due to size. |
Artifact Size Benchmark Reportaarch64-alpine-linux-musl
aarch64-unknown-linux-gnu
libdatadog-x64-windows
libdatadog-x86-windows
x86_64-alpine-linux-musl
x86_64-unknown-linux-gnu
|
e5112d1
to
0b1b61e
Compare
/// # Returns | ||
/// | ||
/// The size of the data. | ||
pub fn len(&self) -> usize { |
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.
I don't think adding getters to builders is generally a good idea. The value of the builder pattern in Rust is to allow flexible setting of parameters while deferring construction until build()
is called. This means the properties on the builder can represent an invalid state for the thing being built. It also means the values may not be set at all.
I'm not recommending it be changed as part of this PR as it already exists...but I would argue all properties should be Option
on a builder. Size shouldn't just be usize
. Is the size actually 0? Or have we just not set it yet on the builder?
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.
Thanks for the feedback! I will pass the size alongside SendDataBuilder
in our codebase instead of calling the getter.
391a01a
to
6c28f32
Compare
/merge |
View all feedbacks in Devflow UI.
The expected merge time in
|
…745) # Background Right now `SendData` is passed around across channels. # This PR Instead of passing `SendData`, pass `SendDataBuilderInfo`, which bundles `SendDataBuilder` and payload size. Just before flush, call `SendDataBuilder.build()` to build `SendData`. # Motivation DataDog/libdatadog#1140 (comment) It is suggested that the function `set_api_key()` shouldn't be added on `SendData`, but should be added on `SendDataBuilder`. Because need to call `set_api_key()` just before flush, we need to make sure the object is `SendDataBuilder` instead of `SendData` until flush time. And because we need payload size in Trace Aggregator, and `SendDataBuilder` doesn't expose this field, we need to pass it explicitly along with `SendDataBuilder`. # Next steps Update #717 #732 so that `get_api_key()` is called just before flush. # Dependency DataDog/libdatadog#1140
# Context The previous PR #717 defers API key resolution from extension init stage to flush time. However, that PR doesn't well handle the failure case. - Before that PR, if resolution fails in init stage, the extension will run an idle loop. - After that PR, the extension will crash at flush time, which will kill the runtime as well, which is not desired. # What does this PR do? 1. For traces, defer key resolution from `TraceProcessor.process_traces()` to `TraceFlusher.flush()`. - (This should ideally be in the previous PR, but since that is already approved, let me add this change in this new PR.) 2. If resolution fails at flush time, then make flush a no-op, so the extension can keep running and consume events without crashing. # Dependencies 1. DataDog/serverless-components#25 2. DataDog/libdatadog#1140 # Manual Test ## Steps 1. Create a layer in sandbox 2. Apply the layer to a Lambda function 3. Set the env var `DD_API_KEY_SECRET_ARN` to an invalid value 5. Run the Lambda 6. Then set `DD_API_KEY_SECRET_ARN` to a valid value 7. Run the Lambda ## Result 1. The function was successful <img width="319" alt="image" src="https://github.com/user-attachments/assets/f8a5cb36-f678-4643-ba1c-85f41256ffa1" /> 2. The extension printed some error logs <img width="737" height="33" alt="image" src="https://github.com/user-attachments/assets/22553d24-e1f5-4ee5-9a91-0d18e3e2f297" /> <img width="603" height="186" alt="image" src="https://github.com/user-attachments/assets/e797f991-ecba-45f0-8f49-7b7b59dd9e7b" /> 3. With valid secret ARN, the Lambda runs successfully and reports to Datadog <img width="678" height="150" alt="image" src="https://github.com/user-attachments/assets/073089f8-1e9a-4728-b8d1-1db7aa85d031" /> <img width="533" height="96" alt="image" src="https://github.com/user-attachments/assets/d5f2b81c-5e02-42bc-b3ef-85e611228fc6" /> # Automated Test I didn't add any automated test because from what I see in the codebase, existing tests are usually unit tests for short functions and not for long functions that this PR touches. Please let me know if you think I should add automated tests.
What does this PR do?
Add functions to
SendDataBuilder
:with_api_key()
with_retry_strategy()
Motivation
DataDog/datadog-lambda-extension#732 We want to lazily set api key in the
target
, i.e. leave it empty at creation time then set it later.As a result, we need to pass
SendDataBuilder
around in the codebase, instead of passingSendData
. Wherever we need to set data onSendData
right now, we need to do it onSendDataBuilder
instead.How to test the change?
Using the added test