Skip to content

Commit

Permalink
fixed checks
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-sanche committed Feb 1, 2024
1 parent 00d70db commit 24432c8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
14 changes: 8 additions & 6 deletions google/cloud/bigtable/data/_metrics/data_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,9 @@ def start_attempt(self) -> None:
if self.backoff_generator and len(self.completed_attempts) > 0:
# find the attempt's backoff by sending attempt number to generator
# generator will return the backoff time in seconds, so convert to ms
backoff_ms = self.backoff_generator.send(len(self.completed_attempts) - 1) * 1000
backoff_ms = (
self.backoff_generator.send(len(self.completed_attempts) - 1) * 1000
)
else:
backoff_ms = 0

Expand Down Expand Up @@ -307,14 +309,14 @@ def end_attempt_with_status(self, status: StatusCode | Exception) -> None:
return self._handle_error(
INVALID_STATE_ERROR.format("end_attempt_with_status", self.state)
)

if isinstance(status, Exception):
status = self._exc_to_status(status)
duration_seconds = time.monotonic() - self.active_attempt.start_time.monotonic
new_attempt = CompletedAttemptMetric(
start_time=self.active_attempt.start_time.utc,
first_response_latency_ms=self.active_attempt.first_response_latency_ms,
duration_ms=(time.monotonic() - self.active_attempt.start_time.monotonic) * 1000,
end_status=self._exc_to_status(status)
if isinstance(status, Exception)
else status,
duration_ms=duration_seconds * 1000,
end_status=status,
gfe_latency_ms=self.active_attempt.gfe_latency_ms,
application_blocking_time_ms=self.active_attempt.application_blocking_time_ms,
backoff_before_attempt_ms=self.active_attempt.backoff_before_attempt_ms,
Expand Down
9 changes: 3 additions & 6 deletions tests/unit/data/_metrics/test_data_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,9 @@ def test_add_response_metadata_server_timing_header(
if metric.active_attempt.gfe_latency_ms is None:
assert expected_latency_ms is None
else:
assert (metric.active_attempt.gfe_latency_ms - expected_latency_ms) < 0.0001
assert (
metric.active_attempt.gfe_latency_ms - expected_latency_ms
) < 0.0001
# should remain in ACTIVE_ATTEMPT state after completing
assert metric.state == State.ACTIVE_ATTEMPT
# no errors encountered
Expand Down Expand Up @@ -708,11 +710,6 @@ def test__handle_error(self):
assert logger_mock.warning.call_count == 1
assert logger_mock.warning.call_args[0][0] == expected_message
assert len(logger_mock.warning.call_args[0]) == 1
# otherwise, do nothing
with mock.patch(
"google.cloud.bigtable.data._metrics.data_model.LOGGER", None
):
type(self._make_one(object()))._handle_error(input_message)

@pytest.mark.asyncio
async def test_async_context_manager(self):
Expand Down

0 comments on commit 24432c8

Please sign in to comment.