Skip to content

Commit

Permalink
add err check for logstreamer
Browse files Browse the repository at this point in the history
  • Loading branch information
kenanfarukcakir committed Mar 21, 2024
1 parent 67fb831 commit 39715ef
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
10 changes: 6 additions & 4 deletions logstreamer/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type fileReader struct {
*bufio.Reader
}

func NewLogStreamer(ctx context.Context, critool *cri.CRITool) *LogStreamer {
func NewLogStreamer(ctx context.Context, critool *cri.CRITool) (*LogStreamer, error) {
ls := &LogStreamer{
critool: critool,
}
Expand All @@ -58,12 +58,14 @@ func NewLogStreamer(ctx context.Context, critool *cri.CRITool) *LogStreamer {
ls.connPool = connPool

if err != nil {
log.Logger.Fatal().Err(err).Msg("failed to create connection pool")
log.Logger.Error().Err(err).Msg("failed to create connection pool")
return nil, err
}

watcher, err := fsnotify.NewWatcher()
if err != nil {
log.Logger.Fatal().Err(err).Msg("failed to create fsnotify watcher")
log.Logger.Error().Err(err).Msg("failed to create fsnotify watcher")
return nil, err
}
ls.watcher = watcher

Expand All @@ -79,7 +81,7 @@ func NewLogStreamer(ctx context.Context, critool *cri.CRITool) *LogStreamer {
ls.logPathToContainerMeta = make(map[string]string, 0)
ls.containerIdToLogPath = make(map[string]string, 0)

return ls
return ls, nil
}

func (ls *LogStreamer) Done() chan struct{} {
Expand Down
18 changes: 11 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,17 @@ func main() {

var ls *logstreamer.LogStreamer
if logsEnabled && ct != nil {
ls = logstreamer.NewLogStreamer(ctx, ct)
go func() {
err := ls.StreamLogs()
if err != nil {
log.Logger.Error().Err(err).Msg("failed to stream logs")
}
}()
ls, err = logstreamer.NewLogStreamer(ctx, ct)
if err != nil {
log.Logger.Error().Err(err).Msg("failed to create logstreamer")
} else {
go func() {
err := ls.StreamLogs()
if err != nil {
log.Logger.Error().Err(err).Msg("failed to stream logs")
}
}()
}
}

go http.ListenAndServe(":8181", nil)
Expand Down

0 comments on commit 39715ef

Please sign in to comment.