Fix to allow process names with spaces

This commit is contained in:
Carsten Grohmann 2021-07-18 14:21:07 +02:00
parent 1f087b7cd9
commit e283ff2019
3 changed files with 53 additions and 15 deletions

View File

@ -817,6 +817,7 @@ function read_and_display_file(file) {
<ol> <ol>
<li>Improve SVG chart colour palette</li> <li>Improve SVG chart colour palette</li>
<li>Add Selenium based unit tests</li> <li>Add Selenium based unit tests</li>
<li>Fix to allow process names with spaces</li>
<li>...</li> <li>...</li>
</ol> </ol>

View File

@ -220,13 +220,24 @@ class OOMEntity(object):
strip later. strip later.
""" """
to_strip = 0 to_strip = 0
columns = first_line.split(" ") columns = first_line.split(" ")
# Examples:
# [11686.888109] sed invoked oom-killer: gfp_mask=0x201da, order=0, oom_adj=0, oom_score_adj=0
# Apr 01 14:13:32 mysrv kernel: sed invoked OOM-killer: gfp_mask=0x201da, order=0
# Apr 01 14:13:32 mysrv kernel: [11686.888109] sed invoked oom-killer: gfp_mask=0x84d0, order=0, oom_adj=0, oom_score_adj=0
try: try:
# strip all before "<program name> invoked oom-killer: gfp_mask=0x280da, order=0, oom_score_adj=0 # strip all incl. "kernel:"
to_strip = columns.index("invoked") if 'kernel:' in first_line:
# decrease to include <program name> to_strip = columns.index("kernel:")
to_strip -= 1 # increase to include "kernel:"
to_strip += 1
# check if next column is a timestamp like "[11686.888109]" and remove it too
rec = re.compile('\[\d+\.\d+\]')
if rec.match(columns[to_strip]):
# increase to include timestamp
to_strip += 1
except ValueError: except ValueError:
pass pass
@ -290,12 +301,6 @@ class OOMEntity(object):
if cols_to_strip: if cols_to_strip:
# [-1] slicing needs Transcrypt operator overloading # [-1] slicing needs Transcrypt operator overloading
line = line.split(" ", cols_to_strip)[-1] # __:opov line = line.split(" ", cols_to_strip)[-1] # __:opov
# OOMs logged to /var/log/messages / journalctl may contain
# "kernel:" at the begin of the content
if line.startswith('kernel:'):
line = line[7:]
stripped_lines.append(line) stripped_lines.append(line)
return stripped_lines return stripped_lines

40
test.py
View File

@ -100,6 +100,12 @@ class TestInBrowser(TestBase):
with self.assertRaises(NoSuchElementException): with self.assertRaises(NoSuchElementException):
notify_box.find_element_by_class_name('js-notify_box__msg--error') notify_box.find_element_by_class_name('js-notify_box__msg--error')
for event in self.driver.get_log('browser'):
# ignore favicon.ico errors
if 'favicon.ico' in event['message']:
continue
self.fail('Error on browser console reported: %s' % event)
def click_analyse(self): def click_analyse(self):
analyse = self.driver.find_element_by_xpath('//button[text()="Analyse"]') analyse = self.driver.find_element_by_xpath('//button[text()="Analyse"]')
analyse.click() analyse.click()
@ -193,11 +199,27 @@ Killed process 6576 (java) total-vm:33914892kB, anon-rss:20629004kB, file-rss:0k
def test_006_trigger_proc_space(self): def test_006_trigger_proc_space(self):
"""Test trigger process name contains a space""" """Test trigger process name contains a space"""
pass example = OOMAnalyser.OOMDisplay.example
example = example.replace('sed', 'VM Monitoring Task')
self.analyse_oom(example)
self.assert_on_warn_error()
h3_summary = self.driver.find_element_by_xpath('//h3[text()="Summary"]')
self.assertTrue(h3_summary.is_displayed(), "Analysis details incl. <h3>Summary</h3> should be displayed")
def test_007_kill_proc_space(self): def test_007_kill_proc_space(self):
"""Test killed process name contains a space""" """Test killed process name contains a space"""
pass example = OOMAnalyser.OOMDisplay.example
example = example.replace('mysqld', 'VM Monitoring Task')
self.analyse_oom(example)
self.assert_on_warn_error()
h3_summary = self.driver.find_element_by_xpath('//h3[text()="Summary"]')
self.assertTrue(h3_summary.is_displayed(), "Analysis details incl. <h3>Summary</h3> should be displayed")
class TestPython(TestBase): class TestPython(TestBase):
@ -228,8 +250,18 @@ class TestPython(TestBase):
self.assertTrue(match, 'Error: re.search(REC_OOM_KILL_PROCESS) failed for process name ' self.assertTrue(match, 'Error: re.search(REC_OOM_KILL_PROCESS) failed for process name '
'with space') 'with space')
def test_003_OOMEntity_number_of_columns_to_strip(self):
"""Test stripping useless / leading columns"""
oom_entity = OOMAnalyser.OOMEntity(OOMAnalyser.OOMDisplay.example)
for pos, line in [
(1, '[11686.888109] sed invoked oom-killer: gfp_mask=0x201da, order=0, oom_adj=0, oom_score_adj=0'),
(5, 'Apr 01 14:13:32 mysrv kernel: sed invoked OOM-killer: gfp_mask=0x201da, order=0'),
(6, 'Apr 01 14:13:32 mysrv kernel: [11686.888109] sed invoked oom-killer: gfp_mask=0x84d0, order=0, oom_adj=0, oom_score_adj=0'),
]:
to_strip = oom_entity._number_of_columns_to_strip(line)
self.assertEqual(to_strip, pos, 'Calc wrong number of colums to strip for "%s": got: %d, expect: %d' % (
line, to_strip, pos))
if __name__ == "__main__": if __name__ == "__main__":
# import logging, sys
# logging.basicConfig(stream=sys.stderr, level=logging.WARNING)
unittest.main(verbosity=2) unittest.main(verbosity=2)