diff options
author | Alexandre Flament <alex@al-f.net> | 2021-04-17 18:15:50 +0200 |
---|---|---|
committer | Alexandre Flament <alex@al-f.net> | 2021-04-21 16:24:46 +0200 |
commit | c27fef1cdeeebcc17e21dbdc3dafad00de08a2ce (patch) | |
tree | 06cf169c03f07cfadd4462c988c33a2f63703f51 /searx/metrics | |
parent | 7acd7ffc02d14d175ec2a99ba984e47d8cb65d7d (diff) | |
download | searxng-c27fef1cdeeebcc17e21dbdc3dafad00de08a2ce.tar.gz searxng-c27fef1cdeeebcc17e21dbdc3dafad00de08a2ce.zip |
[mod] metrics: add secondary parameter
Some error won't stop the engine:
* additional HTTP redirects for example
* some invalid results
secondary=True allows to flag these errors as not important.
Diffstat (limited to 'searx/metrics')
-rw-r--r-- | searx/metrics/error_recorder.py | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/searx/metrics/error_recorder.py b/searx/metrics/error_recorder.py index d99d9375d..2bf25fb0d 100644 --- a/searx/metrics/error_recorder.py +++ b/searx/metrics/error_recorder.py @@ -13,9 +13,10 @@ errors_per_engines = {} class ErrorContext: - __slots__ = 'filename', 'function', 'line_no', 'code', 'exception_classname', 'log_message', 'log_parameters' + __slots__ = ('filename', 'function', 'line_no', 'code', 'exception_classname', + 'log_message', 'log_parameters', 'secondary') - def __init__(self, filename, function, line_no, code, exception_classname, log_message, log_parameters): + def __init__(self, filename, function, line_no, code, exception_classname, log_message, log_parameters, secondary): self.filename = filename self.function = function self.line_no = line_no @@ -23,22 +24,24 @@ class ErrorContext: self.exception_classname = exception_classname self.log_message = log_message self.log_parameters = log_parameters + self.secondary = secondary def __eq__(self, o) -> bool: if not isinstance(o, ErrorContext): return False return self.filename == o.filename and self.function == o.function and self.line_no == o.line_no\ and self.code == o.code and self.exception_classname == o.exception_classname\ - and self.log_message == o.log_message and self.log_parameters == o.log_parameters + and self.log_message == o.log_message and self.log_parameters == o.log_parameters \ + and self.secondary == o.secondary def __hash__(self): return hash((self.filename, self.function, self.line_no, self.code, self.exception_classname, self.log_message, - self.log_parameters)) + self.log_parameters, self.secondary)) def __repr__(self): - return "ErrorContext({!r}, {!r}, {!r}, {!r}, {!r}, {!r})".\ + return "ErrorContext({!r}, {!r}, {!r}, {!r}, {!r}, {!r}) {!r}".\ format(self.filename, self.line_no, self.code, self.exception_classname, self.log_message, - self.log_parameters) + self.log_parameters, self.secondary) def add_error_context(engine_name: str, error_context: ErrorContext) -> None: @@ -111,31 +114,32 @@ def get_exception_classname(exc: Exception) -> str: return exc_module + '.' + exc_name -def get_error_context(framerecords, exception_classname, log_message, log_parameters) -> ErrorContext: +def get_error_context(framerecords, exception_classname, log_message, log_parameters, secondary) -> ErrorContext: searx_frame = get_trace(framerecords) filename = searx_frame.filename function = searx_frame.function line_no = searx_frame.lineno code = searx_frame.code_context[0].strip() del framerecords - return ErrorContext(filename, function, line_no, code, exception_classname, log_message, log_parameters) + return ErrorContext(filename, function, line_no, code, exception_classname, log_message, log_parameters, secondary) -def count_exception(engine_name: str, exc: Exception) -> None: +def count_exception(engine_name: str, exc: Exception, secondary: bool = False) -> None: framerecords = inspect.trace() try: exception_classname = get_exception_classname(exc) log_parameters = get_messages(exc, framerecords[-1][1]) - error_context = get_error_context(framerecords, exception_classname, None, log_parameters) + error_context = get_error_context(framerecords, exception_classname, None, log_parameters, secondary) add_error_context(engine_name, error_context) finally: del framerecords -def count_error(engine_name: str, log_message: str, log_parameters: typing.Optional[typing.Tuple] = None) -> None: +def count_error(engine_name: str, log_message: str, log_parameters: typing.Optional[typing.Tuple] = None, + secondary: bool = False) -> None: framerecords = list(reversed(inspect.stack()[1:])) try: - error_context = get_error_context(framerecords, None, log_message, log_parameters or ()) + error_context = get_error_context(framerecords, None, log_message, log_parameters or (), secondary) add_error_context(engine_name, error_context) finally: del framerecords |