[Python] Set a Beam user agent on the boto3 S3 client - #39574
Draft
goanpeca wants to merge 1 commit into
Draft
Conversation
Contributor
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Addresses #39573
apache_beam.io.aws.clients.s3.boto3_client.Clientbuilds its boto3 client without a botocoreConfig, so every S3 request Beam makes goes out with the stock boto3 user agent and carries nothing identifying the caller as Beam. The other cloud clients in the Python SDK all tag themselves already:gcsio.pysendsapache-beam/<version> (GPN:Beam),bigquery_tools.pysendsapache-beam-<version>, and the Datastore helper sendsbeam-python-sdk/<version>. The S3 client is the odd one out.This passes
Config(user_agent_extra='apache-beam/%s' % beam_version.__version__)when constructing the client. botocore appendsuser_agent_extrato the end of the composed user agent, so the boto3, botocore, platform, and language segments are all preserved and only a suffix is added. The version comes fromapache_beam.version.__version__, the same sourcegcsio.pyuses. The practical benefit is that Beam's S3 traffic becomes identifiable in server access logs, which helps when diagnosing throttling or endpoint problems against Amazon S3 and against any other S3-compatible endpoint reached through--s3_endpoint_url.Tests: a new
ClientUserAgentTestinclient_test.pyconstructs the client from a defaultS3Options()and asserts the composedclient.client.meta.config.user_agentcontainsapache-beam/<version>. It is guarded with@unittest.skipIf(boto3_client is None, ...)following the pattern already used ins3filesystem_test.py, and client construction needs no credentials and no region, so it runs offline. yapf and ruff are clean on both files.Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, commentfixes #<ISSUE NUMBER>instead.CHANGES.mdwith noteworthy changes.See the Contributor Guide for more tips on how to make review process smoother.