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

Commit 2c8506d

Browse files
committed
removed exception flag
1 parent 619d982 commit 2c8506d

2 files changed

Lines changed: 15 additions & 41 deletions

File tree

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

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@
3535
from google.cloud.bigtable.data._metrics.handlers._base import MetricsHandler
3636

3737

38-
# by default, exceptions in the metrics system are logged,
39-
# but enabling this flag causes them to be raised instead
40-
ALLOW_METRIC_EXCEPTIONS = os.getenv("BIGTABLE_METRICS_EXCEPTIONS", False)
4138
LOGGER = logging.getLogger(__name__)
4239

4340
# default values for zone and cluster data, if not captured
@@ -183,8 +180,7 @@ def start(self) -> None:
183180
Optionally called to mark the start of the operation. If not called,
184181
the operation will be started at initialization.
185182
186-
If the operation was completed or has active attempts, will raise an
187-
exception or warning based on the value of ALLOW_METRIC_EXCEPTIONS.
183+
Assunes operation is in CREATED state.
188184
"""
189185
if self.state != OperationState.CREATED:
190186
return self._handle_error(INVALID_STATE_ERROR.format("start", self.state))
@@ -194,8 +190,7 @@ def start_attempt(self) -> None:
194190
"""
195191
Called to initiate a new attempt for the operation.
196192
197-
If the operation was completed or there is already an active attempt,
198-
will raise an exception or warning based on the value of ALLOW_METRIC_EXCEPTIONS.
193+
Assumes operation is in either CREATED or BETWEEN_ATTEMPTS states
199194
"""
200195
if (
201196
self.state != OperationState.BETWEEN_ATTEMPTS
@@ -223,8 +218,7 @@ def add_response_metadata(self, metadata: dict[str, bytes | str]) -> None:
223218
224219
If not called, default values for the metadata will be used.
225220
226-
If the operation was completed or there is no active attempt,
227-
will raise an exception or warning based on the value of ALLOW_METRIC_EXCEPTIONS.
221+
Assumes operation is in ACTIVE_ATTEMPT state.
228222
229223
Args:
230224
- metadata: the metadata as extracted from the grpc call
@@ -280,9 +274,7 @@ def attempt_first_response(self) -> None:
280274
Called to mark the timestamp of the first completed response for the
281275
active attempt.
282276
283-
If the operation was completed, there is no active attempt, or the
284-
active attempt already has a first response time, will raise an
285-
exception or warning based on the value of ALLOW_METRIC_EXCEPTIONS.
277+
Assumes operation is in ACTIVE_ATTEMPT state.
286278
"""
287279
if self.state != OperationState.ACTIVE_ATTEMPT or self.active_attempt is None:
288280
return self._handle_error(
@@ -299,8 +291,7 @@ def end_attempt_with_status(self, status: StatusCode | Exception) -> None:
299291
"""
300292
Called to mark the end of a failed attempt for the operation.
301293
302-
If the operation was completed or there is no active attempt,
303-
will raise an exception or warning based on the value of ALLOW_METRIC_EXCEPTIONS.
294+
Assumes operation is in ACTIVE_ATTEMPT state.
304295
305296
Args:
306297
- status: The status of the attempt.
@@ -332,8 +323,7 @@ def end_with_status(self, status: StatusCode | Exception) -> None:
332323
Called to mark the end of the operation. If there is an active attempt,
333324
end_attempt_with_status will be called with the same status.
334325
335-
If the operation was already completed, will raise an exception or
336-
warning based on the value of ALLOW_METRIC_EXCEPTIONS.
326+
Assumes operation is not already in COMPLETED state.
337327
338328
Causes on_operation_completed to be called for each registered handler.
339329
@@ -368,8 +358,7 @@ def end_with_success(self):
368358
"""
369359
Called to mark the end of the operation with a successful status.
370360
371-
If the operation was already completed, will raise an exception or
372-
warning based on the value of ALLOW_METRIC_EXCEPTIONS.
361+
Assumes operation is not already in COMPLETED state.
373362
374363
Causes on_operation_completed to be called for each registered handler.
375364
"""
@@ -425,14 +414,12 @@ def _exc_to_status(exc: Exception) -> StatusCode:
425414
@staticmethod
426415
def _handle_error(message: str) -> None:
427416
"""
428-
Raises an exception or warning based on the value of ALLOW_METRIC_EXCEPTIONS.
417+
log error metric system error messages
429418
430419
Args:
431420
- message: The message to include in the exception or warning.
432421
"""
433422
full_message = f"Error in Bigtable Metrics: {message}"
434-
if ALLOW_METRIC_EXCEPTIONS:
435-
raise ValueError(full_message)
436423
LOGGER.warning(full_message)
437424

438425
async def __aenter__(self):

tests/unit/data/_metrics/test_data_model.py

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -686,30 +686,17 @@ def test__exc_to_status(self):
686686

687687
def test__handle_error(self):
688688
"""
689-
handle_error should raise an exception or write a log, depending on env var state
689+
handle_error should write log
690690
"""
691691
input_message = "test message"
692692
expected_message = f"Error in Bigtable Metrics: {input_message}"
693-
# if ALLOW_METRIC_EXCEPTIONS is set, raise the exception
694693
with mock.patch(
695-
"google.cloud.bigtable.data._metrics.data_model.ALLOW_METRIC_EXCEPTIONS",
696-
True,
697-
):
698-
with pytest.raises(ValueError) as e:
699-
type(self._make_one(object()))._handle_error(input_message)
700-
assert e.value.args[0] == expected_message
701-
with mock.patch(
702-
"google.cloud.bigtable.data._metrics.data_model.ALLOW_METRIC_EXCEPTIONS",
703-
False,
704-
):
705-
# if LOGGER is populated, log the exception
706-
with mock.patch(
707-
"google.cloud.bigtable.data._metrics.data_model.LOGGER"
708-
) as logger_mock:
709-
type(self._make_one(object()))._handle_error(input_message)
710-
assert logger_mock.warning.call_count == 1
711-
assert logger_mock.warning.call_args[0][0] == expected_message
712-
assert len(logger_mock.warning.call_args[0]) == 1
694+
"google.cloud.bigtable.data._metrics.data_model.LOGGER"
695+
) as logger_mock:
696+
type(self._make_one(object()))._handle_error(input_message)
697+
assert logger_mock.warning.call_count == 1
698+
assert logger_mock.warning.call_args[0][0] == expected_message
699+
assert len(logger_mock.warning.call_args[0]) == 1
713700

714701
@pytest.mark.asyncio
715702
async def test_async_context_manager(self):

0 commit comments

Comments
 (0)