Commit ee65c76a authored by Julien Muchembled's avatar Julien Muchembled

promise: treat CRITICAL like ERROR

parent aee0f487
...@@ -47,10 +47,12 @@ PROMISE_LOG_FOLDER_NAME = '.slapgrid/promise/log' ...@@ -47,10 +47,12 @@ PROMISE_LOG_FOLDER_NAME = '.slapgrid/promise/log'
PROMISE_PARAMETER_NAME = 'extra_config_dict' PROMISE_PARAMETER_NAME = 'extra_config_dict'
LOGLINE_RE = r"(\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2})\s+\-?\s*(\w{4,7})\s+\-?\s+(\d+\-\d{3})\s+\-?\s*(.*)" LOGLINE_RE = r"(\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2})\s+\-?\s*(\w+)\s+\-?\s+(\d+\-\d{3})\s+\-?\s*(.*)"
matchLogStr = re.compile(LOGLINE_RE).match matchLogStr = re.compile(LOGLINE_RE).match
matchLogBytes = re.compile(LOGLINE_RE.encode()).match if PY3 else matchLogStr matchLogBytes = re.compile(LOGLINE_RE.encode()).match if PY3 else matchLogStr
ERROR_LEVEL = 'CRITICAL', 'ERROR'
class BaseResult(object): class BaseResult(object):
def __init__(self, problem=False, message=None, date=None): def __init__(self, problem=False, message=None, date=None):
self.__problem = problem self.__problem = problem
...@@ -283,16 +285,16 @@ class GenericPromise(with_metaclass(ABCMeta, object)): ...@@ -283,16 +285,16 @@ class GenericPromise(with_metaclass(ABCMeta, object)):
continue continue
match = matchLogStr(line) match = matchLogStr(line)
if match is not None: if match is not None:
if not only_failure or (only_failure and match.groups()[1] == 'ERROR'): date, level, tid, msg = match.groups()
if not only_failure or level in ERROR_LEVEL:
result_list.append({ result_list.append({
'date': datetime.strptime(match.groups()[0], '%Y-%m-%d %H:%M:%S'), 'date': datetime.strptime(date, '%Y-%m-%d %H:%M:%S'),
'status': match.groups()[1], 'status': level,
'message': (match.groups()[3] + line_part).strip(), 'message': (msg + line_part).strip(),
}) })
line_part = "" line_part = ""
else: else:
line_part += '\n' + line line_part += '\n' + line
result_list
return [result_list] return [result_list]
...@@ -358,7 +360,7 @@ class GenericPromise(with_metaclass(ABCMeta, object)): ...@@ -358,7 +360,7 @@ class GenericPromise(with_metaclass(ABCMeta, object)):
if transaction_count > result_count: if transaction_count > result_count:
break break
transaction_id = tid transaction_id = tid
if not only_failure or level == 'ERROR': if not only_failure or level in ERROR_LEVEL:
line_list.insert(0, { line_list.insert(0, {
'date': datetime.strptime(date, 'date': datetime.strptime(date,
'%Y-%m-%d %H:%M:%S'), '%Y-%m-%d %H:%M:%S'),
...@@ -378,7 +380,7 @@ class GenericPromise(with_metaclass(ABCMeta, object)): ...@@ -378,7 +380,7 @@ class GenericPromise(with_metaclass(ABCMeta, object)):
failed = False failed = False
message = "" message = ""
for result in result_list: for result in result_list:
if result['status'] == 'ERROR': if result['status'] in ERROR_LEVEL:
failed = True failed = True
message += "\n%s" % result['message'] message += "\n%s" % result['message']
return failed, message.strip() return failed, message.strip()
...@@ -414,7 +416,7 @@ class GenericPromise(with_metaclass(ABCMeta, object)): ...@@ -414,7 +416,7 @@ class GenericPromise(with_metaclass(ABCMeta, object)):
failure_found = 1 failure_found = 1
while i < result_size and failure_found < failure_amount: while i < result_size and failure_found < failure_amount:
for result in latest_result_list[i]: for result in latest_result_list[i]:
if result['status'] == 'ERROR': if result['status'] in ERROR_LEVEL:
failure_found += 1 failure_found += 1
break break
i += 1 i += 1
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment