-
Notifications
You must be signed in to change notification settings - Fork 65
feat: initializing the new data client #1238
Changes from 9 commits
406ae29
f1e03e6
abc9b51
ca1b715
e534cc2
0afdbf2
39ae646
7f49237
d173efe
225df82
7a7e8e3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,9 +34,7 @@ | |
| from google.api_core.gapic_v1 import client_info as client_info_lib | ||
| from google.auth.credentials import AnonymousCredentials # type: ignore | ||
|
|
||
| from google.cloud import bigtable_v2 | ||
| from google.cloud.bigtable import admin | ||
| from google.cloud.bigtable_v2.services.bigtable.transports import BigtableGrpcTransport | ||
| from google.cloud.bigtable.admin.services.bigtable_instance_admin.transports import ( | ||
| BigtableInstanceAdminGrpcTransport, | ||
| ) | ||
|
|
@@ -54,6 +52,11 @@ | |
| from google.cloud.bigtable.cluster import _CLUSTER_NAME_RE | ||
| from google.cloud.environment_vars import BIGTABLE_EMULATOR # type: ignore | ||
|
|
||
| from google.cloud.bigtable.data import BigtableDataClient | ||
| from google.cloud.bigtable.data._helpers import ( | ||
| _DEFAULT_BIGTABLE_EMULATOR_CLIENT, | ||
| ) | ||
|
daniel-sanche marked this conversation as resolved.
|
||
|
|
||
|
|
||
| INSTANCE_TYPE_PRODUCTION = instance.Instance.Type.PRODUCTION | ||
| INSTANCE_TYPE_DEVELOPMENT = instance.Instance.Type.DEVELOPMENT | ||
|
|
@@ -66,7 +69,6 @@ | |
| READ_ONLY_SCOPE = "https://www.googleapis.com/auth/bigtable.data.readonly" | ||
| """Scope for reading table data.""" | ||
|
|
||
| _DEFAULT_BIGTABLE_EMULATOR_CLIENT = "google-cloud-bigtable-emulator" | ||
| _GRPC_CHANNEL_OPTIONS = ( | ||
| ("grpc.max_send_message_length", -1), | ||
| ("grpc.max_receive_message_length", -1), | ||
|
|
@@ -290,18 +292,7 @@ def table_data_client(self): | |
| :rtype: :class:`.bigtable_v2.BigtableClient` | ||
| :returns: A BigtableClient object. | ||
| """ | ||
| if self._table_data_client is None: | ||
| transport = self._create_gapic_client_channel( | ||
| bigtable_v2.BigtableClient, | ||
| BigtableGrpcTransport, | ||
| ) | ||
| klass = _create_gapic_client( | ||
| bigtable_v2.BigtableClient, | ||
| client_options=self._client_options, | ||
| transport=transport, | ||
| ) | ||
| self._table_data_client = klass(self) | ||
| return self._table_data_client | ||
| return self._veneer_data_client._gapic_client | ||
|
|
||
| @property | ||
| def table_admin_client(self): | ||
|
|
@@ -369,6 +360,19 @@ def instance_admin_client(self): | |
| self._instance_admin_client = klass(self) | ||
| return self._instance_admin_client | ||
|
|
||
| @property | ||
| def _veneer_data_client(self): | ||
| """Getter for the new Data Table API.""" | ||
| if self._table_data_client is None: | ||
| self._table_data_client = BigtableDataClient( | ||
| project=self.project, | ||
| credentials=self._credentials, | ||
| client_options=self._client_options, | ||
| _client_info=self._client_info, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was thinking we should customize the What do you think? (Maybe ping Mattie?) |
||
| _is_legacy_client=True, | ||
| ) | ||
| return self._table_data_client | ||
|
|
||
| def instance(self, instance_id, display_name=None, instance_type=None, labels=None): | ||
| """Factory to create a instance associated with this client. | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,7 +64,6 @@ | |
| import google.auth.credentials | ||
| import google.auth._default | ||
| from google.api_core import client_options as client_options_lib | ||
| from google.cloud.bigtable.client import _DEFAULT_BIGTABLE_EMULATOR_CLIENT | ||
| from google.cloud.bigtable.data.row import Row | ||
| from google.cloud.bigtable.data.read_rows_query import ReadRowsQuery | ||
| from google.cloud.bigtable.data.exceptions import FailedQueryShardError | ||
|
|
@@ -73,6 +72,7 @@ | |
| from google.cloud.bigtable.data._helpers import TABLE_DEFAULT, _align_timeouts | ||
| from google.cloud.bigtable.data._helpers import _WarmedInstanceKey | ||
| from google.cloud.bigtable.data._helpers import _CONCURRENCY_LIMIT | ||
| from google.cloud.bigtable.data._helpers import _DEFAULT_BIGTABLE_EMULATOR_CLIENT | ||
| from google.cloud.bigtable.data._helpers import _retry_exception_factory | ||
| from google.cloud.bigtable.data._helpers import _validate_timeouts | ||
| from google.cloud.bigtable.data._helpers import _get_error_type | ||
|
|
@@ -184,9 +184,15 @@ def __init__( | |
| """ | ||
| if "pool_size" in kwargs: | ||
| warnings.warn("pool_size no longer supported") | ||
| # set up client info headers for veneer library | ||
| self.client_info = DEFAULT_CLIENT_INFO | ||
|
|
||
| # Private argument, for internal use only | ||
| self._is_legacy_client = bool(kwargs.get("_is_legacy_client", False)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this is just for customizing the client_version/background refresh, I'd prefer to avoid tracking this extra state. We're already passing in a client_info object, so I'd say we should set the value in the legacy client before passing it in, and then do something like: |
||
|
|
||
| # set up client info headers for veneer library. _client_info is for internal use only, | ||
| # for the legacy client shim. | ||
| self.client_info = kwargs.get("_client_info", DEFAULT_CLIENT_INFO) | ||
| self.client_info.client_library_version = self._client_version() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we want to set a different user agent for the shim... We'll probably want to know how many people are using the shim, to tell us when it can be removed Maybe that means we should build our own client_info in the legacy constructor, and only attach this version string if none was passed in? |
||
|
|
||
| # parse client options | ||
| if type(client_options) is dict: | ||
| client_options = client_options_lib.from_dict(client_options) | ||
|
|
@@ -300,12 +306,13 @@ def api_endpoint(self) -> str: | |
| """ | ||
| return self._gapic_client.api_endpoint | ||
|
|
||
| @staticmethod | ||
| def _client_version() -> str: | ||
| def _client_version(self) -> str: | ||
| """ | ||
| Helper function to return the client version string for this client | ||
| """ | ||
| version_str = f"{google.cloud.bigtable.__version__}-data" | ||
| if self._is_legacy_client: | ||
| version_str += "-shim" | ||
| if CrossSync.is_async: | ||
| version_str += "-async" | ||
| return version_str | ||
|
|
@@ -329,6 +336,7 @@ def _start_background_channel_refresh(self) -> None: | |
| not self._channel_refresh_task | ||
| and not self._emulator_host | ||
| and not self._is_closed.is_set() | ||
| and not self._is_legacy_client | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did like the old version, where there was a flag specifically for disabling background refresh. That could be useful for other purposes too, like testing Enabling _is_legacy_client could come with other side-effects |
||
| ): | ||
| # raise error if not in an event loop in async client | ||
| CrossSync.verify_async_event_loop() | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.