Skip to content

Commit d8ed1a6

Browse files
authored
feat: continuous flushing strategy for high throughput functions (#684)
This is a heavy refactor and new feature. - Introduces FlushDecision and separates it from FlushStrategy - Cleans up FlushControl logic and methods It also adds the ability to flush telemetry across multiple serial lambda invocations. This is done using the `continuous` strategy. This is a huge win for busy functions as seen in our test fleet, where the p99/max drops precipitously, which also causes the average to plummet. This also helps reduce the number of cold starts encountered during scaleup events, which further reduces latency along with costs: ![image](https://github.com/user-attachments/assets/14851e22-327d-43b0-8246-5780cfbf6ef7) Technical implementation: We spawn the task and collect the flush handles, then in the two periodic strategies we check if there were any errors or unresolved futures in the next flush cycle. If so, we switch to the `periodic` strategy to ensure flushing completes successfully. We don't adapt to the periodic strategy unless the last 20 invocations occurred within the `config.flush_timeout` value, which has been increased by default. This is a naive implementation. A better one would be to calculate the first derivative of the invocation periodicity. If the rate is increasing, we can adapt to the continuous strategy. If the rate slows, we should fall back to the periodic strategy. <img width="807" alt="image" src="https://github.com/user-attachments/assets/d3c25419-f1da-4774-975f-0e254047b9b7" /> The existing implementation is cautious in that we could definitely adapt sooner but don't. Todo: add a feature flag for continuous flushing?
1 parent 1384922 commit d8ed1a6

17 files changed

Lines changed: 743 additions & 190 deletions

File tree

.github/workflows/rs_ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ jobs:
139139
tool: nextest@0.9
140140
- uses: mozilla-actions/sccache-action@v0.0.9
141141
- working-directory: bottlecap
142-
run: cargo nextest run --workspace
142+
run: cargo nextest run --workspace --features integration_test
143143

144144
format:
145145
name: Format

bottlecap/Cargo.lock

Lines changed: 15 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bottlecap/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ rustls-native-certs = { version = "0.8.1", optional = true }
5050
# method in favor of our
5151
# datadog_fips::reqwest_adapter::create_reqwest_client_builder. An example can
5252
# be found in the clippy.toml file adjacent to this Cargo.toml.
53-
datadog-protos = { version = "0.1.0", default-features = false, git = "https://github.com/DataDog/saluki/" }
53+
datadog-protos = { version = "0.1.0", default-features = false, git = "https://github.com/DataDog/saluki/", rev = "c89b58e5784b985819baf11f13f7d35876741222"}
5454
ddsketch-agent = { version = "0.1.0", default-features = false, git = "https://github.com/DataDog/saluki/" }
5555
ddcommon = { git = "https://github.com/DataDog/libdatadog", rev = "d6a2da32c6b92d6865a7e7987c8a1df2203fb1ae" }
5656
datadog-trace-protobuf = { git = "https://github.com/DataDog/libdatadog", rev = "d6a2da32c6b92d6865a7e7987c8a1df2203fb1ae" }
5757
datadog-trace-utils = { git = "https://github.com/DataDog/libdatadog", rev = "d6a2da32c6b92d6865a7e7987c8a1df2203fb1ae" , features = ["compression"] }
5858
datadog-trace-normalization = { git = "https://github.com/DataDog/libdatadog", rev = "d6a2da32c6b92d6865a7e7987c8a1df2203fb1ae" }
5959
datadog-trace-obfuscation = { git = "https://github.com/DataDog/libdatadog", rev = "d6a2da32c6b92d6865a7e7987c8a1df2203fb1ae" }
60-
dogstatsd = { git = "https://github.com/DataDog/serverless-components", rev = "3f3347790d4c7f3393589ef7efb7ccf22405a89a", default-features = false }
60+
dogstatsd = { git = "https://github.com/DataDog/serverless-components", rev = "b1583da00e202985057cf6d48f05e1cac77ab910", default-features = false }
6161
datadog-trace-agent = { git = "https://github.com/DataDog/serverless-components", rev = "3f3347790d4c7f3393589ef7efb7ccf22405a89a" }
6262
datadog-fips = { git = "https://github.com/DataDog/serverless-components", rev = "3f3347790d4c7f3393589ef7efb7ccf22405a89a", default-features = false }
6363
axum = { version = "0.8.4", default-features = false, features = ["default"] }
@@ -97,3 +97,4 @@ fips = [
9797
"rustls/fips",
9898
"rustls-native-certs",
9999
]
100+
integration_test = ["reqwest/rustls-tls", "dogstatsd/default", "datadog-fips/default" ]

bottlecap/LICENSE-3rdparty.yml

Lines changed: 209 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4226,6 +4226,214 @@ third_party_libraries:
42264226

42274227
END OF TERMS AND CONDITIONS
42284228

4229+
APPENDIX: How to apply the Apache License to your work.
4230+
4231+
To apply the Apache License to your work, attach the following
4232+
boilerplate notice, with the fields enclosed by brackets "[]"
4233+
replaced with your own identifying information. (Don't include
4234+
the brackets!) The text should be enclosed in the appropriate
4235+
comment syntax for the file format. We also recommend that a
4236+
file or class name and description of purpose be included on the
4237+
same "printed page" as the copyright notice for easier
4238+
identification within third-party archives.
4239+
4240+
Copyright 2025 Datadog, Inc.
4241+
4242+
Licensed under the Apache License, Version 2.0 (the "License");
4243+
you may not use this file except in compliance with the License.
4244+
You may obtain a copy of the License at
4245+
4246+
http://www.apache.org/licenses/LICENSE-2.0
4247+
4248+
Unless required by applicable law or agreed to in writing, software
4249+
distributed under the License is distributed on an "AS IS" BASIS,
4250+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
4251+
See the License for the specific language governing permissions and
4252+
limitations under the License.
4253+
- package_name: datadog-fips
4254+
package_version: 0.1.0
4255+
repository: https://github.com/DataDog/serverless-components
4256+
license: Apache-2.0
4257+
licenses:
4258+
- license: Apache-2.0
4259+
text: |2
4260+
Apache License
4261+
Version 2.0, January 2004
4262+
http://www.apache.org/licenses/
4263+
4264+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
4265+
4266+
1. Definitions.
4267+
4268+
"License" shall mean the terms and conditions for use, reproduction,
4269+
and distribution as defined by Sections 1 through 9 of this document.
4270+
4271+
"Licensor" shall mean the copyright owner or entity authorized by
4272+
the copyright owner that is granting the License.
4273+
4274+
"Legal Entity" shall mean the union of the acting entity and all
4275+
other entities that control, are controlled by, or are under common
4276+
control with that entity. For the purposes of this definition,
4277+
"control" means (i) the power, direct or indirect, to cause the
4278+
direction or management of such entity, whether by contract or
4279+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
4280+
outstanding shares, or (iii) beneficial ownership of such entity.
4281+
4282+
"You" (or "Your") shall mean an individual or Legal Entity
4283+
exercising permissions granted by this License.
4284+
4285+
"Source" form shall mean the preferred form for making modifications,
4286+
including but not limited to software source code, documentation
4287+
source, and configuration files.
4288+
4289+
"Object" form shall mean any form resulting from mechanical
4290+
transformation or translation of a Source form, including but
4291+
not limited to compiled object code, generated documentation,
4292+
and conversions to other media types.
4293+
4294+
"Work" shall mean the work of authorship, whether in Source or
4295+
Object form, made available under the License, as indicated by a
4296+
copyright notice that is included in or attached to the work
4297+
(an example is provided in the Appendix below).
4298+
4299+
"Derivative Works" shall mean any work, whether in Source or Object
4300+
form, that is based on (or derived from) the Work and for which the
4301+
editorial revisions, annotations, elaborations, or other modifications
4302+
represent, as a whole, an original work of authorship. For the purposes
4303+
of this License, Derivative Works shall not include works that remain
4304+
separable from, or merely link (or bind by name) to the interfaces of,
4305+
the Work and Derivative Works thereof.
4306+
4307+
"Contribution" shall mean any work of authorship, including
4308+
the original version of the Work and any modifications or additions
4309+
to that Work or Derivative Works thereof, that is intentionally
4310+
submitted to Licensor for inclusion in the Work by the copyright owner
4311+
or by an individual or Legal Entity authorized to submit on behalf of
4312+
the copyright owner. For the purposes of this definition, "submitted"
4313+
means any form of electronic, verbal, or written communication sent
4314+
to the Licensor or its representatives, including but not limited to
4315+
communication on electronic mailing lists, source code control systems,
4316+
and issue tracking systems that are managed by, or on behalf of, the
4317+
Licensor for the purpose of discussing and improving the Work, but
4318+
excluding communication that is conspicuously marked or otherwise
4319+
designated in writing by the copyright owner as "Not a Contribution."
4320+
4321+
"Contributor" shall mean Licensor and any individual or Legal Entity
4322+
on behalf of whom a Contribution has been received by Licensor and
4323+
subsequently incorporated within the Work.
4324+
4325+
2. Grant of Copyright License. Subject to the terms and conditions of
4326+
this License, each Contributor hereby grants to You a perpetual,
4327+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
4328+
copyright license to reproduce, prepare Derivative Works of,
4329+
publicly display, publicly perform, sublicense, and distribute the
4330+
Work and such Derivative Works in Source or Object form.
4331+
4332+
3. Grant of Patent License. Subject to the terms and conditions of
4333+
this License, each Contributor hereby grants to You a perpetual,
4334+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
4335+
(except as stated in this section) patent license to make, have made,
4336+
use, offer to sell, sell, import, and otherwise transfer the Work,
4337+
where such license applies only to those patent claims licensable
4338+
by such Contributor that are necessarily infringed by their
4339+
Contribution(s) alone or by combination of their Contribution(s)
4340+
with the Work to which such Contribution(s) was submitted. If You
4341+
institute patent litigation against any entity (including a
4342+
cross-claim or counterclaim in a lawsuit) alleging that the Work
4343+
or a Contribution incorporated within the Work constitutes direct
4344+
or contributory patent infringement, then any patent licenses
4345+
granted to You under this License for that Work shall terminate
4346+
as of the date such litigation is filed.
4347+
4348+
4. Redistribution. You may reproduce and distribute copies of the
4349+
Work or Derivative Works thereof in any medium, with or without
4350+
modifications, and in Source or Object form, provided that You
4351+
meet the following conditions:
4352+
4353+
(a) You must give any other recipients of the Work or
4354+
Derivative Works a copy of this License; and
4355+
4356+
(b) You must cause any modified files to carry prominent notices
4357+
stating that You changed the files; and
4358+
4359+
(c) You must retain, in the Source form of any Derivative Works
4360+
that You distribute, all copyright, patent, trademark, and
4361+
attribution notices from the Source form of the Work,
4362+
excluding those notices that do not pertain to any part of
4363+
the Derivative Works; and
4364+
4365+
(d) If the Work includes a "NOTICE" text file as part of its
4366+
distribution, then any Derivative Works that You distribute must
4367+
include a readable copy of the attribution notices contained
4368+
within such NOTICE file, excluding those notices that do not
4369+
pertain to any part of the Derivative Works, in at least one
4370+
of the following places: within a NOTICE text file distributed
4371+
as part of the Derivative Works; within the Source form or
4372+
documentation, if provided along with the Derivative Works; or,
4373+
within a display generated by the Derivative Works, if and
4374+
wherever such third-party notices normally appear. The contents
4375+
of the NOTICE file are for informational purposes only and
4376+
do not modify the License. You may add Your own attribution
4377+
notices within Derivative Works that You distribute, alongside
4378+
or as an addendum to the NOTICE text from the Work, provided
4379+
that such additional attribution notices cannot be construed
4380+
as modifying the License.
4381+
4382+
You may add Your own copyright statement to Your modifications and
4383+
may provide additional or different license terms and conditions
4384+
for use, reproduction, or distribution of Your modifications, or
4385+
for any such Derivative Works as a whole, provided Your use,
4386+
reproduction, and distribution of the Work otherwise complies with
4387+
the conditions stated in this License.
4388+
4389+
5. Submission of Contributions. Unless You explicitly state otherwise,
4390+
any Contribution intentionally submitted for inclusion in the Work
4391+
by You to the Licensor shall be under the terms and conditions of
4392+
this License, without any additional terms or conditions.
4393+
Notwithstanding the above, nothing herein shall supersede or modify
4394+
the terms of any separate license agreement you may have executed
4395+
with Licensor regarding such Contributions.
4396+
4397+
6. Trademarks. This License does not grant permission to use the trade
4398+
names, trademarks, service marks, or product names of the Licensor,
4399+
except as required for reasonable and customary use in describing the
4400+
origin of the Work and reproducing the content of the NOTICE file.
4401+
4402+
7. Disclaimer of Warranty. Unless required by applicable law or
4403+
agreed to in writing, Licensor provides the Work (and each
4404+
Contributor provides its Contributions) on an "AS IS" BASIS,
4405+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
4406+
implied, including, without limitation, any warranties or conditions
4407+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
4408+
PARTICULAR PURPOSE. You are solely responsible for determining the
4409+
appropriateness of using or redistributing the Work and assume any
4410+
risks associated with Your exercise of permissions under this License.
4411+
4412+
8. Limitation of Liability. In no event and under no legal theory,
4413+
whether in tort (including negligence), contract, or otherwise,
4414+
unless required by applicable law (such as deliberate and grossly
4415+
negligent acts) or agreed to in writing, shall any Contributor be
4416+
liable to You for damages, including any direct, indirect, special,
4417+
incidental, or consequential damages of any character arising as a
4418+
result of this License or out of the use or inability to use the
4419+
Work (including but not limited to damages for loss of goodwill,
4420+
work stoppage, computer failure or malfunction, or any and all
4421+
other commercial damages or losses), even if such Contributor
4422+
has been advised of the possibility of such damages.
4423+
4424+
9. Accepting Warranty or Additional Liability. While redistributing
4425+
the Work or Derivative Works thereof, You may choose to offer,
4426+
and charge a fee for, acceptance of support, warranty, indemnity,
4427+
or other liability obligations and/or rights consistent with this
4428+
License. However, in accepting such obligations, You may act only
4429+
on Your own behalf and on Your sole responsibility, not on behalf
4430+
of any other Contributor, and only if You agree to indemnify,
4431+
defend, and hold each Contributor harmless for any liability
4432+
incurred by, or claims asserted against, such Contributor by reason
4433+
of your accepting any such warranty or additional liability.
4434+
4435+
END OF TERMS AND CONDITIONS
4436+
42294437
APPENDIX: How to apply the Apache License to your work.
42304438

42314439
To apply the Apache License to your work, attach the following
@@ -6857,7 +7065,7 @@ third_party_libraries:
68577065
same "printed page" as the copyright notice for easier
68587066
identification within third-party archives.
68597067

6860-
Copyright [yyyy] [name of copyright owner]
7068+
Copyright 2025 Datadog, Inc.
68617069

68627070
Licensed under the Apache License, Version 2.0 (the "License");
68637071
you may not use this file except in compliance with the License.

0 commit comments

Comments
 (0)