Skip to content

Commit

Permalink
Merge pull request google#488 from kateknister/master
Browse files Browse the repository at this point in the history
Minor change to the way time is parsed from the kernel log in oomparser
  • Loading branch information
kateknister committed Feb 5, 2015
2 parents 621045b + 1291347 commit 5e61b39
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
4 changes: 3 additions & 1 deletion utils/oomparser/oomparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ func getProcessNamePid(line string, currentOomInstance *OomInstance) (bool, erro
if reList == nil {
return false, nil
}
linetime, err := time.Parse(time.Stamp, reList[1])
const longForm = "Jan _2 15:04:05 2006"
stringYear := strconv.Itoa(time.Now().Year())
linetime, err := time.Parse(longForm, reList[1]+" "+stringYear)
if err != nil {
return false, err
}
Expand Down
11 changes: 7 additions & 4 deletions utils/oomparser/oomparser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ const containerLogFile = "containerOomExampleLog.txt"
const systemLogFile = "systemOomExampleLog.txt"

func createExpectedContainerOomInstance(t *testing.T) *OomInstance {
deathTime, err := time.Parse(time.Stamp, "Jan 5 15:19:27")
const longForm = "Jan _2 15:04:05 2006"
deathTime, err := time.Parse(longForm, "Jan 5 15:19:27 2015")
if err != nil {
t.Fatalf("could not parse expected time when creating expected container oom instance. Had error %v", err)
return nil
Expand All @@ -41,7 +42,8 @@ func createExpectedContainerOomInstance(t *testing.T) *OomInstance {
}

func createExpectedSystemOomInstance(t *testing.T) *OomInstance {
deathTime, err := time.Parse(time.Stamp, "Jan 28 19:58:45")
const longForm = "Jan _2 15:04:05 2006"
deathTime, err := time.Parse(longForm, "Jan 28 19:58:45 2015")
if err != nil {
t.Fatalf("could not parse expected time when creating expected system oom instance. Had error %v", err)
return nil
Expand Down Expand Up @@ -82,7 +84,8 @@ func TestGetProcessNamePid(t *testing.T) {
t.Errorf("bad line fed to getProcessNamePid should return false but returned %v", couldParseLine)
}

correctTime, err := time.Parse(time.Stamp, "Jan 21 22:01:49")
const longForm = "Jan _2 15:04:05 2006"
correctTime, err := time.Parse(longForm, "Jan 21 22:01:49 2015")
couldParseLine, err = getProcessNamePid(endLine, currentOomInstance)
if err != nil {
t.Errorf("good line fed to getProcessNamePid should yield no error, but had error %v", err)
Expand All @@ -97,7 +100,7 @@ func TestGetProcessNamePid(t *testing.T) {
t.Errorf("getProcessNamePid should have set PID to 19667, not %d", currentOomInstance.Pid)
}
if !correctTime.Equal(currentOomInstance.TimeOfDeath) {
t.Errorf("getProcessNamePid should have set date to %v, not %v", correctTime, currentOomInstance.Pid)
t.Errorf("getProcessNamePid should have set date to %v, not %v", correctTime, currentOomInstance.TimeOfDeath)
}
}

Expand Down

0 comments on commit 5e61b39

Please sign in to comment.