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

Commit 019a8c2

Browse files
committed
Merge branch 'csm_interceptor' into csm_1_data_model
2 parents b6eac6c + 00cc52f commit 019a8c2

4 files changed

Lines changed: 26 additions & 17 deletions

File tree

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

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,10 @@
102102
AsyncBigtableMetricsInterceptor as MetricInterceptorType,
103103
)
104104
from google.cloud.bigtable.data._async._swappable_channel import (
105-
AsyncSwappableChannel,
105+
AsyncSwappableChannel as SwappableChannelType,
106+
)
107+
from google.cloud.bigtable.data._async.metrics_interceptor import (
108+
AsyncBigtableMetricsInterceptor as MetricInterceptorType,
106109
)
107110
else:
108111
from typing import Iterable # noqa: F401
@@ -115,9 +118,11 @@
115118
BigtableMetricsInterceptor as MetricInterceptorType,
116119
)
117120
from google.cloud.bigtable.data._sync_autogen._swappable_channel import ( # noqa: F401
118-
SwappableChannel,
121+
SwappableChannel as SwappableChannelType,
122+
)
123+
from google.cloud.bigtable.data._sync_autogen.metrics_interceptor import ( # noqa: F401
124+
BigtableMetricsInterceptor as MetricInterceptorType,
119125
)
120-
121126

122127
if TYPE_CHECKING:
123128
from google.cloud.bigtable.data._helpers import RowKeySamples
@@ -266,12 +271,11 @@ def __init__(
266271
stacklevel=2,
267272
)
268273

269-
@CrossSync.convert(replace_symbols={"AsyncSwappableChannel": "SwappableChannel"})
270-
def _build_grpc_channel(self, *args, **kwargs) -> AsyncSwappableChannel:
274+
def _build_grpc_channel(self, *args, **kwargs) -> SwappableChannelType:
271275
"""
272276
This method is called by the gapic transport to create a grpc channel.
273277
274-
The init arguments passed down are captured in a partial used by AsyncSwappableChannel
278+
The init arguments passed down are captured in a partial used by SwappableChannel
275279
to create new channel instances in the future, as part of the channel refresh logic
276280
277281
Emulators always use an inseucre channel
@@ -296,7 +300,7 @@ def create_channel_fn():
296300
self._metrics_interceptor,
297301
)
298302

299-
new_channel = AsyncSwappableChannel(create_channel_fn)
303+
new_channel = SwappableChannelType(create_channel_fn)
300304
if CrossSync.is_async:
301305
# attach async interceptors
302306
new_channel._unary_unary_interceptors.append(self._metrics_interceptor)
@@ -423,7 +427,7 @@ def _invalidate_channel_stubs(self):
423427
self.transport._stubs = {}
424428
self.transport._prep_wrapped_messages(self.client_info)
425429

426-
@CrossSync.convert(replace_symbols={"AsyncSwappableChannel": "SwappableChannel"})
430+
@CrossSync.convert
427431
async def _manage_channel(
428432
self,
429433
refresh_interval_min: float = 60 * 35,
@@ -448,10 +452,10 @@ async def _manage_channel(
448452
grace_period: time to allow previous channel to serve existing
449453
requests before closing, in seconds
450454
"""
451-
if not isinstance(self.transport.grpc_channel, AsyncSwappableChannel):
455+
if not isinstance(self.transport.grpc_channel, SwappableChannelType):
452456
warnings.warn("Channel does not support auto-refresh.")
453457
return
454-
super_channel: AsyncSwappableChannel = self.transport.grpc_channel
458+
super_channel: SwappableChannelType = self.transport.grpc_channel
455459
first_refresh = self._channel_init_time + random.uniform(
456460
refresh_interval_min, refresh_interval_max
457461
)

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,12 @@
8585
from google.cloud.bigtable.data._sync_autogen.metrics_interceptor import (
8686
BigtableMetricsInterceptor as MetricInterceptorType,
8787
)
88-
from google.cloud.bigtable.data._sync_autogen._swappable_channel import SwappableChannel
88+
from google.cloud.bigtable.data._sync_autogen._swappable_channel import (
89+
SwappableChannel as SwappableChannelType,
90+
)
91+
from google.cloud.bigtable.data._sync_autogen.metrics_interceptor import (
92+
BigtableMetricsInterceptor as MetricInterceptorType,
93+
)
8994

9095
if TYPE_CHECKING:
9196
from google.cloud.bigtable.data._helpers import RowKeySamples
@@ -192,7 +197,7 @@ def __init__(
192197
stacklevel=2,
193198
)
194199

195-
def _build_grpc_channel(self, *args, **kwargs) -> SwappableChannel:
200+
def _build_grpc_channel(self, *args, **kwargs) -> SwappableChannelType:
196201
"""This method is called by the gapic transport to create a grpc channel.
197202
198203
The init arguments passed down are captured in a partial used by SwappableChannel
@@ -216,7 +221,7 @@ def create_channel_fn():
216221
self._metrics_interceptor,
217222
)
218223

219-
new_channel = SwappableChannel(create_channel_fn)
224+
new_channel = SwappableChannelType(create_channel_fn)
220225
return new_channel
221226

222227
@property
@@ -338,10 +343,10 @@ def _manage_channel(
338343
between `refresh_interval_min` and `refresh_interval_max`
339344
grace_period: time to allow previous channel to serve existing
340345
requests before closing, in seconds"""
341-
if not isinstance(self.transport.grpc_channel, SwappableChannel):
346+
if not isinstance(self.transport.grpc_channel, SwappableChannelType):
342347
warnings.warn("Channel does not support auto-refresh.")
343348
return
344-
super_channel: SwappableChannel = self.transport.grpc_channel
349+
super_channel: SwappableChannelType = self.transport.grpc_channel
345350
first_refresh = self._channel_init_time + random.uniform(
346351
refresh_interval_min, refresh_interval_max
347352
)

tests/system/data/test_system_async.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ async def test_channel_refresh(self, table_id, instance_id, temp_rows):
292292
assert len(rows_after_refresh) == 2
293293
assert client.transport.grpc_channel is channel_wrapper
294294
updated_channel = channel_wrapper._channel
295-
assert channel_wrapper._channel is not first_channel
295+
assert updated_channel is not first_channel
296296
# ensure interceptors are kept (gapic's logging interceptor, and metric interceptor)
297297
if CrossSync.is_async:
298298
unary_interceptors = updated_channel._unary_unary_interceptors

tests/system/data/test_system_autogen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ def test_channel_refresh(self, table_id, instance_id, temp_rows):
244244
assert len(rows_after_refresh) == 2
245245
assert client.transport.grpc_channel is channel_wrapper
246246
updated_channel = channel_wrapper._channel
247-
assert channel_wrapper._channel is not first_channel
247+
assert updated_channel is not first_channel
248248
assert isinstance(
249249
client.transport._logged_channel._interceptor, GapicInterceptor
250250
)

0 commit comments

Comments
 (0)