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

Commit 24432c8

Browse files
committed
fixed checks
1 parent 00d70db commit 24432c8

2 files changed

Lines changed: 11 additions & 12 deletions

File tree

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,9 @@ def start_attempt(self) -> None:
209209
if self.backoff_generator and len(self.completed_attempts) > 0:
210210
# find the attempt's backoff by sending attempt number to generator
211211
# generator will return the backoff time in seconds, so convert to ms
212-
backoff_ms = self.backoff_generator.send(len(self.completed_attempts) - 1) * 1000
212+
backoff_ms = (
213+
self.backoff_generator.send(len(self.completed_attempts) - 1) * 1000
214+
)
213215
else:
214216
backoff_ms = 0
215217

@@ -307,14 +309,14 @@ def end_attempt_with_status(self, status: StatusCode | Exception) -> None:
307309
return self._handle_error(
308310
INVALID_STATE_ERROR.format("end_attempt_with_status", self.state)
309311
)
310-
312+
if isinstance(status, Exception):
313+
status = self._exc_to_status(status)
314+
duration_seconds = time.monotonic() - self.active_attempt.start_time.monotonic
311315
new_attempt = CompletedAttemptMetric(
312316
start_time=self.active_attempt.start_time.utc,
313317
first_response_latency_ms=self.active_attempt.first_response_latency_ms,
314-
duration_ms=(time.monotonic() - self.active_attempt.start_time.monotonic) * 1000,
315-
end_status=self._exc_to_status(status)
316-
if isinstance(status, Exception)
317-
else status,
318+
duration_ms=duration_seconds * 1000,
319+
end_status=status,
318320
gfe_latency_ms=self.active_attempt.gfe_latency_ms,
319321
application_blocking_time_ms=self.active_attempt.application_blocking_time_ms,
320322
backoff_before_attempt_ms=self.active_attempt.backoff_before_attempt_ms,

tests/unit/data/_metrics/test_data_model.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,9 @@ def test_add_response_metadata_server_timing_header(
389389
if metric.active_attempt.gfe_latency_ms is None:
390390
assert expected_latency_ms is None
391391
else:
392-
assert (metric.active_attempt.gfe_latency_ms - expected_latency_ms) < 0.0001
392+
assert (
393+
metric.active_attempt.gfe_latency_ms - expected_latency_ms
394+
) < 0.0001
393395
# should remain in ACTIVE_ATTEMPT state after completing
394396
assert metric.state == State.ACTIVE_ATTEMPT
395397
# no errors encountered
@@ -708,11 +710,6 @@ def test__handle_error(self):
708710
assert logger_mock.warning.call_count == 1
709711
assert logger_mock.warning.call_args[0][0] == expected_message
710712
assert len(logger_mock.warning.call_args[0]) == 1
711-
# otherwise, do nothing
712-
with mock.patch(
713-
"google.cloud.bigtable.data._metrics.data_model.LOGGER", None
714-
):
715-
type(self._make_one(object()))._handle_error(input_message)
716713

717714
@pytest.mark.asyncio
718715
async def test_async_context_manager(self):

0 commit comments

Comments
 (0)