Skip to content

Commit

Permalink
- Updated the condition to perform a case-insensitive check for log m…
Browse files Browse the repository at this point in the history
…essages

- Add sync and increase timeout for test

Signed-off-by: Fluder-Paradyne <[email protected]>
  • Loading branch information
Fluder-Paradyne committed Dec 29, 2024
1 parent 9eccac9 commit c1f1255
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
3 changes: 1 addition & 2 deletions server/application/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ func parseLogsStream(podName string, stream io.ReadCloser, ch chan logEntry) {
timeStampStr := parts[0]
logTime, err := time.Parse(time.RFC3339Nano, timeStampStr)
if err != nil {
if strings.HasPrefix(line, "unable to retrieve container logs for ") ||
strings.HasPrefix(line, "Unable to retrieve container logs for ") {
if strings.HasPrefix(strings.ToLower(line), "unable to retrieve container logs for ") {
ch <- logEntry{line: line, podName: podName, timeStamp: time.Now()}
break
}
Expand Down
11 changes: 9 additions & 2 deletions server/application/logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,20 +110,27 @@ func TestParseLogsStream_ContainerLogRetrievalMessage(t *testing.T) {
r := io.NopCloser(strings.NewReader(`unable to retrieve container logs for containerd://2c7e54dbbfef27148d5`))

res := make(chan logEntry)
done := make(chan struct{})

go func() {
parseLogsStream("test", r, res)
close(res)
close(done)
}()

var entries []logEntry
for entry := range res {
entries = append(entries, entry)
}

// Wait for parseLogsStream to complete
<-done

require.Len(t, entries, 1)

assert.Equal(t, "unable to retrieve container logs for containerd://2c7e54dbbfef27148d5", entries[0].line)
assert.Equal(t, "test", entries[0].podName)
// Verify timestamp is recent (within last second)
assert.Less(t, time.Since(entries[0].timeStamp), time.Second)

// Verify timestamp is recent (within last 5 seconds)
assert.Less(t, time.Since(entries[0].timeStamp), 5*time.Second)
}

0 comments on commit c1f1255

Please sign in to comment.