in logger/common.go [465:487]
func readFromContainerPipe(pipe io.Reader, buf []byte, bytesInBuffer, maxReadBytes int) (bool, int, error) {
// eof indicates if we have already met EOF error.
eof := false
// Decide how many bytes we can read from container pipe for this iteration. It's either
// the current bytes in buffer plus 2048 bytes or the available spaces left, whichever is
// smaller.
readBytesUpto := int(math.Min(float64(bytesInBuffer+maxReadBytes), float64(cap(buf))))
// Read logs from container pipe if there are available spaces for new log messages.
if readBytesUpto > bytesInBuffer {
readBytesFromPipe, err := pipe.Read(buf[bytesInBuffer:readBytesUpto])
if err != nil {
if err != io.EOF {
return false, bytesInBuffer, fmt.Errorf("failed to read log stream from container pipe: %w", err)
}
// Pipe is closed, set flag to true.
eof = true
}
atomic.AddUint64(&bytesReadFromSrc, uint64(readBytesFromPipe))
bytesInBuffer += readBytesFromPipe
}
return eof, bytesInBuffer, nil
}