12from .models
import HistogramStorage, CounterStorage, VoidHistogram, VoidCounterStorage
76 global counter_storage, histogram_storage
87 for engine_name
in engine_names
or engines:
88 if engine_name
in engines:
89 max_timeout = max(max_timeout, engines[engine_name].timeout)
93 histogram_size = int(1.5 * max_timeout / histogram_width)
96 for engine_name
in engine_names
or engines:
98 counter_storage.configure(
'engine', engine_name,
'search',
'count',
'sent')
99 counter_storage.configure(
'engine', engine_name,
'search',
'count',
'successful')
101 counter_storage.configure(
'engine', engine_name,
'search',
'count',
'error')
103 counter_storage.configure(
'engine', engine_name,
'score')
105 histogram_storage.configure(1, 100,
'engine', engine_name,
'result',
'count')
107 histogram_storage.configure(histogram_width, histogram_size,
'engine', engine_name,
'time',
'http')
110 histogram_storage.configure(histogram_width, histogram_size,
'engine', engine_name,
'time',
'total')
115 engine_names = list(errors_per_engines.keys())
117 for engine_name
in engine_names:
118 if engine_name
not in engline_name_list:
121 error_stats = errors_per_engines[engine_name]
122 sent_search_count = max(counter(
'engine', engine_name,
'search',
'count',
'sent'), 1)
123 sorted_context_count_list = sorted(error_stats.items(), key=
lambda context_count: context_count[1])
125 for context, count
in sorted_context_count_list:
126 percentage = round(20 * count / sent_search_count) * 5
129 'filename': context.filename,
130 'function': context.function,
131 'line_no': context.line_no,
132 'code': context.code,
133 'exception_classname': context.exception_classname,
134 'log_message': context.log_message,
135 'log_parameters': context.log_parameters,
136 'secondary': context.secondary,
137 'percentage': percentage,
140 result[engine_name] = sorted(r, reverse=
True, key=
lambda d: d[
'percentage'])
147 engine_errors = get_engine_errors(engline_name_list)
149 for engine_name
in engline_name_list:
150 checker_result = checker_results.get(engine_name, {})
151 checker_success = checker_result.get(
'success',
True)
152 errors = engine_errors.get(engine_name)
or []
153 sent_count = counter(
'engine', engine_name,
'search',
'count',
'sent')
158 elif checker_success
and not errors:
160 elif 'simple' in checker_result.get(
'errors', {}):
166 reliability = 100 - sum([error[
'percentage']
for error
in errors
if not error.get(
'secondary')])
168 reliabilities[engine_name] = {
169 'reliability': reliability,
170 'sent_count': sent_count,
172 'checker': checker_result.get(
'errors', {}),
178 assert counter_storage
is not None
179 assert histogram_storage
is not None
182 max_time_total = max_result_count =
None
184 for engine_name
in engine_name_list:
186 sent_count = counter(
'engine', engine_name,
'search',
'count',
'sent')
190 result_count = histogram(
'engine', engine_name,
'result',
'count').percentage(50)
191 result_count_sum = histogram(
'engine', engine_name,
'result',
'count').sum
192 successful_count = counter(
'engine', engine_name,
'search',
'count',
'successful')
194 time_total = histogram(
'engine', engine_name,
'time',
'total').percentage(50)
195 max_time_total = max(time_total
or 0, max_time_total
or 0)
196 max_result_count = max(result_count
or 0, max_result_count
or 0)
207 'processing_p80':
None,
208 'processing_p95':
None,
210 'score_per_result': 0,
211 'result_count': result_count,
214 if successful_count
and result_count_sum:
215 score = counter(
'engine', engine_name,
'score')
217 stats[
'score'] = score
218 stats[
'score_per_result'] = score / float(result_count_sum)
220 time_http = histogram(
'engine', engine_name,
'time',
'http').percentage(50)
221 time_http_p80 = time_http_p95 = 0
223 if time_http
is not None:
225 time_http_p80 = histogram(
'engine', engine_name,
'time',
'http').percentage(80)
226 time_http_p95 = histogram(
'engine', engine_name,
'time',
'http').percentage(95)
228 stats[
'http'] = round(time_http, 1)
229 stats[
'http_p80'] = round(time_http_p80, 1)
230 stats[
'http_p95'] = round(time_http_p95, 1)
232 if time_total
is not None:
234 time_total_p80 = histogram(
'engine', engine_name,
'time',
'total').percentage(80)
235 time_total_p95 = histogram(
'engine', engine_name,
'time',
'total').percentage(95)
237 stats[
'total'] = round(time_total, 1)
238 stats[
'total_p80'] = round(time_total_p80, 1)
239 stats[
'total_p95'] = round(time_total_p95, 1)
241 stats[
'processing'] = round(time_total - (time_http
or 0), 1)
242 stats[
'processing_p80'] = round(time_total_p80 - time_http_p80, 1)
243 stats[
'processing_p95'] = round(time_total_p95 - time_http_p95, 1)
245 list_time.append(stats)
249 'max_time': math.ceil(max_time_total
or 0),
250 'max_result_count': math.ceil(max_result_count
or 0),