-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Add log gathering to debug command. #10609
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a601e8b
Add log gathering to debug command.
ncabatoff 209fe53
Fix test failure, and make the debug command succeed even if log gath…
ncabatoff 8a03884
Add CL entry.
ncabatoff f62976c
Close output file.
ncabatoff e2e613d
Don't treat a nil read from the log ch as a failure.
ncabatoff File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -169,7 +169,7 @@ func (c *DebugCommand) Flags() *FlagSets { | |
Usage: "Target to capture, defaulting to all if none specified. " + | ||
"This can be specified multiple times to capture multiple targets. " + | ||
"Available targets are: config, host, metrics, pprof, " + | ||
"replication-status, server-status.", | ||
"replication-status, server-status, log.", | ||
}) | ||
|
||
return set | ||
|
@@ -477,7 +477,7 @@ func (c *DebugCommand) preflight(rawArgs []string) (string, error) { | |
} | ||
|
||
func (c *DebugCommand) defaultTargets() []string { | ||
return []string{"config", "host", "metrics", "pprof", "replication-status", "server-status"} | ||
return []string{"config", "host", "metrics", "pprof", "replication-status", "server-status", "log"} | ||
} | ||
|
||
func (c *DebugCommand) captureStaticTargets() error { | ||
|
@@ -513,6 +513,7 @@ func (c *DebugCommand) capturePollingTargets() error { | |
var g run.Group | ||
|
||
ctx, cancelFunc := context.WithTimeout(context.Background(), c.flagDuration+debugDurationGrace) | ||
defer cancelFunc() | ||
|
||
// This run group watches for interrupt or duration | ||
g.Add(func() error { | ||
|
@@ -576,6 +577,15 @@ func (c *DebugCommand) capturePollingTargets() error { | |
}) | ||
} | ||
|
||
if strutil.StrListContains(c.flagTargets, "log") { | ||
g.Add(func() error { | ||
_ = c.writeLogs(ctx) | ||
return nil | ||
}, func(error) { | ||
cancelFunc() | ||
}) | ||
} | ||
|
||
// We shouldn't bump across errors since none is returned by the interrupts, | ||
// but we error check for sanity here. | ||
if err := g.Run(); err != nil { | ||
|
@@ -981,3 +991,29 @@ func (c *DebugCommand) captureError(target string, err error) { | |
}) | ||
c.errLock.Unlock() | ||
} | ||
|
||
func (c *DebugCommand) writeLogs(ctx context.Context) error { | ||
out, err := os.Create(filepath.Join(c.flagOutput, "vault.log")) | ||
if err != nil { | ||
return err | ||
} | ||
logCh, err := c.cachedClient.Sys().Monitor(ctx, "trace") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for { | ||
select { | ||
case log, ok := <-logCh: | ||
if !ok { | ||
return nil | ||
} | ||
_, err = out.WriteString(log) | ||
if err != nil { | ||
return err | ||
} | ||
case <-ctx.Done(): | ||
return nil | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What causes this loop to terminate other than errors? I don't think the context will time out, will it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, the context passed in has a timeout. |
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Do we need to close
out
?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.
D'oh, ty!