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

Fix a few problems in 'podman logs --tail' with journald driver #12067

Merged
merged 1 commit into from
Oct 26, 2021

Conversation

hshiina
Copy link
Contributor

@hshiina hshiina commented Oct 23, 2021

Signed-off-by: Hironori Shiina [email protected]

What this PR does / why we need it:

The following problems regarding logs --tail with the journald log driver are fixed:

  • One more line than a specified value is displayed.
  • --tail 0 displays all lines while the other log drivers displays nothing.
  • Partial lines are not considered.
  • If the journald events backend is used and a container has exited, nothing is displayed.

Integration tests that should have detected the bugs are also fixed. The tests are executed with json-file log driver three times without this fix.

How to verify it

Run the fixed integration tests in test/e2e/logs_test.go.

Which issue(s) this PR fixes:

None

Special notes for your reviewer:

@umohnani8
Copy link
Member

@hshiina thanks for the fixes! But looks like the podman logs tests are unhappy.

Comment on lines 40 to 41
for _, log := range []string{"k8s-file", "journald", "json-file"} {

Copy link
Member

Choose a reason for hiding this comment

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

That is a good catch but the correct fix would be:

for _, log := range []string{"k8s-file", "journald", "json-file"} {
    log := log
}

This allows us to have one loop and have the log driver in the test name.

Having this loop inside the It() blocks would make it very hard to debug.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the advice!

@@ -121,7 +121,7 @@ func (c *Container) readFromJournal(ctx context.Context, options *logs.LogOption
}()

tailQueue := []*logs.LogLine{} // needed for options.Tail
doTail := options.Tail > 0
doTail := options.Tail >= 0
Copy link
Member

Choose a reason for hiding this comment

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

I am sure this should stay Tail > 0. If there are zero lines given we do not have to tail at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The existing integration test expects '--tail 0' to output nothing and the other log drivers do so. I would like to make the journald driver consistent with the others now though this behavior may not be useful.

Copy link
Member

Choose a reason for hiding this comment

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

OK, you are right. I thought the default value was 0 but it is -1.

@hshiina hshiina force-pushed the logs-journal-tail branch 2 times, most recently from df8c1f9 to 53adcd2 Compare October 25, 2021 21:57
@TomSweeneyRedHat
Copy link
Member

Changes LGTM. I'm on the fence about the > vs >= discussion.

@@ -38,8 +51,16 @@ var _ = Describe("Podman logs", func() {
})

for _, log := range []string{"k8s-file", "journald", "json-file"} {
log := log
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a comment here explaining that this is important to move log var to the correct scope.

The following problems regarding `logs --tail` with the journald log
driver are fixed:
- One more line than a specified value is displayed.
- '--tail 0' displays all lines while the other log drivers displays
  nothing.
- Partial lines are not considered.
- If the journald events backend is used and a container has exited,
  nothing is displayed.

Integration tests that should have detected the bugs are also fixed. The
tests are executed with json-file log driver three times without this
fix.

Signed-off-by: Hironori Shiina <[email protected]>
Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

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

LGTM

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Oct 26, 2021

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: hshiina, Luap99

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

The pull request process is described here

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 openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 26, 2021
@Luap99
Copy link
Member

Luap99 commented Oct 26, 2021

@containers/podman-maintainers PTAL

@rhatdan
Copy link
Member

rhatdan commented Oct 26, 2021

/lgtm
/hold

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 26, 2021
@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Oct 26, 2021
@TomSweeneyRedHat
Copy link
Member

/hold cancel

@openshift-ci openshift-ci bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 26, 2021
@openshift-merge-robot openshift-merge-robot merged commit 1243954 into containers:main Oct 26, 2021
@TomSweeneyRedHat
Copy link
Member

@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 22, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 22, 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants