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

Commit a70824b

Browse files
committed
fixed lint
1 parent c408e14 commit a70824b

2 files changed

Lines changed: 37 additions & 22 deletions

File tree

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

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -65,20 +65,20 @@ class OperationType(Enum):
6565
class OperationState(Enum):
6666
"""Enum for the state of the active operation.
6767
68-
┌───────────┐
69-
│ CREATED │
70-
└─────┬─────┘
71-
72-
73-
┌▶ ACTIVE_ATTEMPT ───┐
74-
│ │ │
75-
│ ▼ │
76-
└─ BETWEEN_ATTEMPTS │
77-
│ │
78-
▼ ▼
79-
┌───────────┐ │
80-
│ COMPLETED │ ◀─────┘
81-
└───────────┘
68+
┌───────────┐
69+
│ CREATED │
70+
└─────┬─────┘
71+
72+
73+
┌▶ ACTIVE_ATTEMPT ───┐
74+
│ │ │
75+
│ ▼ │
76+
└─ BETWEEN_ATTEMPTS │
77+
│ │
78+
▼ ▼
79+
┌───────────┐ │
80+
│ COMPLETED │ ◀─────┘
81+
└───────────┘
8282
"""
8383

8484
CREATED = 0
@@ -329,7 +329,9 @@ def end_attempt_with_status(self, status: StatusCode | BaseException) -> None:
329329
)
330330
if isinstance(status, BaseException):
331331
status = self._exc_to_status(status)
332-
duration_ns = self._ensure_positive(time.monotonic_ns() - self.active_attempt.start_time_ns, "duration")
332+
duration_ns = self._ensure_positive(
333+
time.monotonic_ns() - self.active_attempt.start_time_ns, "duration"
334+
)
333335
complete_attempt = CompletedAttemptMetric(
334336
duration_ns=duration_ns,
335337
end_status=status,
@@ -365,7 +367,9 @@ def end_with_status(self, status: StatusCode | BaseException) -> None:
365367
)
366368
if self.state == OperationState.ACTIVE_ATTEMPT:
367369
self.end_attempt_with_status(final_status)
368-
duration_ns = self._ensure_positive(time.monotonic_ns() - self.start_time_ns, "duration")
370+
duration_ns = self._ensure_positive(
371+
time.monotonic_ns() - self.start_time_ns, "duration"
372+
)
369373
finalized = CompletedOperationMetric(
370374
op_type=self.op_type,
371375
completed_attempts=self.completed_attempts,
@@ -430,7 +434,7 @@ def _handle_error(message: str) -> None:
430434
full_message = f"Error in Bigtable Metrics: {message}"
431435
LOGGER.warning(full_message)
432436

433-
def _ensure_positive(self, value:int, field_name:str) -> int:
437+
def _ensure_positive(self, value: int, field_name: str) -> int:
434438
"""
435439
Helper to replace negative value with 0, and record an error
436440
"""

tests/unit/data/_metrics/test_data_model.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,10 @@ def test_add_response_metadata_cbt_header(
271271
cls = type(self._make_one(mock.Mock()))
272272
with mock.patch.object(cls, "_handle_error") as mock_handle_error:
273273
metric = self._make_one(
274-
mock.Mock(), cluster_id=start_cluster, zone=start_zone, state=State.ACTIVE_ATTEMPT
274+
mock.Mock(),
275+
cluster_id=start_cluster,
276+
zone=start_zone,
277+
state=State.ACTIVE_ATTEMPT,
275278
)
276279
metric.active_attempt = mock.Mock()
277280
metric.active_attempt.gfe_latency_ns = None
@@ -391,7 +394,6 @@ def test_end_attempt_with_status(self, mock_monotonic_ns):
391394
expected_gfe_latency_ns = 5
392395
expected_app_blocking = 12
393396
expected_backoff = 2
394-
expected_grpc_throttle = 3
395397
handlers = [mock.Mock(), mock.Mock()]
396398

397399
metric = self._make_one(mock.Mock(), handlers=handlers)
@@ -450,7 +452,10 @@ def test_end_attempt_with_negative_duration_ns(self, mock_monotonic_ns):
450452
metric.end_attempt_with_status(mock.Mock())
451453

452454
assert mock_handle_error.call_count == 1
453-
assert "received negative value for duration" in mock_handle_error.call_args[0][0]
455+
assert (
456+
"received negative value for duration"
457+
in mock_handle_error.call_args[0][0]
458+
)
454459
assert metric.completed_attempts[0].duration_ns == 0
455460

456461
@mock.patch("time.monotonic_ns")
@@ -479,7 +484,10 @@ def test_end_with_status(self, mock_monotonic_ns):
479484

480485
handlers = [mock.Mock(), mock.Mock()]
481486
metric = self._make_one(
482-
expected_type, handlers=handlers, start_time_ns=expected_start_time, state=State.ACTIVE_ATTEMPT
487+
expected_type,
488+
handlers=handlers,
489+
start_time_ns=expected_start_time,
490+
state=State.ACTIVE_ATTEMPT,
483491
)
484492
metric.cluster_id = expected_cluster
485493
metric.zone = expected_zone
@@ -534,7 +542,10 @@ def test_end_with_negative_duration_ns(self, mock_monotonic_ns):
534542
metric.end_with_status(mock.Mock())
535543

536544
assert mock_handle_error.call_count == 1
537-
assert "received negative value for duration" in mock_handle_error.call_args[0][0]
545+
assert (
546+
"received negative value for duration"
547+
in mock_handle_error.call_args[0][0]
548+
)
538549
final_op = metric.handlers[0].on_operation_complete.call_args[0][0]
539550
assert final_op.duration_ns == 0
540551

0 commit comments

Comments
 (0)