Skip to content

Commit

Permalink
Improve container log streaming (#140)
Browse files Browse the repository at this point in the history
Co-authored-by: Luke Lombardi <[email protected]>
  • Loading branch information
luke-lombardi and Luke Lombardi authored Apr 16, 2024
1 parent d7ce31a commit 125077a
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions internal/worker/runc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"path/filepath"
"strings"
"syscall"
"time"

pb "github.com/beam-cloud/beta9/proto"

Expand Down Expand Up @@ -131,22 +132,28 @@ func (s *RunCServer) RunCStreamLogs(req *pb.RunCStreamLogsRequest, stream pb.Run
}

buffer := make([]byte, 4096)
logEntry := &pb.RunCLogEntry{}

for {
n, err := instance.LogBuffer.Read(buffer)
if err == io.EOF {
break
}

if err != nil {
return err
}

logEntry := &pb.RunCLogEntry{
Msg: string(buffer[:n]),
}
if n > 0 {
logEntry.Msg = string(buffer[:n])
if err := stream.Send(logEntry); err != nil {
return err
}

if err := stream.Send(logEntry); err != nil {
return err
continue
}

time.Sleep(time.Duration(100) * time.Millisecond)
}

return nil
Expand Down

0 comments on commit 125077a

Please sign in to comment.