From c6bc4213a663dab55a75bc999dbc5c00c36d781b Mon Sep 17 00:00:00 2001 From: Ashley Xu Date: Tue, 24 Oct 2023 19:06:00 +0000 Subject: [PATCH 1/3] feat: populate ibis version in user agent --- bigframes/session/clients.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/bigframes/session/clients.py b/bigframes/session/clients.py index 544f74265f..f2e5a08931 100644 --- a/bigframes/session/clients.py +++ b/bigframes/session/clients.py @@ -28,6 +28,7 @@ import google.cloud.bigquery_storage_v1 import google.cloud.functions_v2 import google.cloud.resourcemanager_v3 +import ibis import pydata_google_auth import bigframes.version @@ -49,6 +50,18 @@ def _get_default_credentials_with_project(): return pydata_google_auth.default(scopes=_SCOPES, use_local_webserver=False) +def _create_user_agent(application_name: str) -> str: + user_agent = [] + + if application_name: + user_agent.append(application_name) + + user_agent_default_template = f"ibis/{ibis.__version__}" + user_agent.append(user_agent_default_template) + + return " ".join(user_agent) + + class ClientsProvider: """Provides client instances necessary to perform cloud operations.""" @@ -108,7 +121,7 @@ def bqclient(self): ), ) bq_info = google.api_core.client_info.ClientInfo( - user_agent=self._application_name + user_agent=_create_user_agent(self._application_name) ) self._bqclient = bigquery.Client( client_info=bq_info, @@ -131,7 +144,7 @@ def bqconnectionclient(self): ) ) bqconnection_info = google.api_core.gapic_v1.client_info.ClientInfo( - user_agent=self._application_name + user_agent=_create_user_agent(self._application_name) ) self._bqconnectionclient = ( google.cloud.bigquery_connection_v1.ConnectionServiceClient( @@ -154,7 +167,7 @@ def bqstoragereadclient(self): ) ) bqstorage_info = google.api_core.gapic_v1.client_info.ClientInfo( - user_agent=self._application_name + user_agent=_create_user_agent(self._application_name) ) self._bqstoragereadclient = ( google.cloud.bigquery_storage_v1.BigQueryReadClient( @@ -170,7 +183,7 @@ def bqstoragereadclient(self): def cloudfunctionsclient(self): if not self._cloudfunctionsclient: functions_info = google.api_core.gapic_v1.client_info.ClientInfo( - user_agent=self._application_name + user_agent=_create_user_agent(self._application_name) ) self._cloudfunctionsclient = ( google.cloud.functions_v2.FunctionServiceClient( @@ -185,7 +198,7 @@ def cloudfunctionsclient(self): def resourcemanagerclient(self): if not self._resourcemanagerclient: resourcemanager_info = google.api_core.gapic_v1.client_info.ClientInfo( - user_agent=self._application_name + user_agent=_create_user_agent(self._application_name) ) self._resourcemanagerclient = ( google.cloud.resourcemanager_v3.ProjectsClient( From 0d81f03ab6db9fa874a5395cc3b4eb846af1b803 Mon Sep 17 00:00:00 2001 From: Ashley Xu Date: Thu, 26 Oct 2023 16:07:13 +0000 Subject: [PATCH 2/3] fix: address comments --- bigframes/session/clients.py | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/bigframes/session/clients.py b/bigframes/session/clients.py index f2e5a08931..caa0ecb8b3 100644 --- a/bigframes/session/clients.py +++ b/bigframes/session/clients.py @@ -34,7 +34,7 @@ import bigframes.version _ENV_DEFAULT_PROJECT = "GOOGLE_CLOUD_PROJECT" -_APPLICATION_NAME = f"bigframes/{bigframes.version.__version__}" +_APPLICATION_NAME = f"bigframes/{bigframes.version.__version__}/ibis/{ibis.__version__}" _SCOPES = ["https://www.googleapis.com/auth/cloud-platform"] # BigQuery is a REST API, which requires the protocol as part of the URL. @@ -50,18 +50,6 @@ def _get_default_credentials_with_project(): return pydata_google_auth.default(scopes=_SCOPES, use_local_webserver=False) -def _create_user_agent(application_name: str) -> str: - user_agent = [] - - if application_name: - user_agent.append(application_name) - - user_agent_default_template = f"ibis/{ibis.__version__}" - user_agent.append(user_agent_default_template) - - return " ".join(user_agent) - - class ClientsProvider: """Provides client instances necessary to perform cloud operations.""" @@ -121,7 +109,7 @@ def bqclient(self): ), ) bq_info = google.api_core.client_info.ClientInfo( - user_agent=_create_user_agent(self._application_name) + user_agent=self._application_name ) self._bqclient = bigquery.Client( client_info=bq_info, @@ -144,7 +132,7 @@ def bqconnectionclient(self): ) ) bqconnection_info = google.api_core.gapic_v1.client_info.ClientInfo( - user_agent=_create_user_agent(self._application_name) + user_agent=self._application_name ) self._bqconnectionclient = ( google.cloud.bigquery_connection_v1.ConnectionServiceClient( @@ -167,7 +155,7 @@ def bqstoragereadclient(self): ) ) bqstorage_info = google.api_core.gapic_v1.client_info.ClientInfo( - user_agent=_create_user_agent(self._application_name) + user_agent=self._application_name ) self._bqstoragereadclient = ( google.cloud.bigquery_storage_v1.BigQueryReadClient( @@ -183,7 +171,7 @@ def bqstoragereadclient(self): def cloudfunctionsclient(self): if not self._cloudfunctionsclient: functions_info = google.api_core.gapic_v1.client_info.ClientInfo( - user_agent=_create_user_agent(self._application_name) + user_agent=self._application_name ) self._cloudfunctionsclient = ( google.cloud.functions_v2.FunctionServiceClient( @@ -198,7 +186,7 @@ def cloudfunctionsclient(self): def resourcemanagerclient(self): if not self._resourcemanagerclient: resourcemanager_info = google.api_core.gapic_v1.client_info.ClientInfo( - user_agent=_create_user_agent(self._application_name) + user_agent=self._application_name ) self._resourcemanagerclient = ( google.cloud.resourcemanager_v3.ProjectsClient( From 1f83e9ad4df1a14540d5e047e627ec707f8f8730 Mon Sep 17 00:00:00 2001 From: Ashley Xu <139821907+ashleyxuu@users.noreply.github.com> Date: Thu, 26 Oct 2023 11:04:30 -0700 Subject: [PATCH 3/3] Update bigframes/session/clients.py Co-authored-by: Tim Swast --- bigframes/session/clients.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bigframes/session/clients.py b/bigframes/session/clients.py index caa0ecb8b3..e33413002f 100644 --- a/bigframes/session/clients.py +++ b/bigframes/session/clients.py @@ -34,7 +34,7 @@ import bigframes.version _ENV_DEFAULT_PROJECT = "GOOGLE_CLOUD_PROJECT" -_APPLICATION_NAME = f"bigframes/{bigframes.version.__version__}/ibis/{ibis.__version__}" +_APPLICATION_NAME = f"bigframes/{bigframes.version.__version__} ibis/{ibis.__version__}" _SCOPES = ["https://www.googleapis.com/auth/cloud-platform"] # BigQuery is a REST API, which requires the protocol as part of the URL.