Add SIGUSR2 pprof to agent and proxy (#27510)

* Add SIGUSR2 pprof to agent

* changelog

* Update command/agent.go

Co-authored-by: Violet Hynes <violet.hynes@hashicorp.com>

* Update command/agent.go

Co-authored-by: Violet Hynes <violet.hynes@hashicorp.com>

* Add to proxy, update tests

* Fix path

* Changelog

* dry

* choose one error style

---------

Co-authored-by: Violet Hynes <violet.hynes@hashicorp.com>
This commit is contained in:
Jason O'Donnell
2024-06-17 13:10:00 -04:00
committed by GitHub
parent 299cd3d1f7
commit fe1f36a1dc
8 changed files with 76 additions and 31 deletions

View File

@@ -13,6 +13,7 @@ import (
"net"
"net/http"
"os"
"path/filepath"
"sort"
"strings"
"sync"
@@ -74,6 +75,7 @@ type AgentCommand struct {
ShutdownCh chan struct{}
SighupCh chan struct{}
SigUSR2Ch chan struct{}
tlsReloadFuncsLock sync.RWMutex
tlsReloadFuncs []reloadutil.ReloadFunc
@@ -758,6 +760,16 @@ func (c *AgentCommand) Run(args []string) int {
case c.reloadedCh <- struct{}{}:
default:
}
case <-c.SigUSR2Ch:
pprofPath := filepath.Join(os.TempDir(), "vault-agent-pprof")
cpuProfileDuration := time.Second * 1
err := WritePprofToFile(pprofPath, cpuProfileDuration)
if err != nil {
c.logger.Error(err.Error())
continue
}
c.logger.Info(fmt.Sprintf("Wrote pprof files to: %s", pprofPath))
case <-ctx.Done():
return nil
}