From df41b7712150adf384bc08e38215a7cc9970c100 Mon Sep 17 00:00:00 2001 From: Alexandre Flament Date: Fri, 23 Apr 2021 21:08:48 +0200 Subject: [PATCH] [mod] /stats : detail per engine allow to submit a github issue including the technical details (exceptions, errors, warning, checker result) --- searx/__init__.py | 4 ++ searx/metrics/__init__.py | 2 +- searx/settings.yml | 1 + searx/templates/__common__/new_issue.html | 74 ++++++++++++++++++++ searx/templates/oscar/stats.html | 82 ++++++++++++++++++++--- searx/templates/simple/stats.html | 70 +++++++++++++++++-- searx/webapp.py | 14 +++- 7 files changed, 227 insertions(+), 20 deletions(-) create mode 100644 searx/templates/__common__/new_issue.html diff --git a/searx/__init__.py b/searx/__init__.py index 11adbba73..71e00a49a 100644 --- a/searx/__init__.py +++ b/searx/__init__.py @@ -88,6 +88,10 @@ class _brand_namespace: def ISSUE_URL(self): return self.get_val('brand', 'issue_url') + @property + def NEW_ISSUE_URL(self): + return self.get_val('brand', 'new_issue_url') + @property def DOCS_URL(self): return self.get_val('brand', 'docs_url') diff --git a/searx/metrics/__init__.py b/searx/metrics/__init__.py index adcb47aeb..6ed578116 100644 --- a/searx/metrics/__init__.py +++ b/searx/metrics/__init__.py @@ -150,7 +150,7 @@ def get_reliabilities(engline_name_list, checker_results): reliabilities[engine_name] = { 'reliablity': reliablity, 'errors': errors, - 'checker': checker_results.get(engine_name, {}).get('errors', {}).keys(), + 'checker': checker_results.get(engine_name, {}).get('errors', {}), } return reliabilities diff --git a/searx/settings.yml b/searx/settings.yml index 6e106a462..13163c7e4 100644 --- a/searx/settings.yml +++ b/searx/settings.yml @@ -7,6 +7,7 @@ brand: git_url: https://github.com/searxng/searxng git_branch: master issue_url: https://github.com/searxng/searxng/issues + new_issue_url: https://github.com/searxng/searxng/issues/new docs_url: https://searxng.github.io/searxng public_instances: https://searx.space wiki_url: https://github.com/searxng/searxng/wiki diff --git a/searx/templates/__common__/new_issue.html b/searx/templates/__common__/new_issue.html new file mode 100644 index 000000000..2a111a527 --- /dev/null +++ b/searx/templates/__common__/new_issue.html @@ -0,0 +1,74 @@ +{% macro new_issue(new_issue_url, engine_name, engine_reliability) %} +
+ + + + + + +
+{% endmacro %} diff --git a/searx/templates/oscar/stats.html b/searx/templates/oscar/stats.html index b83714020..49c776ea8 100644 --- a/searx/templates/oscar/stats.html +++ b/searx/templates/oscar/stats.html @@ -1,18 +1,21 @@ -{% extends "oscar/base.html" %} +{% extends 'oscar/base.html' %} +{% from '__common__/new_issue.html' import new_issue %} -{% block title %}{{ _('stats') }} - {% endblock %} +{% block title %}{{ _('stats') }} - {% if selected_engine_name %} {{ selected_engine_name }} - {% endif %}{% endblock %} {%- macro th_sort(column_order, column_name) -%} - {% if column_order==sort_order %} - {{ column_name }} {{ icon('chevron-down') }} - {% else %} - {{ column_name }} - {% endif %} + {%- if selected_engine_name -%} + {{ column_name }} + {%- elif column_order==sort_order -%} + {{ column_name }} {{ icon('arrow-dropdown') }} + {%- else -%} + {{ column_name }} + {%- endif -%} {%- endmacro -%} {% block content %}
-

{{ _('Engine stats') }}

+

{{ _('Engine stats') }}{% if selected_engine_name %} - {{ selected_engine_name }}{% endif %}

@@ -31,14 +34,14 @@ {% for engine_stat in engine_stats.get('time', []) %} - {{ engine_stat.name }} + {{ engine_stat.name }} - {% if engine_stat.score %} + {%- if engine_stat.score -%} {{ engine_stat.score|round(1) }} - {% endif %} + {%- endif -%} {%- if engine_stat.result_count -%} @@ -92,6 +95,63 @@ {% endif %}
+
+ {% if selected_engine_name %} + {% for secondary in [False, True] %} + {% set ns = namespace(first=true) %} + {% for error in engine_reliabilities[selected_engine_name].errors %} + {% if secondary == error.secondary %} + {% if ns.first %} + {% set ns.first = false %} +

{% if secondary %}{{ _('Warnings') }}{% else %}{{ _('Errors and exceptions') }}{% endif %}

+ {% endif %} + + + + {%- if error.exception_classname -%} + + {%- elif error.log_message -%} + + {%- endif -%} + + + {% if error.log_parameters and error.log_parameters != (None, None, None) %}{{- '' -}} + + + {% endif %} + + + + +
{{ _('Exception') }}{{ error.exception_classname }}{{ _('Message') }}{{ error.log_message }}{{ _('Percentage') }}{{ error.percentage }}
{{ _('Parameter') }} + {%- for param in error.log_parameters -%} + {{ param }} + {%- endfor -%} +
{{ _('Filename') }}{{ error.filename }}:{{ error.line_no }}
{{ _('Function') }}{{ error.function }}
{{ _('Code') }}{{ error.code }}
+ {% endif %} + {% endfor %} + {% endfor %} + {% if engine_reliabilities[selected_engine_name].checker %} +

{{ _('Checker') }}

+ + + + + + {% for test_name, results in engine_reliabilities[selected_engine_name].checker.items() %} + + + + + {% endfor %} +
{{ _('Failed test') }}{{ _('Comment(s)') }}
{{ test_name }} + {% for r in results %}

{{ r }}

{% endfor %} +
+ {% endif %} + {{ new_issue(brand.NEW_ISSUE_URL, selected_engine_name, engine_reliabilities[selected_engine_name]) }} + {% endif %} +
+ {% endblock %} diff --git a/searx/templates/simple/stats.html b/searx/templates/simple/stats.html index eecd88903..098a54065 100644 --- a/searx/templates/simple/stats.html +++ b/searx/templates/simple/stats.html @@ -1,12 +1,15 @@ {% from 'simple/macros.html' import icon %} +{% from '__common__/new_issue.html' import new_issue %} {% extends "simple/base.html" %} {%- macro th_sort(column_order, column_name) -%} - {% if column_order==sort_order %} + {% if selected_engine_name %} + {{ column_name }} + {% elif column_order==sort_order %} {{ column_name }} {{ icon('arrow-dropdown') }} {% else %} - {{ column_name }} + {{ column_name }} {% endif %} {%- endmacro -%} @@ -15,12 +18,12 @@

searx

-

{{ _('Engine stats') }}

+

{{ _('Engine stats') }}{% if selected_engine_name %} - {{ selected_engine_name }}{% endif %}

{% if not engine_stats.get('time') %} {{ _('There is currently no data available. ') }} {% else %} - +
@@ -30,7 +33,7 @@ {% for engine_stat in engine_stats.get('time', []) %} - +
{{ th_sort('name', _("Engine name")) }} {{ th_sort('score', _('Scores')) }}
{{ engine_stat.name }}{{ engine_stat.name }} {% if engine_stat.score %} {{ engine_stat.score|round(1) }} @@ -90,4 +93,61 @@
{% endif %} +
+ {% if selected_engine_name %} + {% for secondary in [False, True] %} + {% set ns = namespace(first=true) %} + {% for error in engine_reliabilities[selected_engine_name].errors %} + {% if secondary == error.secondary %} + {% if ns.first %} + {% set ns.first = false %} +

{% if secondary %}{{ _('Warnings') }}{% else %}{{ _('Errors and exceptions') }}{% endif %}

+ {% endif %} + + + + {%- if error.exception_classname -%} + + {%- elif error.log_message -%} + + {%- endif -%} + + + {% if error.log_parameters and error.log_parameters != (None, None, None) %}{{- '' -}} + + + {% endif %} + + + + +
{{ _('Exception') }}{{ error.exception_classname }}{{ _('Message') }}{{ error.log_message }}{{ _('Percentage') }}{{ error.percentage }}
{{ _('Parameter') }} + {%- for param in error.log_parameters -%} + {{ param }} + {%- endfor -%} +
{{ _('Filename') }}{{ error.filename }}:{{ error.line_no }}
{{ _('Function') }}{{ error.function }}
{{ _('Code') }}{{ error.code }}
+ {% endif %} + {% endfor %} + {% endfor %} + {% if engine_reliabilities[selected_engine_name].checker %} +

{{ _('Checker') }}

+ + + + + + {% for test_name, results in engine_reliabilities[selected_engine_name].checker.items() %} + + + + + {% endfor %} +
{{ _('Failed test') }}{{ _('Comment(s)') }}
{{ test_name }} + {% for r in results %}

{{ r }}

{% endfor %} +
+ {% endif %} + {{ new_issue(brand.NEW_ISSUE_URL, selected_engine_name, engine_reliabilities[selected_engine_name]) }} + {% endif %} +
+ {% endblock %} diff --git a/searx/webapp.py b/searx/webapp.py index d917c16d4..69ec915a7 100755 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -1073,16 +1073,23 @@ def image_proxy(): @app.route('/stats', methods=['GET']) def stats(): """Render engine statistics page.""" + sort_order = request.args.get('sort', default='name', type=str) + selected_engine_name = request.args.get('engine', default=None, type=str) + + filtered_engines = dict(filter(lambda kv: (kv[0], request.preferences.validate_token(kv[1])), engines.items())) + if selected_engine_name: + if selected_engine_name not in filtered_engines: + selected_engine_name = None + else: + filtered_engines = [selected_engine_name] + checker_results = checker_get_result() checker_results = checker_results['engines'] \ if checker_results['status'] == 'ok' and 'engines' in checker_results else {} - filtered_engines = dict(filter(lambda kv: (kv[0], request.preferences.validate_token(kv[1])), engines.items())) engine_stats = get_engines_stats(filtered_engines) engine_reliabilities = get_reliabilities(filtered_engines, checker_results) - sort_order = request.args.get('sort', default='name', type=str) - SORT_PARAMETERS = { 'name': (False, 'name', ''), 'score': (True, 'score', 0), @@ -1114,6 +1121,7 @@ def stats(): sort_order=sort_order, engine_stats=engine_stats, engine_reliabilities=engine_reliabilities, + selected_engine_name=selected_engine_name, )