11from .models
import HistogramStorage, CounterStorage, VoidHistogram, VoidCounterStorage
75 global counter_storage, histogram_storage
86 for engine_name
in engine_names
or engines:
87 if engine_name
in engines:
88 max_timeout = max(max_timeout, engines[engine_name].timeout)
92 histogram_size = int(1.5 * max_timeout / histogram_width)
95 for engine_name
in engine_names
or engines:
97 counter_storage.configure(
'engine', engine_name,
'search',
'count',
'sent')
98 counter_storage.configure(
'engine', engine_name,
'search',
'count',
'successful')
100 counter_storage.configure(
'engine', engine_name,
'search',
'count',
'error')
102 counter_storage.configure(
'engine', engine_name,
'score')
104 histogram_storage.configure(1, 100,
'engine', engine_name,
'result',
'count')
106 histogram_storage.configure(histogram_width, histogram_size,
'engine', engine_name,
'time',
'http')
109 histogram_storage.configure(histogram_width, histogram_size,
'engine', engine_name,
'time',
'total')
114 engine_names = list(errors_per_engines.keys())
116 for engine_name
in engine_names:
117 if engine_name
not in engline_name_list:
120 error_stats = errors_per_engines[engine_name]
121 sent_search_count = max(counter(
'engine', engine_name,
'search',
'count',
'sent'), 1)
122 sorted_context_count_list = sorted(error_stats.items(), key=
lambda context_count: context_count[1])
124 for context, count
in sorted_context_count_list:
125 percentage = round(20 * count / sent_search_count) * 5
128 'filename': context.filename,
129 'function': context.function,
130 'line_no': context.line_no,
131 'code': context.code,
132 'exception_classname': context.exception_classname,
133 'log_message': context.log_message,
134 'log_parameters': context.log_parameters,
135 'secondary': context.secondary,
136 'percentage': percentage,
139 result[engine_name] = sorted(r, reverse=
True, key=
lambda d: d[
'percentage'])
146 engine_errors = get_engine_errors(engline_name_list)
148 for engine_name
in engline_name_list:
149 checker_result = checker_results.get(engine_name, {})
150 checker_success = checker_result.get(
'success',
True)
151 errors = engine_errors.get(engine_name)
or []
152 if counter(
'engine', engine_name,
'search',
'count',
'sent') == 0:
155 elif checker_success
and not errors:
157 elif 'simple' in checker_result.get(
'errors', {}):
163 reliability = 100 - sum([error[
'percentage']
for error
in errors
if not error.get(
'secondary')])
165 reliabilities[engine_name] = {
166 'reliability': reliability,
168 'checker': checker_results.get(engine_name, {}).get(
'errors', {}),
174 assert counter_storage
is not None
175 assert histogram_storage
is not None
178 max_time_total = max_result_count =
None
180 for engine_name
in engine_name_list:
182 sent_count = counter(
'engine', engine_name,
'search',
'count',
'sent')
186 result_count = histogram(
'engine', engine_name,
'result',
'count').percentage(50)
187 result_count_sum = histogram(
'engine', engine_name,
'result',
'count').sum
188 successful_count = counter(
'engine', engine_name,
'search',
'count',
'successful')
190 time_total = histogram(
'engine', engine_name,
'time',
'total').percentage(50)
191 max_time_total = max(time_total
or 0, max_time_total
or 0)
192 max_result_count = max(result_count
or 0, max_result_count
or 0)
203 'processing_p80':
None,
204 'processing_p95':
None,
206 'score_per_result': 0,
207 'result_count': result_count,
210 if successful_count
and result_count_sum:
211 score = counter(
'engine', engine_name,
'score')
213 stats[
'score'] = score
214 stats[
'score_per_result'] = score / float(result_count_sum)
216 time_http = histogram(
'engine', engine_name,
'time',
'http').percentage(50)
217 time_http_p80 = time_http_p95 = 0
219 if time_http
is not None:
221 time_http_p80 = histogram(
'engine', engine_name,
'time',
'http').percentage(80)
222 time_http_p95 = histogram(
'engine', engine_name,
'time',
'http').percentage(95)
224 stats[
'http'] = round(time_http, 1)
225 stats[
'http_p80'] = round(time_http_p80, 1)
226 stats[
'http_p95'] = round(time_http_p95, 1)
228 if time_total
is not None:
230 time_total_p80 = histogram(
'engine', engine_name,
'time',
'total').percentage(80)
231 time_total_p95 = histogram(
'engine', engine_name,
'time',
'total').percentage(95)
233 stats[
'total'] = round(time_total, 1)
234 stats[
'total_p80'] = round(time_total_p80, 1)
235 stats[
'total_p95'] = round(time_total_p95, 1)
237 stats[
'processing'] = round(time_total - (time_http
or 0), 1)
238 stats[
'processing_p80'] = round(time_total_p80 - time_http_p80, 1)
239 stats[
'processing_p95'] = round(time_total_p95 - time_http_p95, 1)
241 list_time.append(stats)
245 'max_time': math.ceil(max_time_total
or 0),
246 'max_result_count': math.ceil(max_result_count
or 0),