DAQ: throttle userrightsexception. so it does not repeatedly log the same error
This commit is contained in:
@@ -104,6 +104,8 @@ class AuthenticationException(Exception):
|
||||
|
||||
|
||||
class UserRightsException(Exception):
|
||||
_last_log_ts_by_message: dict[str, float] = {}
|
||||
_throttle_window_s = 30.0
|
||||
def __init__(self,
|
||||
message: str = "User does not have rights to perform this action.",
|
||||
*,
|
||||
@@ -115,7 +117,12 @@ class UserRightsException(Exception):
|
||||
self.status_code = status_code
|
||||
self.headers = headers
|
||||
self.code = code
|
||||
logger.error(message, extra={"exception:": Exception})
|
||||
|
||||
now = time.monotonic()
|
||||
last_ts = self._last_log_ts_by_message.get(message, 0.0)
|
||||
if (now - last_ts) >= self._throttle_window_s:
|
||||
self._last_log_ts_by_message[message] = now
|
||||
logger.warning(message, extra={"exception:": Exception})
|
||||
|
||||
def __str__(self) -> str:
|
||||
return self.message
|
||||
|
||||
Reference in New Issue
Block a user