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

Commit c5a08c5

Browse files
committed
ran lint
1 parent de53154 commit c5a08c5

7 files changed

Lines changed: 74 additions & 47 deletions

File tree

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,12 @@
8686
from google.cloud.bigtable.data.row_filters import CellsRowLimitFilter
8787
from google.cloud.bigtable.data.row_filters import RowFilterChain
8888
from google.cloud.bigtable.data._metrics import BigtableClientSideMetricsController
89-
from google.cloud.bigtable.data._metrics.handlers.gcp_exporter import BigtableMetricsExporter
90-
from google.cloud.bigtable.data._metrics.handlers.gcp_exporter import GoogleCloudMetricsHandler
89+
from google.cloud.bigtable.data._metrics.handlers.gcp_exporter import (
90+
BigtableMetricsExporter,
91+
)
92+
from google.cloud.bigtable.data._metrics.handlers.gcp_exporter import (
93+
GoogleCloudMetricsHandler,
94+
)
9195
from google.cloud.bigtable.data._metrics import OperationType
9296

9397
from google.cloud.bigtable.data._cross_sync import CrossSync

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class GoogleCloudMetricsHandler(OpenTelemetryMetricsHandler):
9999
- throttling_latencies: latency introduced by waiting when there are too many outstanding requests in a bulk operation.
100100
101101
Args:
102-
- exporter: The exporter object used to write metrics to Cloud Montitoring.
102+
- exporter: The exporter object used to write metrics to Cloud Montitoring.
103103
Should correspond 1:1 with a bigtable client, and share auth configuration
104104
- export_interval: The interval (in seconds) at which to export metrics to Cloud Monitoring.
105105
- *args: configuration positional arguments passed down to super class
@@ -112,7 +112,9 @@ def __init__(self, exporter, *args, export_interval=60, **kwargs):
112112
exporter, export_interval_millis=export_interval * 1000
113113
)
114114
# use private meter provider to store instruments and views
115-
self.meter_provider = MeterProvider(metric_readers=[gcp_reader], views=VIEW_LIST)
115+
self.meter_provider = MeterProvider(
116+
metric_readers=[gcp_reader], views=VIEW_LIST
117+
)
116118
otel = _OpenTelemetryInstruments(meter_provider=self.meter_provider)
117119
super().__init__(*args, instruments=otel, **kwargs)
118120

@@ -266,4 +268,4 @@ def force_flush(self, timeout_millis: float = 10_000):
266268
Adapted from CloudMonitoringMetricsExporter
267269
https://github.com/GoogleCloudPlatform/opentelemetry-operations-python/blob/3668dfe7ce3b80dd01f42af72428de957b58b316/opentelemetry-exporter-gcp-monitoring/src/opentelemetry/exporter/cloud_monitoring/__init__.py#L82
268270
"""
269-
return True
271+
return True

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
from google.cloud.bigtable.data._metrics.data_model import CompletedOperationMetric
2828

2929
# conversion factor for converting from nanoseconds to milliseconds
30-
NS_TO_MS= 1e6
30+
NS_TO_MS = 1e6
31+
3132

3233
class _OpenTelemetryInstruments:
3334
"""
@@ -211,15 +212,22 @@ def on_attempt_complete(
211212
is_streaming = str(op.is_streaming)
212213

213214
self.otel.attempt_latencies.record(
214-
attempt.duration_ns / NS_TO_MS, {"streaming": is_streaming, "status": status, **labels}
215+
attempt.duration_ns / NS_TO_MS,
216+
{"streaming": is_streaming, "status": status, **labels},
215217
)
216218
combined_throttling = attempt.grpc_throttling_time_ns / NS_TO_MS
217219
if not op.completed_attempts:
218220
# add flow control latency to first attempt's throttling latency
219-
combined_throttling += (op.flow_throttling_time_ns / NS_TO_MS if op.flow_throttling_time_ns else 0)
221+
combined_throttling += (
222+
op.flow_throttling_time_ns / NS_TO_MS
223+
if op.flow_throttling_time_ns
224+
else 0
225+
)
220226
self.otel.throttling_latencies.record(combined_throttling, labels)
221227
self.otel.application_latencies.record(
222-
(attempt.application_blocking_time_ns + attempt.backoff_before_attempt_ns) / NS_TO_MS, labels
228+
(attempt.application_blocking_time_ns + attempt.backoff_before_attempt_ns)
229+
/ NS_TO_MS,
230+
labels,
223231
)
224232
if attempt.gfe_latency_ns is not None:
225233
self.otel.server_latencies.record(
@@ -229,6 +237,4 @@ def on_attempt_complete(
229237
else:
230238
# gfe headers not attached. Record a connectivity error.
231239
# TODO: this should not be recorded as an error when direct path is enabled
232-
self.otel.connectivity_error_count.add(
233-
1, {"status": status, **labels}
234-
)
240+
self.otel.connectivity_error_count.add(1, {"status": status, **labels})

tests/system/data/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,4 +196,4 @@ def authorized_view_id(
196196
try:
197197
admin_client.table_admin_client.delete_authorized_view(name=new_path)
198198
except exceptions.NotFound:
199-
print(f"View {new_view_id} not found, skipping deletion")
199+
print(f"View {new_view_id} not found, skipping deletion")

tests/system/data/test_metrics_async.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2197,4 +2197,4 @@ async def test_check_and_mutate_row_failure_unauthorized(
21972197
assert (
21982198
attempt.gfe_latency_ns >= 0
21992199
and attempt.gfe_latency_ns < operation.duration_ns
2200-
)
2200+
)

tests/system/data/test_system_async.py

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ def init_table_id(self):
174174
base_id = f"{base_id}-async"
175175
return base_id
176176

177-
178177
def _make_client(self):
179178
project = os.getenv("GOOGLE_CLOUD_PROJECT") or None
180179
return CrossSync.DataClient(project=project)
@@ -1338,7 +1337,7 @@ async def test_execute_metadata_on_empty_response(
13381337
SqlType.Bytes(), SqlType.Int64()
13391338
)
13401339

1341-
@pytest.mark.order('last')
1340+
@pytest.mark.order("last")
13421341
class TestExportedMetrics(SystemTestRunner):
13431342
"""
13441343
Checks to make sure metrics were exported by tests
@@ -1361,36 +1360,42 @@ def time_interval(self, start_timestamp):
13611360
LOOKBACK_MINUTES = os.getenv("LOOKBACK_MINUTES")
13621361
if LOOKBACK_MINUTES is not None:
13631362
print(f"running with LOOKBACK_MINUTES={LOOKBACK_MINUTES}")
1364-
start_timestamp = start_timestamp - datetime.timedelta(minutes=int(LOOKBACK_MINUTES))
1363+
start_timestamp = start_timestamp - datetime.timedelta(
1364+
minutes=int(LOOKBACK_MINUTES)
1365+
)
13651366
return {"start_time": start_timestamp, "end_time": end_time}
13661367

1367-
1368-
@pytest.mark.parametrize("metric,methods", [
1369-
("attempt_latencies", [m.value for m in OperationType]),
1370-
("operation_latencies", [m.value for m in OperationType]),
1371-
("retry_count", [m.value for m in OperationType]),
1372-
("first_response_latencies", [OperationType.READ_ROWS]),
1373-
("server_latencies", [m.value for m in OperationType]),
1374-
("connectivity_error_count", [m.value for m in OperationType]),
1375-
("application_blocking_latencies", [OperationType.READ_ROWS]),
1376-
])
1377-
@retry.Retry(
1378-
predicate=retry.if_exception_type(AssertionError)
1368+
@pytest.mark.parametrize(
1369+
"metric,methods",
1370+
[
1371+
("attempt_latencies", [m.value for m in OperationType]),
1372+
("operation_latencies", [m.value for m in OperationType]),
1373+
("retry_count", [m.value for m in OperationType]),
1374+
("first_response_latencies", [OperationType.READ_ROWS]),
1375+
("server_latencies", [m.value for m in OperationType]),
1376+
("connectivity_error_count", [m.value for m in OperationType]),
1377+
("application_blocking_latencies", [OperationType.READ_ROWS]),
1378+
],
13791379
)
1380-
def test_metric_existence(self, client, table_id, metrics_client, time_interval, metric, methods):
1380+
@retry.Retry(predicate=retry.if_exception_type(AssertionError))
1381+
def test_metric_existence(
1382+
self, client, table_id, metrics_client, time_interval, metric, methods
1383+
):
13811384
"""
13821385
Checks existence of each metric in Cloud Monitoring
13831386
"""
13841387
for m in methods:
13851388
metric_filter = (
1386-
f'metric.type = "bigtable.googleapis.com/client/{metric}" ' +
1387-
f'AND metric.labels.client_name = "python-bigtable/{client._client_version()}" ' +
1388-
f'AND resource.labels.table = "{table_id}" '
1389+
f'metric.type = "bigtable.googleapis.com/client/{metric}" '
1390+
+ f'AND metric.labels.client_name = "python-bigtable/{client._client_version()}" '
1391+
+ f'AND resource.labels.table = "{table_id}" '
1392+
)
1393+
results = list(
1394+
metrics_client.list_time_series(
1395+
name=f"projects/{client.project}",
1396+
filter=metric_filter,
1397+
interval=time_interval,
1398+
view=0,
1399+
)
13891400
)
1390-
results = list(metrics_client.list_time_series(
1391-
name=f"projects/{client.project}",
1392-
filter=metric_filter,
1393-
interval=time_interval,
1394-
view=0,
1395-
))
1396-
assert len(results) > 0, f"No data found for {metric} {m}"
1401+
assert len(results) > 0, f"No data found for {metric} {m}"

tests/unit/data/_async/test_client.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,20 @@ async def test_metrics_exporter_init_shares_arguments(self):
202202
expected_options = client_options.ClientOptions()
203203
expected_options.credentials_file = None
204204
expected_options.quota_project_id = None
205-
with mock.patch("google.cloud.bigtable.data._metrics.handlers.gcp_exporter.BigtableMetricsExporter.__init__", return_value=None) as exporter_mock:
206-
async with self._make_client(project=expected_project, credentials=expected_credentials, client_options=expected_options):
207-
exporter_mock.assert_called_once_with(project_id=expected_project, credentials=expected_credentials, client_options=expected_options)
205+
with mock.patch(
206+
"google.cloud.bigtable.data._metrics.handlers.gcp_exporter.BigtableMetricsExporter.__init__",
207+
return_value=None,
208+
) as exporter_mock:
209+
async with self._make_client(
210+
project=expected_project,
211+
credentials=expected_credentials,
212+
client_options=expected_options,
213+
):
214+
exporter_mock.assert_called_once_with(
215+
project_id=expected_project,
216+
credentials=expected_credentials,
217+
client_options=expected_options,
218+
)
208219

209220
@CrossSync.pytest
210221
async def test_metrics_exporter_init_implicit_project(self):
@@ -1185,9 +1196,7 @@ async def test_ctor(self):
11851196
from google.cloud.bigtable.data._metrics import (
11861197
BigtableClientSideMetricsController,
11871198
)
1188-
from google.cloud.bigtable.data._metrics import (
1189-
GoogleCloudMetricsHandler
1190-
)
1199+
from google.cloud.bigtable.data._metrics import GoogleCloudMetricsHandler
11911200

11921201
expected_table_id = "table-id"
11931202
expected_instance_id = "instance-id"
@@ -1522,7 +1531,8 @@ def _make_one(
15221531
async def test_ctor(self):
15231532
from google.cloud.bigtable.data._helpers import _WarmedInstanceKey
15241533
from google.cloud.bigtable.data._metrics import (
1525-
BigtableClientSideMetricsController, GoogleCloudMetricsHandler
1534+
BigtableClientSideMetricsController,
1535+
GoogleCloudMetricsHandler,
15261536
)
15271537

15281538
expected_table_id = "table-id"

0 commit comments

Comments
 (0)