Skip to content

Commit

Permalink
Put undefined in regex.error_re as well.
Browse files Browse the repository at this point in the history
Rearrange code to remove the duplication and prevent future errors here.
  • Loading branch information
Ryan Hitchman committed May 18, 2017
1 parent 7f5172d commit 181b35b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
4 changes: 1 addition & 3 deletions gubernator/log_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,7 @@ def digest(data, objref_dict=None, filters=None, error_re=regex.error_re,
if filters is None:
filters = {'Namespace': '', 'UID': '', 'pod': '', 'ContainerID':''}

highlight_words = [
"build timed out", "error", "fail", "failed", "fatal", "undefined"
]
highlight_words = regex.default_words

if filters["pod"]:
highlight_words = [filters["pod"]]
Expand Down
5 changes: 4 additions & 1 deletion gubernator/regex.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ def wordRE(word):
# Match lines with error messages
# HACK: match ANSI colored lines by allowing preceding "m",
# as in"\x1b[0;31mFAILED\x1b[0m"

default_words = ["build timed out", "error", "fail", "failed", "fatal", "undefined"]

error_re = re.compile(
r'(?:\b|(?<=m))(error|fatal|fail|failed|build timed out)\b', re.IGNORECASE)
r'(?:\b|(?<=m))(%s)\b' % '|'.join(default_words), re.IGNORECASE)

# Match the dictionary string in the given line
def objref(line):
Expand Down
1 change: 1 addition & 0 deletions gubernator/regex_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def test_error_re(self):
('there was a FaTaL error', True),
('we failed to read logs', True),
('FAIL k8s.io/kubernetes/pkg/client/record', True),
('undefined: someVariable', True),
('\x1b[0;31mFAILED\x1b[0m', True), # color codes
]:
self.assertEqual(bool(regex.error_re.search(text)), matches,
Expand Down

0 comments on commit 181b35b

Please sign in to comment.