Skip to content

Commit

Permalink
command/debug: pprof needs to create its directory
Browse files Browse the repository at this point in the history
  • Loading branch information
langmartin committed Jul 20, 2020
1 parent a43ecea commit c9cf971
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
4 changes: 4 additions & 0 deletions command/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,10 @@ func (c *DebugCommand) collectPprof(path, id string, client *api.Client) {
}

path = filepath.Join(path, id)
err := c.mkdir(path)
if err != nil {
return
}

bs, err := client.Agent().CPUProfile(opts, nil)
if err == nil {
Expand Down
19 changes: 8 additions & 11 deletions command/debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,17 @@ func TestDebugCapturedFiles(t *testing.T) {
ui := new(cli.MockUi)
cmd := &DebugCommand{Meta: Meta{Ui: ui}}

// Calculate the output name
format := "2006-01-02-150405Z"
stamped := "nomad-debug-" + time.Now().UTC().Format(format)
path := filepath.Join(os.TempDir(), stamped)
defer os.Remove(path)

code := cmd.Run([]string{
"-address", url,
"-output", os.TempDir(),
"-server-id", "leader",
"-duration", "1s",
"-interval", "500ms",
"-interval", "600ms",
})

path := cmd.collectDir
defer os.Remove(path)

require.Empty(t, ui.ErrorWriter.String())
require.Equal(t, 0, code)
ui.ErrorWriter.Reset()
Expand All @@ -106,10 +103,10 @@ func TestDebugCapturedFiles(t *testing.T) {
require.FileExists(t, filepath.Join(path, "server", "leader", "goroutine.prof"))

// Multiple snapshots are collected, 00 is always created
require.FileExists(t, filepath.Join(path, "nomad", "00", "jobs.json"))
require.FileExists(t, filepath.Join(path, "nomad", "00", "nodes.json"))
require.FileExists(t, filepath.Join(path, "nomad", "0000", "jobs.json"))
require.FileExists(t, filepath.Join(path, "nomad", "0000", "nodes.json"))

// Multiple snapshots are collected, 01 requires two intervals
require.FileExists(t, filepath.Join(path, "nomad", "01", "jobs.json"))
require.FileExists(t, filepath.Join(path, "nomad", "01", "nodes.json"))
require.FileExists(t, filepath.Join(path, "nomad", "0001", "jobs.json"))
require.FileExists(t, filepath.Join(path, "nomad", "0001", "nodes.json"))
}

0 comments on commit c9cf971

Please sign in to comment.