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

Commit bc6036e

Browse files
committed
added close to metric spec
1 parent ed9d3cf commit bc6036e

6 files changed

Lines changed: 35 additions & 0 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1685,6 +1685,7 @@ async def close(self):
16851685
"""
16861686
Called to close the Table instance and release any resources held by it.
16871687
"""
1688+
self._metrics.close()
16881689
if self._register_instance_future:
16891690
self._register_instance_future.cancel()
16901691
await self.client._remove_instance_registration(self.instance_id, self)

google/cloud/bigtable/data/_metrics/handlers/_base.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,6 @@ def on_attempt_complete(
3333
self, attempt: CompletedAttemptMetric, op: ActiveOperationMetric
3434
) -> None:
3535
pass
36+
37+
def close(self):
38+
pass

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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,6 +1414,7 @@ def read_modify_write_row(
14141414

14151415
def close(self):
14161416
"""Called to close the Table instance and release any resources held by it."""
1417+
self._metrics.close()
14171418
if self._register_instance_future:
14181419
self._register_instance_future.cancel()
14191420
self.client._remove_instance_registration(self.instance_id, self)

tests/unit/data/_async/test_client.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,6 +1464,16 @@ async def test_call_metadata(self, include_app_profile, fn_name, fn_args, gapic_
14641464
# empty app_profile_id should send empty string
14651465
assert "app_profile_id=" in routing_str
14661466

1467+
@CrossSync.pytest
1468+
async def test_close(self):
1469+
client = self._make_client()
1470+
table = self._make_one(client)
1471+
with mock.patch.object(table._metrics, "close", mock.Mock()) as metric_close_mock:
1472+
with mock.patch.object(client, "_remove_instance_registration") as remove_mock:
1473+
await table.close()
1474+
remove_mock.assert_called_once_with(table.instance_id, table)
1475+
metric_close_mock.assert_called_once()
1476+
14671477

14681478
@CrossSync.convert_class(
14691479
"TestAuthorizedView", add_mapping_for_name="TestAuthorizedView"

tests/unit/data/_sync_autogen/test_client.py

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

1176+
def test_close(self):
1177+
client = self._make_client()
1178+
table = self._make_one(client)
1179+
with mock.patch.object(
1180+
table._metrics, "close", mock.Mock()
1181+
) as metric_close_mock:
1182+
with mock.patch.object(
1183+
client, "_remove_instance_registration"
1184+
) as remove_mock:
1185+
table.close()
1186+
remove_mock.assert_called_once_with(table.instance_id, table)
1187+
metric_close_mock.assert_called_once()
1188+
11761189

11771190
@CrossSync._Sync_Impl.add_mapping_decorator("TestAuthorizedView")
11781191
class TestAuthorizedView(CrossSync._Sync_Impl.TestTable):

0 commit comments

Comments
 (0)