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

VAULT-12732: Add Heap Profiling Option to Vault Server Command Line #27033

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

ltcarbonell
Copy link
Contributor

@ltcarbonell ltcarbonell commented May 15, 2024

Background

Currently, we utilize sys/pprof and/or vault debug to generate pprof dumps for performance and debugging purposes. However, these tools are not effective if the issue we want to investigate occurs during the startup phase, or if Vault exits too quickly to issue such requests.

Objective

To address this limitation, this PR introduces a new command-line option to Vault that allows specifying a file path to generate a heap profile dump at startup. This enhancement is intended to facilitate debugging in scenarios where Vault starts and exits rapidly, making it challenging to use the existing profiling tools.

Implementation

New Command-Line Option: -pprof-dump-dir=/path/to/dir

  • This option allows users to specify the file path where the heap profile dump should be saved.
  • The heap profile will be generated and saved at the specified path during the startup process.

Usage: This is a one-off option and does not require HCL configuration. It is intended for temporary use during debugging sessions and not for repeated or regular use.

Example

To start the Vault server and generate a heap profile dump, use the following command:

vault server -pprof-dump-dir=/path/to/dir

@ltcarbonell ltcarbonell requested a review from a team as a code owner May 15, 2024 12:30
@github-actions github-actions bot added the hashicorp-contributed-pr If the PR is HashiCorp (i.e. not-community) contributed label May 15, 2024
Copy link

github-actions bot commented May 15, 2024

CI Results:
All Go tests succeeded! ✅

Copy link

Build Results:
All builds succeeded! ✅

@ltcarbonell ltcarbonell requested a review from a team May 23, 2024 15:19
website/content/docs/commands/server.mdx Outdated Show resolved Hide resolved
Copy link
Contributor

@schavis schavis left a comment

Choose a reason for hiding this comment

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

Content LGTM

c.logger.Info(fmt.Sprintf("Wrote pprof files to: %s", pprofPath))
case <-heapProfCh:
path := c.flagHeapProfile
if _, err := os.Stat(path); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this going to error if the path to save the files in doesn't exist, which means we never make it to line 1832 below, where you're creating the new directory?

Off the cuff, it feels like we need 3 different branches of logic here:

  • err is nil, meaning the path exists, so that's where we put the files
  • err is not nil but the error is ErrNotExist, which is fine, and not actually an error case for us, in which case we need to create the directory
  • err is not nil and is also not ErrNotExist, meaning there's some legitimate error that will prevent this process from continuing, in which case we need to exit early.

Am I misunderstanding this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a check for ErrNotExist, I was previously lumping case 2 and 3 together.

@@ -1809,6 +1821,49 @@ func (c *ServerCommand) Run(args []string) int {
pFile.Close()
}

c.logger.Info(fmt.Sprintf("Wrote pprof files to: %s", pprofPath))
Copy link
Contributor

Choose a reason for hiding this comment

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

It feels like this log message would be better moved to inside the case statement, after everything has completed, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is actually an already existing log from the case above (git doing some interesting diffing here). I will add something to the message however, so that the two log messages aren't identical.

continue
}

dumps := []string{"goroutine", "heap", "allocs", "threadcreate", "profile"}
Copy link
Contributor

Choose a reason for hiding this comment

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

The command line flag references "heap profile" but we're actually writing out many profiles here. Maybe it would be a good idea to rename the CLI flag to better reflect what we're actually doing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hashicorp-contributed-pr If the PR is HashiCorp (i.e. not-community) contributed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants