Skip to content

chore: pass SendDataBuilderInfo instead of SendData until flush time #745

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

Merged
merged 12 commits into from
Jul 16, 2025

Conversation

lym953
Copy link
Contributor

@lym953 lym953 commented Jul 14, 2025

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

@lym953 lym953 force-pushed the yiming.luo/upgrade-libdd branch from 1ae5c33 to d460d15 Compare July 14, 2025 21:41
@lym953 lym953 force-pushed the yiming.luo/send-data-builder branch from ad6fad4 to 20c90e4 Compare July 14, 2025 21:41
@lym953 lym953 marked this pull request as ready for review July 14, 2025 21:42
@lym953 lym953 requested a review from a team as a code owner July 14, 2025 21:42
@lym953 lym953 force-pushed the yiming.luo/upgrade-libdd branch from d460d15 to d3c142e Compare July 14, 2025 23:04
Base automatically changed from yiming.luo/upgrade-libdd to main July 14, 2025 23:53
@lym953 lym953 force-pushed the yiming.luo/send-data-builder branch from 20c90e4 to 622a2d6 Compare July 14, 2025 23:53
@lym953 lym953 changed the title chore: pass SendDataBuilder instead of SendData until flush time chore: pass SendDataBuilderInfo instead of SendData until flush time Jul 16, 2025
Comment on lines +10 to +22
// Bundle SendDataBuilder with payload size because SendDataBuilder doesn't
// expose a getter for the size
pub struct SendDataBuilderInfo {
pub builder: SendDataBuilder,
pub size: usize,
}

impl SendDataBuilderInfo {
pub fn new(builder: SendDataBuilder, size: usize) -> Self {
Self { builder, size }
}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding SendDataBuilderInfo in trace_aggregator.rs because this is where the size is consumed. Let me know if you have a better place.

// TODO(duncanista): revisit if this is bigger than limit
let payload_size = payload.len();
let payload_size = payload_info.size;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

size is consumed here

while !trace_builders.is_empty() {
let traces: Vec<_> = trace_builders
.into_iter()
.map(SendDataBuilder::build)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

build() is called here

.with_compression(Compression::Zstd(6))
.build();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

build() is no longer called here

None,
));

SendDataBuilderInfo::new(builder, body_size)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SendDataBuilderInfo is constructed here

@lym953 lym953 force-pushed the yiming.luo/send-data-builder branch from 531ce59 to 84cadbf Compare July 16, 2025 19:55
@lym953 lym953 merged commit f37bb89 into main Jul 16, 2025
46 checks passed
@lym953 lym953 deleted the yiming.luo/send-data-builder branch July 16, 2025 20:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants