Provide urllib3 implementation of HTTPClient. #879
Merged
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.
Requirements for Contributing to this repository
What does this PR do?
Adds a third implementation for
HTTPClient
usingurllib3
.Description of the Change
The
datadog-lambda-python
package depends ondatadogpy
for submitting metrics in certain cases. The package is used in AWS Lambda environments where resources are very constrained. There is a hard limit of 250MB for all code plus dependencies. Customers are often hitting this limit and so keeping our package size down is important.One of the largest dependencies of
datadog-lambda-python
is therequests
package and it's dependencies. Removing this dependency would reduce the size of our installed package by roughly 8.5%.This PR offers a new solution to this problem. We know that
urllib3
is installed by default on all python lambda runtime containers, and thus does not count toward the 250MB limit. Switching fromrequests
tourllib3
therefore would allow us to benefit from the 8.5% size reduction.Alternate Designs
Possible Drawbacks
Verification Process
I created a testing python lambda layer using these changes and then removing requests and dependencies. It is deployed to the serverless sandbox as
arn:aws:lambda:sa-east-1:425362996713:layer:Python39-REY:40
.I then created a handler that submits a metric using the
datadogpy
package. It then returns a list of installed packages and which http client class was used.The response shows that
requests
and dependencies --certifi
,idna
,chardet
, andcharset-normalizer
-- are no longer installed. Despite removingurllib3
from our layer, we can see that it is still found in the lambda runtime. Lastly, we see that the newly addedUrllib3Client
is used to submit metrics.The metric explorer shows the custom metric
rey.kittens
has been ingested.Additional Notes
This change will have many additional positive impacts as well. We see a 12% reduction in cold start time for example.
Release Notes
Review checklist (to be filled by reviewers)
changelog/
label attached. If applicable it should have thebackward-incompatible
label attached.do-not-merge/
label attached.kind/
andseverity/
labels attached at least.