Skip to content

Stop following logs using timers#6702

Merged
openshift-merge-robot merged 3 commits into
containers:masterfrom
jgallucci32:follow-logs-poll
Jun 22, 2020
Merged

Stop following logs using timers#6702
openshift-merge-robot merged 3 commits into
containers:masterfrom
jgallucci32:follow-logs-poll

Conversation

@jgallucci32
Copy link
Copy Markdown
Contributor

@jgallucci32 jgallucci32 commented Jun 20, 2020

This incorporates code from PR #6591 and #6614 but does not use
event channels to detect container state and rather uses timers
with a defined wait duration before calling t.StopAtEOF() to
ensure the last log entry is output before a container exits.

The polling interval is set to 250 milliseconds based on polling
interval defined in hpcloud/tail here:
https://github.com/hpcloud/tail/blob/v1.0.0/watch/polling.go#L117

Close #6531

Co-authored-by: Qi Wang qiwan@redhat.com
Signed-off-by: jgallucci32 john.gallucci.iv@gmail.com

This incorporates code from PR #6591 and #6614 but does not use
event channels to detect container state and rather uses timers
with a defined wait duration before calling t.StopAtEOF() to
ensure the last log entry is output before a container exits.

The polling interval is set to 250 milliseconds based on polling
interval defined in hpcloud/tail here:
https://github.com/hpcloud/tail/blob/v1.0.0/watch/polling.go#L117

Co-authored-by: Qi Wang <qiwan@redhat.com>
Signed-off-by: jgallucci32 <john.gallucci.iv@gmail.com>
@openshift-ci-robot
Copy link
Copy Markdown
Collaborator

Hi @jgallucci32. Thanks for your PR.

I'm waiting for a containers member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@openshift-ci-robot openshift-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jun 20, 2020
@jgallucci32
Copy link
Copy Markdown
Contributor Author

/assign @vrothberg

@jgallucci32
Copy link
Copy Markdown
Contributor Author

@mheon @TomSweeneyRedHat @QiWang19 @edsantiago PTAL

This passed all checks first go around. The key difference with this PR is I removed the dependency on the external event module and it now runs independently using timers. To get the timing precise it needed to match the polling interval defined in hpcloud/tail here:
https://github.com/hpcloud/tail/blob/v1.0.0/watch/polling.go#L117

func init() {
	POLL_DURATION = 250 * time.Millisecond
}

Additionally it needed to ensure when the container changes state, the 250 milisecond delay is applied before calling StopAtEOF() to avoid the race condition where the tailing stops before the last entry is output to stdout.

Comment thread libpod/container_log.go Outdated
Signed-off-by: jgallucci32 <john.gallucci.iv@gmail.com>
@rhatdan
Copy link
Copy Markdown
Member

rhatdan commented Jun 22, 2020

LGTM
@edsantiago @giuseppe @vrothberg @mheon @baude PTAL

Comment thread libpod/container_log.go
go func() {
for {
state, err := c.State()
time.Sleep(watch.POLL_DURATION)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

is there any reason why we do a Sleep before checking for the error? Should the Sleep happen later?

Copy link
Copy Markdown
Contributor Author

@jgallucci32 jgallucci32 Jun 22, 2020

Choose a reason for hiding this comment

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

Yes. Under all conditions you must call stopAtEOF() when exiting the subroutine in order to break the infinite wait state t.Lines in the other subroutine. You must also wait up to the POLL_DURATION before calling stopAtEOF() or else you may run into the condition where the container has exited or does not exist and t.Lines is still polling for changes to the log file.

If you check commit 8926e1f you will see there originally was 3 sleep statements, 2 of them after the if condition. This was refactored as there is no logical difference between calling sleep first at the beginning versus calling it after the conditional statements and at the end of the entire loop.

Comment thread test/e2e/logs_test.go Outdated
Signed-off-by: jgallucci32 <john.gallucci.iv@gmail.com>
@jgallucci32 jgallucci32 requested a review from edsantiago June 22, 2020 15:36
Copy link
Copy Markdown
Member

@edsantiago edsantiago left a comment

Choose a reason for hiding this comment

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

LGTM

@mheon
Copy link
Copy Markdown
Member

mheon commented Jun 22, 2020

/ok-to-test
/approve

@openshift-ci-robot openshift-ci-robot added ok-to-test and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jun 22, 2020
@openshift-ci-robot
Copy link
Copy Markdown
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: edsantiago, jgallucci32, mheon

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 22, 2020
@mheon
Copy link
Copy Markdown
Member

mheon commented Jun 22, 2020

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Jun 22, 2020
@openshift-merge-robot openshift-merge-robot merged commit 11dd5f5 into containers:master Jun 22, 2020
@jgallucci32 jgallucci32 deleted the follow-logs-poll branch June 22, 2020 17:33
@github-actions github-actions Bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 24, 2023
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Sep 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. ok-to-test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

podman logs -f continues indefinitely on a stopped container

8 participants