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 )
4138LOGGER = 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 ):
0 commit comments