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

Commit 3906ea6

Browse files
committed
Merge branch 'csm_2_instrumentation' into csm_3_handlers
2 parents 8e82647 + 4fd97e1 commit 3906ea6

6 files changed

Lines changed: 43 additions & 4 deletions

File tree

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1736,8 +1736,7 @@ async def close(self):
17361736
"""
17371737
Called to close the Table instance and release any resources held by it.
17381738
"""
1739-
for handler in self._metrics.handlers:
1740-
handler.close()
1739+
self._metrics.close()
17411740
if self._register_instance_future:
17421741
self._register_instance_future.cancel()
17431742
await self.client._remove_instance_registration(self.instance_id, self)

google/cloud/bigtable/data/_metrics/metrics_controller.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,10 @@ def create_operation(
5454
Creates a new operation and registers it with the subscribed handlers.
5555
"""
5656
return ActiveOperationMetric(op_type, **kwargs, handlers=self.handlers)
57+
58+
def close(self):
59+
"""
60+
Close all handlers.
61+
"""
62+
for handler in self.handlers:
63+
handler.close()

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,8 +1463,7 @@ def read_modify_write_row(
14631463

14641464
def close(self):
14651465
"""Called to close the Table instance and release any resources held by it."""
1466-
for handler in self._metrics.handlers:
1467-
handler.close()
1466+
self._metrics.close()
14681467
if self._register_instance_future:
14691468
self._register_instance_future.cancel()
14701469
self.client._remove_instance_registration(self.instance_id, self)

tests/unit/data/_async/test_client.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1500,6 +1500,20 @@ async def test_call_metadata(self, include_app_profile, fn_name, fn_args, gapic_
15001500
# empty app_profile_id should send empty string
15011501
assert "app_profile_id=" in routing_str
15021502

1503+
@CrossSync.pytest
1504+
async def test_close(self):
1505+
client = self._make_client()
1506+
table = self._make_one(client)
1507+
with mock.patch.object(
1508+
table._metrics, "close", mock.Mock()
1509+
) as metric_close_mock:
1510+
with mock.patch.object(
1511+
client, "_remove_instance_registration"
1512+
) as remove_mock:
1513+
await table.close()
1514+
remove_mock.assert_called_once_with(table.instance_id, table)
1515+
metric_close_mock.assert_called_once()
1516+
15031517

15041518
@CrossSync.convert_class(
15051519
"TestAuthorizedView", add_mapping_for_name="TestAuthorizedView"

tests/unit/data/_metrics/test_metrics_controller.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,10 @@ def test_create_operation(self):
8787
assert op.zone is expected_zone
8888
assert len(op.handlers) == 1
8989
assert op.handlers[0] is handler
90+
91+
def test_close(self):
92+
handlers = [mock.Mock() for _ in range(3)]
93+
controller = self._make_one(handlers=handlers)
94+
controller.close()
95+
for handler in handlers:
96+
handler.close.assert_called_once()

tests/unit/data/_sync_autogen/test_client.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,6 +1207,19 @@ def test_call_metadata(self, include_app_profile, fn_name, fn_args, gapic_fn):
12071207
else:
12081208
assert "app_profile_id=" in routing_str
12091209

1210+
def test_close(self):
1211+
client = self._make_client()
1212+
table = self._make_one(client)
1213+
with mock.patch.object(
1214+
table._metrics, "close", mock.Mock()
1215+
) as metric_close_mock:
1216+
with mock.patch.object(
1217+
client, "_remove_instance_registration"
1218+
) as remove_mock:
1219+
table.close()
1220+
remove_mock.assert_called_once_with(table.instance_id, table)
1221+
metric_close_mock.assert_called_once()
1222+
12101223

12111224
@CrossSync._Sync_Impl.add_mapping_decorator("TestAuthorizedView")
12121225
class TestAuthorizedView(CrossSync._Sync_Impl.TestTable):

0 commit comments

Comments
 (0)