10from .models
import HistogramStorage, CounterStorage, VoidHistogram, VoidCounterStorage
70def initialize(engine_names: list[str] |
None =
None, enabled: bool =
True) ->
None:
74 global counter_storage, histogram_storage
85 for engine_name
in engine_names
or engines:
86 if engine_name
in engines:
87 max_timeout = max(max_timeout, engines[engine_name].timeout)
91 histogram_size = int(1.5 * max_timeout / histogram_width)
94 for engine_name
in engine_names
or engines:
96 counter_storage.configure(
'engine', engine_name,
'search',
'count',
'sent')
97 counter_storage.configure(
'engine', engine_name,
'search',
'count',
'successful')
99 counter_storage.configure(
'engine', engine_name,
'search',
'count',
'error')
101 counter_storage.configure(
'engine', engine_name,
'score')
103 histogram_storage.configure(1, 100,
'engine', engine_name,
'result',
'count')
105 histogram_storage.configure(histogram_width, histogram_size,
'engine', engine_name,
'time',
'http')
108 histogram_storage.configure(histogram_width, histogram_size,
'engine', engine_name,
'time',
'total')
113 engine_names = list(errors_per_engines.keys())
115 for engine_name
in engine_names:
116 if engine_name
not in engline_name_list:
119 error_stats = errors_per_engines[engine_name]
120 sent_search_count = max(
counter(
'engine', engine_name,
'search',
'count',
'sent'), 1)
121 sorted_context_count_list = sorted(error_stats.items(), key=
lambda context_count: context_count[1])
123 for context, count
in sorted_context_count_list:
124 percentage = round(20 * count / sent_search_count) * 5
127 'filename': context.filename,
128 'function': context.function,
129 'line_no': context.line_no,
130 'code': context.code,
131 'exception_classname': context.exception_classname,
132 'log_message': context.log_message,
133 'log_parameters': context.log_parameters,
134 'secondary': context.secondary,
135 'percentage': percentage,
138 result[engine_name] = sorted(r, reverse=
True, key=
lambda d: d[
'percentage'])
147 for engine_name
in engline_name_list:
148 checker_result = checker_results.get(engine_name, {})
149 checker_success = checker_result.get(
'success',
True)
150 errors = engine_errors.get(engine_name)
or []
151 sent_count =
counter(
'engine', engine_name,
'search',
'count',
'sent')
156 elif checker_success
and not errors:
158 elif 'simple' in checker_result.get(
'errors', {}):
164 reliability = 100 - sum([error[
'percentage']
for error
in errors
if not error.get(
'secondary')])
166 reliabilities[engine_name] = {
167 'reliability': reliability,
168 'sent_count': sent_count,
170 'checker': checker_result.get(
'errors', {}),
176 assert counter_storage
is not None
177 assert histogram_storage
is not None
180 max_time_total = max_result_count =
None
182 for engine_name
in engine_name_list:
184 sent_count =
counter(
'engine', engine_name,
'search',
'count',
'sent')
188 result_count =
histogram(
'engine', engine_name,
'result',
'count').percentage(50)
189 result_count_sum =
histogram(
'engine', engine_name,
'result',
'count').sum
190 successful_count =
counter(
'engine', engine_name,
'search',
'count',
'successful')
192 time_total =
histogram(
'engine', engine_name,
'time',
'total').percentage(50)
193 max_time_total = max(time_total
or 0, max_time_total
or 0)
194 max_result_count = max(result_count
or 0, max_result_count
or 0)
205 'processing_p80':
None,
206 'processing_p95':
None,
208 'score_per_result': 0,
209 'result_count': result_count,
212 if successful_count
and result_count_sum:
213 score =
counter(
'engine', engine_name,
'score')
215 stats[
'score'] = score
216 stats[
'score_per_result'] = score / float(result_count_sum)
218 time_http =
histogram(
'engine', engine_name,
'time',
'http').percentage(50)
219 time_http_p80 = time_http_p95 = 0
221 if time_http
is not None:
223 time_http_p80 =
histogram(
'engine', engine_name,
'time',
'http').percentage(80)
224 time_http_p95 =
histogram(
'engine', engine_name,
'time',
'http').percentage(95)
226 stats[
'http'] = round(time_http, 1)
227 stats[
'http_p80'] = round(time_http_p80, 1)
228 stats[
'http_p95'] = round(time_http_p95, 1)
230 if time_total
is not None:
232 time_total_p80 =
histogram(
'engine', engine_name,
'time',
'total').percentage(80)
233 time_total_p95 =
histogram(
'engine', engine_name,
'time',
'total').percentage(95)
235 stats[
'total'] = round(time_total, 1)
236 stats[
'total_p80'] = round(time_total_p80, 1)
237 stats[
'total_p95'] = round(time_total_p95, 1)
239 stats[
'processing'] = round(time_total - (time_http
or 0), 1)
240 stats[
'processing_p80'] = round(time_total_p80 - time_http_p80, 1)
241 stats[
'processing_p95'] = round(time_total_p95 - time_http_p95, 1)
243 list_time.append(stats)
247 'max_time': math.ceil(max_time_total
or 0),
248 'max_result_count': math.ceil(max_result_count
or 0),