Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

logs: k8s-file: restore poll sleep #10742

Merged
merged 2 commits into from
Jun 21, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions libpod/container_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import (
"context"
"fmt"
"os"
"time"

"github.com/containers/podman/v3/libpod/define"
"github.com/containers/podman/v3/libpod/events"
"github.com/containers/podman/v3/libpod/logs"
"github.com/hpcloud/tail/watch"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
Expand Down Expand Up @@ -74,7 +76,7 @@ func (c *Container) readFromLogFile(ctx context.Context, options *logs.LogOption
}
nll, err := logs.NewLogLine(line.Text)
if err != nil {
logrus.Error(err)
logrus.Errorf("Error getting new log line: %v", err)
continue
}
if nll.Partial() {
Expand All @@ -93,17 +95,20 @@ func (c *Container) readFromLogFile(ctx context.Context, options *logs.LogOption
}()
// Check if container is still running or paused
if options.Follow {
// If the container isn't running or if we encountered an error
// getting its state, instruct the logger to read the file
// until EOF.
state, err := c.State()
if err != nil || state != define.ContainerStateRunning {
// If the container isn't running or if we encountered
// an error getting its state, instruct the logger to
// read the file until EOF.
// Make sure to wait at least for the poll duration
// before stopping the file logger (see #10675).
time.Sleep(watch.POLL_DURATION)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm always worried about putting a hard sleep into a function like this, but I'm not thinking of a better way atm.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. I really did not like it which is why I removed it previously. I read the docs of the library we're using but they did not reflect reality :(

tailError := t.StopAtEOF()
if tailError != nil && fmt.Sprintf("%v", tailError) != "tail: stop at eof" {
logrus.Error(tailError)
logrus.Errorf("Error stopping logger: %v", tailError)
}
if errors.Cause(err) != define.ErrNoSuchCtr {
logrus.Error(err)
if err != nil && errors.Cause(err) != define.ErrNoSuchCtr {
logrus.Errorf("Error getting container state: %v", err)
}
return nil
}
Expand All @@ -124,9 +129,12 @@ func (c *Container) readFromLogFile(ctx context.Context, options *logs.LogOption
// Now wait for the died event and signal to finish
// reading the log until EOF.
<-eventChannel
// Make sure to wait at least for the poll duration
// before stopping the file logger (see #10675).
time.Sleep(watch.POLL_DURATION)
tailError := t.StopAtEOF()
if tailError != nil && fmt.Sprintf("%v", tailError) != "tail: stop at eof" {
logrus.Error(tailError)
logrus.Errorf("Error stopping logger: %v", tailError)
}
}()
}
Expand Down