small change to the way time is parsed from the kernel log in oomparser

small change to the way time is parsed from the kernel log in oomparser
This commit is contained in:
Katie Knister 2015-02-04 16:38:32 -08:00
parent 621045b4d0
commit 1291347c73
2 changed files with 10 additions and 5 deletions

View File

@ -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
}

View File

@ -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
@ -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
@ -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)
@ -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)
}
}