-
Notifications
You must be signed in to change notification settings - Fork 106
adlfs user agent #501
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
base: main
Are you sure you want to change the base?
adlfs user agent #501
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. I just had a couple of suggestions.
adlfs/spec.py
Outdated
@@ -2055,21 +2062,26 @@ def connect_client(self): | |||
account_url=self.fs.account_url, | |||
credential=cred, | |||
_location_mode=self.fs.location_mode, | |||
user_agent=self._user_agent, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I missed that we need to set the user_agent
in this class as well as in the file system class when we talked about it offline...
Given that we need to duplicate this logic across classes along with if branch statements, it is probably worth we try to consolidate client creation to module level helper function at this point. To do this, let's:
- Define a top-level
_USER_AGENT
that we can use as the constant for the adlfs user agent. - Define a top-level
_create_aio_blob_service_client()
function that requires anaccount_url
and optional acceptscredential
andlocation_mode
. It will use_USER_AGENT
as part of creating the client - Define a top-level
_create_aio_blob_service_client_from_connection_string()
function that requires just aconnection_string
. It will also set_USER_AGENT
as part of creating the client.
I think in making this refactor it is going to much more manageable adding the user agent in and plumb in more configurations in the future.
adlfs/tests/test_spec.py
Outdated
@@ -2045,3 +2048,15 @@ def test_open_file_x(storage: azure.storage.blob.BlobServiceClient, tmpdir): | |||
with fs.open("data/afile", "xb") as f: | |||
pass | |||
assert fs.cat_file("data/afile") == b"data" | |||
|
|||
|
|||
def test_user_agent(storage: azure.storage.blob.BlobServiceClient, mocker): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be great if we could expand + parameterize this test case to assert user agent being set for:
- Both the file system and file classes
- Both client creation approaches i.e., using
from_connection_string
and using the initializer
I think this is important given the amount of branching logic when it comes to client creation so that there is coverage for the various ways clients are created in adlfs
Added adlfs to the user agent to differentiate between adlfs and azure python sdk usage.
Request headers example:
'x-ms-version': 'REDACTED'
'Accept': 'application/xml'
'User-Agent': 'adlfs/2024.12.0 azsdk-python-storage-blob/12.25.1 Python/3.13.5 (Windows-11-10.0.26100-SP0)'
'x-ms-date': 'REDACTED'
'x-ms-client-request-id': '0fbad80d-5059-11f0-9c34-000d3a6d20b2'
'Authorization': 'REDACTED'