-
Notifications
You must be signed in to change notification settings - Fork 288
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
Save CLI log output to file included in support bundle #4289
Conversation
Skipping CI for Draft Pull Request. |
Codecov Report
@@ Coverage Diff @@
## main #4289 +/- ##
==========================================
+ Coverage 68.61% 68.70% +0.09%
==========================================
Files 406 408 +2
Lines 33086 33310 +224
==========================================
+ Hits 22701 22886 +185
- Misses 8933 8969 +36
- Partials 1452 1455 +3
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
6379b93
to
9dfc2b8
Compare
\hold |
f8402cb
to
1e4143f
Compare
\unhold |
1e4143f
to
2a7c980
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Is there a requirement to store the logs in memory? Or is that just an implementation detail.
- Do we need this log dump always or should be just do it selectively where we need it (CLI commands for example)?
- How does this solve the interrupted SSH connection? It seems like we are only reading the in memory logs when the support bundle report is triggered. And that only happens if the CLI execution is maintained uninterrupted and only after a CLI error happens. If the SSH connection is dropped and the process is interrupted, the support bundle won't be created and there won't be any logs. TBH, the solution to this problem should be to use tmux or screen, SSH connections are out of the CLI's domain of responsibility, so any SSH associated issue should be solved with SSH tools. But you described that situation in your problem statement and I don't think this code solves that usecase.
Wouldn't this be simpler if we use config.OutputPaths
?
Yeah from the conversation between @cxbrowne1207 and myself, the original impetus for this work was #1703; but the ticket over-states the importance of perserving the connection when SSH is used, and the real value is 'how do we get the CLI logs into the support bundle' rather than 'how do we maintain the session when closed'; I think that maybe we need to revisit the description, but the value of doing this as a way to get the CLI output into the support bundle stands IMO. Agree tho re: customer should be using |
It's only an implementation detail, the goal is to have the logs to be ultimately stored in the support bundle it seems. As mentioned @danbudris mentioned, the original ticket was used for as a basis for the description, but there's a mismatch with the goal of saving the logs to the support bundle as it doesn't solve the SSH connection issue. So, the PR description is a mistake. Will update. I guess the question is now whether or not the solution is too complex and if the same thing can be done with |
Using
|
This seems reasonable to me; from looking at the docs and some quick googling this seems like the recommended approach. |
For the record, there was quorum since I voted option 2 offline as well :) |
2a7c980
to
fb189b0
Compare
c90bf8e
to
0ca4492
Compare
pkg/logger/config.go
Outdated
} | ||
|
||
// Build constructs a logger and returns a logger. | ||
func (cfg Config) Build() (*zap.Logger, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exported?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was exported mainly so that it could be accessed it from the tests.
pkg/logger/logger.go
Outdated
l logr.Logger = logr.Discard() | ||
once sync.Once | ||
outputFilename string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should think about grouping these 3 (or at least the logger and output file) in a struct
Can be a follow up
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed
@@ -32,7 +33,11 @@ func rootPersistentPreRun(cmd *cobra.Command, args []string) { | |||
} | |||
|
|||
func initLogger() error { | |||
if err := logger.InitZap(viper.GetInt("verbosity")); err != nil { | |||
outputFilePath := fmt.Sprintf("./eksa-cli-%s.log", time.Now().Format("2006-01-02T15_04_05")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we look into deleting this file after a successful cli operation?
pkg/logger/zap.go
Outdated
opt(&logr) | ||
|
||
for _, name := range args.WithNames { | ||
WithName(name)(&logr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
WithName(name)(&logr) | |
logr = logr.WithName(name) |
I think it's a bit more readable? Unless I'm missing something
b50f417
to
6bef564
Compare
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: cxbrowne1207 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 |
/unhold |
Issue #, if available:
Description of changes:
This PR customizes the zap logger to log verbose logs to a file, and then include a copy of it in the support bundles when one is generated. This offers an easier way for the customer recover CLI run logs for debugging, when there are errors and interruptions of some kind.
Testing (if applicable):
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.