Skip to content

Commit fe722c7

Browse files
committed
oomparser: don't get stuck for certain processes
The oomparser logic would end up stuck, unable to detect the end of a given oom trace, for any process with a name that didn't match \w+. This includes processes like 'python3.4' due to the '.', or 'docker-containerd' due to the '-'. This fix was included in pr #1544 last year, but since that PR seems dead it seems like a good idea to break this more important fix out. I've updated the tests such that they would have caught this issue.
1 parent ee7e1dd commit fe722c7

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

Diff for: utils/oomparser/oomparser.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import (
3232

3333
var (
3434
containerRegexp = regexp.MustCompile(`Task in (.*) killed as a result of limit of (.*)`)
35-
lastLineRegexp = regexp.MustCompile(`(^[A-Z][a-z]{2} .*[0-9]{1,2} [0-9]{1,2}:[0-9]{2}:[0-9]{2}) .* Killed process ([0-9]+) \(([\w]+)\)`)
35+
lastLineRegexp = regexp.MustCompile(`(^[A-Z][a-z]{2} .*[0-9]{1,2} [0-9]{1,2}:[0-9]{2}:[0-9]{2}) .* Killed process ([0-9]+) \((.+)\)`)
3636
firstLineRegexp = regexp.MustCompile(`invoked oom-killer:`)
3737
)
3838

Diff for: utils/oomparser/oomparser_test.go

+14-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
)
2727

2828
const startLine = "Jan 21 22:01:49 localhost kernel: [62278.816267] ruby invoked oom-killer: gfp_mask=0x201da, order=0, oom_score_adj=0"
29-
const endLine = "Jan 21 22:01:49 localhost kernel: [62279.421192] Killed process 19667 (evilprogram2) total-vm:1460016kB, anon-rss:1414008kB, file-rss:4kB"
29+
const endLine = "Jan 21 22:01:49 localhost kernel: [62279.421192] Killed process 19667 (evil-program2) total-vm:1460016kB, anon-rss:1414008kB, file-rss:4kB"
3030
const containerLine = "Jan 26 14:10:07 kateknister0.mtv.corp.google.com kernel: [1814368.465205] Task in /mem2 killed as a result of limit of /mem3"
3131
const containerLogFile = "containerOomExampleLog.txt"
3232
const systemLogFile = "systemOomExampleLog.txt"
@@ -104,8 +104,8 @@ func TestGetProcessNamePid(t *testing.T) {
104104
if !couldParseLine {
105105
t.Errorf("good line fed to getProcessNamePid should return true but returned %v", couldParseLine)
106106
}
107-
if currentOomInstance.ProcessName != "evilprogram2" {
108-
t.Errorf("getProcessNamePid should have set processName to evilprogram2, not %s", currentOomInstance.ProcessName)
107+
if currentOomInstance.ProcessName != "evil-program2" {
108+
t.Errorf("getProcessNamePid should have set processName to evil-program2, not %s", currentOomInstance.ProcessName)
109109
}
110110
if currentOomInstance.Pid != 19667 {
111111
t.Errorf("getProcessNamePid should have set PID to 19667, not %d", currentOomInstance.Pid)
@@ -126,6 +126,17 @@ func TestCheckIfStartOfMessages(t *testing.T) {
126126
}
127127
}
128128

129+
func TestLastLineRegex(t *testing.T) {
130+
processNames := []string{"foo", "python3.4", "foo-bar", "Plex Media Server", "x86_64-pc-linux-gnu-c++-5.4.0", "[", "()", `"with quotes"`}
131+
for _, name := range processNames {
132+
line := fmt.Sprintf("Jan 21 22:01:49 localhost kernel: [62279.421192] Killed process 1234 (%s) total-vm:1460016kB, anon-rss:1414008kB, file-rss:4kB", name)
133+
oomInfo := &OomInstance{}
134+
getProcessNamePid(line, oomInfo)
135+
assert.Equal(t, 1234, oomInfo.Pid)
136+
assert.Equal(t, name, oomInfo.ProcessName)
137+
}
138+
}
139+
129140
func TestStreamOomsContainer(t *testing.T) {
130141
expectedContainerOomInstance := createExpectedContainerOomInstance(t)
131142
helpTestStreamOoms(expectedContainerOomInstance, containerLogFile, t)

0 commit comments

Comments
 (0)