Skip to content
This repository was archived by the owner on Apr 1, 2026. It is now read-only.

Commit 0afdbf2

Browse files
committed
Added app_profile_id, legacy client shim version, and renamed
_data_client
1 parent e534cc2 commit 0afdbf2

8 files changed

Lines changed: 109 additions & 71 deletions

File tree

google/cloud/bigtable/client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ def table_data_client(self):
292292
:rtype: :class:`.bigtable_v2.BigtableClient`
293293
:returns: A BigtableClient object.
294294
"""
295-
return self._data_client._gapic_client
295+
return self._veneer_data_client._gapic_client
296296

297297
@property
298298
def table_admin_client(self):
@@ -361,15 +361,15 @@ def instance_admin_client(self):
361361
return self._instance_admin_client
362362

363363
@property
364-
def _data_client(self):
364+
def _veneer_data_client(self):
365365
"""Getter for the new Data Table API."""
366366
if self._table_data_client is None:
367367
self._table_data_client = BigtableDataClient(
368368
project=self.project,
369369
credentials=self._credentials,
370370
client_options=self._client_options,
371371
_client_info=self._client_info,
372-
_disable_background_channel_refresh=True,
372+
_is_legacy_client=True,
373373
)
374374
return self._table_data_client
375375

google/cloud/bigtable/data/_async/client.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,16 @@ def __init__(
184184
"""
185185
if "pool_size" in kwargs:
186186
warnings.warn("pool_size no longer supported")
187-
if "_client_info" in kwargs:
188-
# use client_info passed in from legacy client. For internal use only, for the legacy
189-
# client shim.
190-
self.client_info = kwargs["_client_info"]
191-
else:
192-
# set up client info headers for veneer library.
193-
self.client_info = kwargs.get("_client_info", DEFAULT_CLIENT_INFO)
194-
self.client_info.client_library_version = self._client_version()
187+
188+
# Private argument, for internal use only
189+
self._is_legacy_client = bool(
190+
kwargs.get("_is_legacy_client", False)
191+
)
192+
193+
# set up client info headers for veneer library. _client_info is for internal use only,
194+
# for the legacy client shim.
195+
self.client_info = kwargs.get("_client_info", DEFAULT_CLIENT_INFO)
196+
self.client_info.client_library_version = self._client_version()
195197

196198
# parse client options
197199
if type(client_options) is dict:
@@ -242,10 +244,6 @@ def __init__(
242244
"is the default."
243245
)
244246
self._is_closed = CrossSync.Event()
245-
# Private argument, for internal use only
246-
self._disable_background_channel_refresh = bool(
247-
kwargs.get("_disable_background_channel_refresh", False)
248-
)
249247
self.transport = cast(TransportType, self._gapic_client.transport)
250248
# keep track of active instances to for warmup on channel refresh
251249
self._active_instances: Set[_WarmedInstanceKey] = set()
@@ -310,12 +308,13 @@ def api_endpoint(self) -> str:
310308
"""
311309
return self._gapic_client.api_endpoint
312310

313-
@staticmethod
314-
def _client_version() -> str:
311+
def _client_version(self) -> str:
315312
"""
316313
Helper function to return the client version string for this client
317314
"""
318315
version_str = f"{google.cloud.bigtable.__version__}-data"
316+
if self._is_legacy_client:
317+
version_str += "-shim"
319318
if CrossSync.is_async:
320319
version_str += "-async"
321320
return version_str
@@ -339,7 +338,7 @@ def _start_background_channel_refresh(self) -> None:
339338
not self._channel_refresh_task
340339
and not self._emulator_host
341340
and not self._is_closed.is_set()
342-
and not self._disable_background_channel_refresh
341+
and not self._is_legacy_client
343342
):
344343
# raise error if not in an event loop in async client
345344
CrossSync.verify_async_event_loop()

google/cloud/bigtable/data/_sync_autogen/client.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,9 @@ def __init__(
127127
"""
128128
if "pool_size" in kwargs:
129129
warnings.warn("pool_size no longer supported")
130-
if "_client_info" in kwargs:
131-
self.client_info = kwargs["_client_info"]
132-
else:
133-
self.client_info = kwargs.get("_client_info", DEFAULT_CLIENT_INFO)
134-
self.client_info.client_library_version = self._client_version()
130+
self._is_legacy_client = bool(kwargs.get("_is_legacy_client", False))
131+
self.client_info = kwargs.get("_client_info", DEFAULT_CLIENT_INFO)
132+
self.client_info.client_library_version = self._client_version()
135133
if type(client_options) is dict:
136134
client_options = client_options_lib.from_dict(client_options)
137135
client_options = cast(
@@ -171,9 +169,6 @@ def __init__(
171169
f"The configured universe domain ({self.universe_domain}) does not match the universe domain found in the credentials ({self._credentials.universe_domain}). If you haven't configured the universe domain explicitly, `googleapis.com` is the default."
172170
)
173171
self._is_closed = CrossSync._Sync_Impl.Event()
174-
self._disable_background_channel_refresh = bool(
175-
kwargs.get("_disable_background_channel_refresh", False)
176-
)
177172
self.transport = cast(TransportType, self._gapic_client.transport)
178173
self._active_instances: Set[_WarmedInstanceKey] = set()
179174
self._instance_owners: dict[_WarmedInstanceKey, Set[int]] = {}
@@ -229,10 +224,11 @@ def api_endpoint(self) -> str:
229224
str: The API endpoint used by the client instance."""
230225
return self._gapic_client.api_endpoint
231226

232-
@staticmethod
233-
def _client_version() -> str:
227+
def _client_version(self) -> str:
234228
"""Helper function to return the client version string for this client"""
235229
version_str = f"{google.cloud.bigtable.__version__}-data"
230+
if self._is_legacy_client:
231+
version_str += "-shim"
236232
return version_str
237233

238234
def _start_background_channel_refresh(self) -> None:
@@ -244,7 +240,7 @@ def _start_background_channel_refresh(self) -> None:
244240
not self._channel_refresh_task
245241
and (not self._emulator_host)
246242
and (not self._is_closed.is_set())
247-
and (not self._disable_background_channel_refresh)
243+
and (not self._is_legacy_client)
248244
):
249245
CrossSync._Sync_Impl.verify_async_event_loop()
250246
self._channel_refresh_task = CrossSync._Sync_Impl.create_task(

google/cloud/bigtable/table.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,13 @@ def __init__(self, table_id, instance, mutation_timeout=None, app_profile_id=Non
132132
self._app_profile_id = app_profile_id
133133
self.mutation_timeout = mutation_timeout
134134

135+
# TODO: Figure out which value to use for mutation_timeout after looking at how
136+
# mutation_timeout is used in this class.
135137
self._table_impl = (
136-
self._instance._client._data_client.get_table(
138+
self._instance._client._veneer_data_client.get_table(
137139
self._instance.instance_id,
138140
self.table_id,
141+
app_profile_id=app_profile_id,
139142
)
140143
if self._instance
141144
else None

tests/unit/data/_async/test_client.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ async def test_ctor(self):
119119
@CrossSync.pytest
120120
async def test_ctor_super_inits(self):
121121
from google.cloud.client import ClientWithProject
122+
from google.cloud.bigtable import __version__ as bigtable_version
122123
from google.api_core import client_options as client_options_lib
123124
from google.cloud.bigtable_v2.services.bigtable.transports.base import (
124125
DEFAULT_CLIENT_INFO,
@@ -155,7 +156,9 @@ async def test_ctor_super_inits(self):
155156

156157
expected_client_info = copy.copy(DEFAULT_CLIENT_INFO)
157158
expected_client_info.client_library_version = (
158-
CrossSync.DataClient._client_version()
159+
f"{bigtable_version}-data"
160+
if not CrossSync.is_async
161+
else f"{bigtable_version}-data-async"
159162
)
160163
assert (
161164
kwargs["client_info"].to_user_agent()
@@ -174,9 +177,11 @@ async def test_ctor_super_inits(self):
174177
assert kwargs["client_options"] == options_parsed
175178

176179
@CrossSync.pytest
177-
async def test_ctor_client_info(self):
180+
async def test_ctor_legacy_client(self):
178181
from google.api_core import client_options as client_options_lib
179182
from google.api_core.gapic_v1.client_info import ClientInfo
183+
from google.cloud.bigtable import __version__ as bigtable_version
184+
import copy
180185

181186
project = "project-id"
182187
credentials = AnonymousCredentials()
@@ -193,6 +198,7 @@ async def test_ctor_client_info(self):
193198
client_options=options_parsed,
194199
use_emulator=False,
195200
_client_info=client_info,
201+
_is_legacy_client=True,
196202
)
197203
except TypeError:
198204
pass
@@ -203,7 +209,20 @@ async def test_ctor_client_info(self):
203209
assert kwargs["credentials"] == credentials
204210
assert kwargs["client_options"] == options_parsed
205211

206-
kwargs["client_info"] == client_info
212+
expected_client_info = copy.copy(client_info)
213+
expected_client_info.client_library_version = (
214+
f"{bigtable_version}-data-shim"
215+
if not CrossSync.is_async
216+
else f"{bigtable_version}-data-shim-async"
217+
)
218+
assert (
219+
kwargs["client_info"].to_user_agent()
220+
== expected_client_info.to_user_agent()
221+
)
222+
assert (
223+
kwargs["client_info"].to_grpc_metadata()
224+
== expected_client_info.to_grpc_metadata()
225+
)
207226

208227
@CrossSync.pytest
209228
async def test_ctor_dict_options(self):
@@ -297,10 +316,10 @@ async def test__start_background_channel_refresh(self):
297316
await client.close()
298317

299318
@CrossSync.pytest
300-
async def test__start_background_channel_refresh_disable_refresh(self):
319+
async def test__start_background_channel_refresh_legacy_client(self):
301320
client = self._make_client(
302321
project="project-id",
303-
_disable_background_channel_refresh=True,
322+
_is_legacy_client=True,
304323
)
305324
# should create background tasks for each channel
306325
with mock.patch.object(

tests/unit/data/_sync_autogen/test_client.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ def test_ctor(self):
8989

9090
def test_ctor_super_inits(self):
9191
from google.cloud.client import ClientWithProject
92+
from google.cloud.bigtable import __version__ as bigtable_version
9293
from google.api_core import client_options as client_options_lib
9394
from google.cloud.bigtable_v2.services.bigtable.transports.base import (
9495
DEFAULT_CLIENT_INFO,
@@ -122,7 +123,9 @@ def test_ctor_super_inits(self):
122123
assert kwargs["client_options"] == options_parsed
123124
expected_client_info = copy.copy(DEFAULT_CLIENT_INFO)
124125
expected_client_info.client_library_version = (
125-
CrossSync._Sync_Impl.DataClient._client_version()
126+
f"{bigtable_version}-data"
127+
if not CrossSync._Sync_Impl.is_async
128+
else f"{bigtable_version}-data-async"
126129
)
127130
assert (
128131
kwargs["client_info"].to_user_agent()
@@ -138,9 +141,11 @@ def test_ctor_super_inits(self):
138141
assert kwargs["credentials"] == credentials
139142
assert kwargs["client_options"] == options_parsed
140143

141-
def test_ctor_client_info(self):
144+
def test_ctor_legacy_client(self):
142145
from google.api_core import client_options as client_options_lib
143146
from google.api_core.gapic_v1.client_info import ClientInfo
147+
from google.cloud.bigtable import __version__ as bigtable_version
148+
import copy
144149

145150
project = "project-id"
146151
credentials = AnonymousCredentials()
@@ -157,14 +162,28 @@ def test_ctor_client_info(self):
157162
client_options=options_parsed,
158163
use_emulator=False,
159164
_client_info=client_info,
165+
_is_legacy_client=True,
160166
)
161167
except TypeError:
162168
pass
163169
assert bigtable_client_init.call_count == 1
164170
kwargs = bigtable_client_init.call_args[1]
165171
assert kwargs["credentials"] == credentials
166172
assert kwargs["client_options"] == options_parsed
167-
kwargs["client_info"] == client_info
173+
expected_client_info = copy.copy(client_info)
174+
expected_client_info.client_library_version = (
175+
f"{bigtable_version}-data-shim"
176+
if not CrossSync._Sync_Impl.is_async
177+
else f"{bigtable_version}-data-shim-async"
178+
)
179+
assert (
180+
kwargs["client_info"].to_user_agent()
181+
== expected_client_info.to_user_agent()
182+
)
183+
assert (
184+
kwargs["client_info"].to_grpc_metadata()
185+
== expected_client_info.to_grpc_metadata()
186+
)
168187

169188
def test_ctor_dict_options(self):
170189
from google.api_core.client_options import ClientOptions
@@ -238,10 +257,8 @@ def test__start_background_channel_refresh(self):
238257
assert ping_and_warm.call_count == 1
239258
client.close()
240259

241-
def test__start_background_channel_refresh_disable_refresh(self):
242-
client = self._make_client(
243-
project="project-id", _disable_background_channel_refresh=True
244-
)
260+
def test__start_background_channel_refresh_legacy_client(self):
261+
client = self._make_client(project="project-id", _is_legacy_client=True)
245262
with mock.patch.object(
246263
client, "_ping_and_warm_instances", CrossSync._Sync_Impl.Mock()
247264
) as ping_and_warm:

tests/unit/v2_client/test_client.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -397,29 +397,29 @@ def test_client_data_client_not_initialized():
397397
credentials = _make_credentials()
398398
client = _make_client(project=PROJECT, credentials=credentials)
399399

400-
data_client = client._data_client
401-
assert isinstance(data_client, BigtableDataClient)
402-
assert client._data_client is data_client
403-
assert client._data_client._disable_background_channel_refresh
400+
veneer_data_client = client._veneer_data_client
401+
assert isinstance(veneer_data_client, BigtableDataClient)
402+
assert client._veneer_data_client is veneer_data_client
403+
assert client._veneer_data_client._is_legacy_client
404404

405405

406-
def test_client_data_client_not_initialized_w_client_info():
406+
def test_client_veneer_data_client_not_initialized_w_client_info():
407407
from google.api_core.gapic_v1.client_info import ClientInfo
408408

409409
credentials = _make_credentials()
410410
client_info = ClientInfo(gapic_version="1.2.3", user_agent="test-client-")
411411
client = _make_client(
412412
project=PROJECT, credentials=credentials, client_info=client_info
413413
)
414-
data_client = client._data_client
414+
data_client = client._veneer_data_client
415415

416416
assert client._client_info is client_info
417-
assert client._data_client is data_client
418-
assert client._data_client.client_info is client_info
419-
assert client._data_client._disable_background_channel_refresh
417+
assert client._veneer_data_client is data_client
418+
assert client._veneer_data_client.client_info is client_info
419+
assert client._veneer_data_client._is_legacy_client
420420

421421

422-
def test_client_data_client_not_initialized_w_client_options():
422+
def test_client_veneer_data_client_not_initialized_w_client_options():
423423
from google.api_core.client_options import ClientOptions
424424

425425
credentials = _make_credentials()
@@ -428,18 +428,18 @@ def test_client_data_client_not_initialized_w_client_options():
428428
project=PROJECT, credentials=credentials, client_options=client_options
429429
)
430430

431-
data_client = client._data_client
432-
assert client._data_client is data_client
433-
assert client._data_client._disable_background_channel_refresh
434-
assert client._data_client._gapic_client._client_options == client_options
431+
data_client = client._veneer_data_client
432+
assert client._veneer_data_client is data_client
433+
assert client._veneer_data_client._is_legacy_client
434+
assert client._veneer_data_client._gapic_client._client_options == client_options
435435

436436

437-
def test_client_data_client_initialized():
437+
def test_client_veneer_data_client_initialized():
438438
credentials = _make_credentials()
439439
client = _make_client(project=PROJECT, credentials=credentials, admin=True)
440440

441441
already = client._table_data_client = object()
442-
assert client._data_client is already
442+
assert client._veneer_data_client is already
443443

444444

445445
def test_client_data_gapic_client_not_initialized():

0 commit comments

Comments
 (0)