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 no logs in stdout/stderr if uses stdoutConfig #6162

Merged
merged 1 commit into from
Mar 28, 2023

Conversation

chengjoey
Copy link
Member

@chengjoey chengjoey commented Feb 14, 2023

Changes

fix #6136
used to only collect stdout and err to a file if the std{out/err}Path is specified, now add both os.std{out/err} and the std{out/err}Path to multiwriter to collect logs.

there is a full test to verify the stdoutConfig, in addition, this pr adds the verification of whether to print the log to standard output in the TestRealRunnerStdoutAndStderrPaths test

Submitter Checklist

As the author of this PR, please check off the items in this checklist:

  • Has Docs included if any changes are user facing
  • Has Tests included if any functionality added or changed
  • Follows the commit message standard
  • Meets the Tekton contributor standards (including
    functionality, content, code)
  • Has a kind label. You can add one by adding a comment on this PR that contains /kind <type>. Valid types are bug, cleanup, design, documentation, feature, flake, misc, question, tep
  • Release notes block below has been updated with any user facing changes (API changes, bug fixes, changes requiring upgrade notices or deprecation warnings)
  • Release notes contains the string "action required" if the change requires additional action from users switching to the new release

Release Notes

users can still view the output through the Pod log API if stdoutConfig.path or stderrConfig.path is specified

@tekton-robot tekton-robot added the release-note-none Denotes a PR that doesnt merit a release note. label Feb 14, 2023
@tekton-robot tekton-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Feb 14, 2023
@chengjoey
Copy link
Member Author

/kind bug

@tekton-robot tekton-robot added the kind/bug Categorizes issue or PR as related to a bug. label Feb 14, 2023
@chengjoey
Copy link
Member Author

/assign @wlynch
could you please take a review?🙏

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
cmd/entrypoint/runner.go 82.8% 83.3% 0.5

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage-df to re-run this coverage report

File Old Coverage New Coverage Delta
cmd/entrypoint/runner.go 82.8% 85.2% 2.4

Copy link
Member

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

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

This will probably need a release-note entry 👼🏼

@tekton-robot tekton-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-none Denotes a PR that doesnt merit a release note. labels Feb 14, 2023
@chengjoey
Copy link
Member Author

This will probably need a release-note entry 👼🏼

thanks @vdemeester , i added the release-note and marked the release-note checklist

@chengjoey
Copy link
Member Author

/test pull-tekton-pipeline-integration-tests

@afrittoli
Copy link
Member

@chengjoey thanks for this fix.

As you pointed out, there is a test for this, which was already succeeding, which unfortunately means there is full coverage for this change - it could be inadvertently broken again and the tests would not catch it.
Would it be possible to add test coverage to make sure we do not lose pod logs when using stdoutConfig?

@afrittoli
Copy link
Member

@wlynch it would be nice if you could review this one since you changed this code last 🙏

used to only collect stdout and err to a file if the std{out/err}Path is specified, now add both os.std{out/err} and the std{out/err}Path to multiwriter to collect logs
@tekton-robot tekton-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Feb 16, 2023
@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
cmd/entrypoint/runner.go 84.4% 83.3% -1.0

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage-df to re-run this coverage report

File Old Coverage New Coverage Delta
cmd/entrypoint/runner.go 84.4% 85.2% 0.8

@chengjoey
Copy link
Member Author

@chengjoey thanks for this fix.

As you pointed out, there is a test for this, which was already succeeding, which unfortunately means there is full coverage for this change - it could be inadvertently broken again and the tests would not catch it. Would it be possible to add test coverage to make sure we do not lose pod logs when using stdoutConfig?

Of course, i added verification in TestRealRunnerStdoutAndStderrPaths that whether realRunner print the log to std{out/err}. Thanks for the reminder, your advice is great!

Copy link
Member

@wlynch wlynch left a comment

Choose a reason for hiding this comment

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

One thing, otherwise LGTM!

Comment on lines +46 to +52
oldStdout := os.Stdout // keep backup of the real stdout
outReader, outWriter, _ := os.Pipe()
os.Stdout = outWriter

oldStderr := os.Stderr
errReader, errWriter, _ := os.Pipe()
os.Stderr = errWriter
Copy link
Member

Choose a reason for hiding this comment

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

This seems brittle since it modifies global state.

How about we:

  1. Modify realRunner to take in io.Writers
  2. Have main.go initialize the multiwriters if the flag is set.
  3. If the writers are nil, default to os.Stdout/Stderr

This way in tests we can just use a buffer and remove a bunch of the path manipulation?

Copy link
Member Author

Choose a reason for hiding this comment

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

The test here is to verify that logs can be printed to standard output. If you modify realRunner to accept io.Writers, you need to pass in os.stdout, which is the same as the current situation.

@chengjoey
Copy link
Member Author

/test pull-tekton-pipeline-alpha-integration-tests

@Yongxuanzhang
Copy link
Member

/assign

return nil, fmt.Errorf("error creating pipe: %w", err)
}

// be used for multiple streams if desired. note that close after use
Copy link
Member

Choose a reason for hiding this comment

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

Is this docstring missing after "note that close after use"?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not missing, I just modified the note here and added it to where it was used.
notes related to teaReader are no longer needed here

@tekton-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: vdemeester, Yongxuanzhang

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

@Yongxuanzhang
Copy link
Member

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Mar 28, 2023
@tekton-robot tekton-robot merged commit 1689636 into tektoncd:main Mar 28, 2023
@vdemeester
Copy link
Member

@chengjoey @pritidesai @jerop should this be cherry-picked in the latest LTS ? (0.41 and 0.44)

@chengjoey
Copy link
Member Author

/cherry-pick release-v0.41.x
/cherry-pick release-v0.42.x
/cherry-pick release-v0.43.x
/cherry-pick release-v0.44.x

@tekton-robot
Copy link
Collaborator

@chengjoey: #6162 failed to apply on top of branch "release-v0.41.x":

Applying: Fix no logs in stdout/stderr if uses stdoutConfig
Using index info to reconstruct a base tree...
M	cmd/entrypoint/runner.go
M	cmd/entrypoint/runner_test.go
Falling back to patching base and 3-way merge...
Auto-merging cmd/entrypoint/runner_test.go
CONFLICT (content): Merge conflict in cmd/entrypoint/runner_test.go
Auto-merging cmd/entrypoint/runner.go
CONFLICT (content): Merge conflict in cmd/entrypoint/runner.go
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0001 Fix no logs in stdout/stderr if uses stdoutConfig
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".

In response to this:

/cherry-pick release-v0.41.x
/cherry-pick release-v0.42.x
/cherry-pick release-v0.43.x
/cherry-pick release-v0.44.x

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.

chengjoey added a commit to chengjoey/pipeline that referenced this pull request Apr 6, 2023
…ektoncd#6162)

used to only collect stdout and err to a file if the std{out/err}Path is specified, now add both os.std{out/err} and the std{out/err}Path to multiwriter to collect logs

io/ioutil has been deprecaed in Go 1.16

Signed-off-by: chengjoey <zchengjoey@gmail.com>
@chengjoey
Copy link
Member Author

@chengjoey @pritidesai @jerop should this be cherry-picked in the latest LTS ? (0.41 and 0.44)

when i try to cherry-pick to 0.41, there are some conflicts, I manually submitted a hotfix pr, is this the correct hotfix process

tekton-robot pushed a commit that referenced this pull request Apr 6, 2023
…6162)

used to only collect stdout and err to a file if the std{out/err}Path is specified, now add both os.std{out/err} and the std{out/err}Path to multiwriter to collect logs

io/ioutil has been deprecaed in Go 1.16

Signed-off-by: chengjoey <zchengjoey@gmail.com>
@chengjoey
Copy link
Member Author

/cherry-pick release-v0.44.x

@tekton-robot
Copy link
Collaborator

@chengjoey: new pull request created: #6506

In response to this:

/cherry-pick release-v0.44.x

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/bug Categorizes issue or PR as related to a bug. lgtm Indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

No logs in stdout/stderr if uses stdoutConfig
6 participants