Skip to content

[SVLS-8713] perf(logs-agent): compress log batches before waiting for the API key - #195

Draft
litianningdatadog wants to merge 1 commit into
tianning.li/logs-sc-4-compress-oncefrom
tianning.li/logs-sc-5-compress-before-key
Draft

litianningdatadog wants to merge 1 commit into
tianning.li/logs-sc-4-compress-oncefrom
tianning.li/logs-sc-5-compress-before-key

Conversation

@litianningdatadog

@litianningdatadog litianningdatadog commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

flush() now compresses its batches first (only if some endpoint uses compression), then awaits the API key resolver, then sends. Same requests and bytes; each batch is still compressed at most once.

Motivation

Part of SVLS-8713: bottlecap (the Datadog Lambda Extension) is replacing its own logs aggregator and flusher with this crate. Two rules for the whole stack:

  • Nothing changes for existing users of this crate (for example serverless-compat): every new behavior is opt-in, defaults and public API stay the same (additions only), no new environment variables, no new dependencies.
  • Nothing changes for Lambda users: the options let bottlecap reproduce its current behavior exactly.

Found by a real Lambda A/B test of bottlecap with this stack vs main: the first flush after a cold start was about 20 ms (11–13%) slower. That flush waits for the first API key lookup (a Secrets Manager call, 70–110 ms), and the shared flusher compressed only after it, while bottlecap's old flusher compressed first so the work overlapped. With compression disabled on both sides the gap disappeared, confirming the cause. Warm flushes weren't affected (the key is cached).

Additional Notes

After this change the same Lambda test showed parity: first-flush time −3.9% [95% CI −7.8%, +2.7%] over 40 cold starts, and warm, 128 MB, high-volume, all flush strategies and failing-intake runs all within noise vs main and vs the v101 release. A #[cfg(test)] thread-local counter in compress_zstd lets the tests check the ordering deterministically (no cost in release builds).

Describe how to test/QA your changes

114 tests pass (new: every batch compressed before the key is requested and not again; extras-only compression; nothing compressed when no endpoint wants it; each mutation-checked). Workspace clippy, FIPS clippy and cargo check -p datadog-serverless-compat clean.

Stack

Each PR is nested under the PR it builds on (and targets). Review and merge from the top down.

serverless-components (datadog-logs-agent options; merge first)

datadog-lambda-extension (bottlecap)

🤖 Generated with Claude Code

Why: with an API key resolver, the flusher waited for the key and only then
compressed the batches. The first key lookup can be slow (for example the
first Secrets Manager call after a Lambda cold start, about 70-110 ms), so
compression time was added on top of it. Measured on Lambda with bottlecap,
this made the first flush after a cold start about 20 ms (11-13%) slower
than bottlecap's own flusher, which compressed first. Warm flushes were not
affected because the key is cached.

What: each flush now compresses its batches first (only if some endpoint
uses compression), then waits for the key, then sends. Compression can now
overlap a key lookup that is already in flight, for example one started by
another flusher that shares the key source. The requests and bytes sent do
not change, and each batch is still compressed at most once. New tests
check that every batch is compressed before the key is requested and not
compressed again, that an additional endpoint alone triggers the early
compression, and that nothing is compressed when no endpoint wants it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@litianningdatadog
litianningdatadog force-pushed the tianning.li/logs-sc-5-compress-before-key branch from 3fad977 to cff2697 Compare October 21, 2026 19:52
@litianningdatadog
litianningdatadog force-pushed the tianning.li/logs-sc-4-compress-once branch from 89ab609 to 84cb56d Compare October 21, 2026 19:52

This branch has not been deployed

No deployments
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.

1 participant