[client] Add heap profile to debug bundle (#3679)

This commit is contained in:
Viktor Liu 2025-04-15 11:36:41 +02:00 committed by GitHub
parent 51bb52cdf5
commit b165f63327
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -34,7 +34,8 @@ import (
)
const readmeContent = `Netbird debug bundle
This debug bundle contains the following files:
This debug bundle contains the following files.
If the --anonymize flag is set, the files are anonymized to protect sensitive information.
status.txt: Anonymized status information of the NetBird client.
client.log: Most recent, anonymized client log file of the NetBird client.
@ -50,6 +51,7 @@ state.json: Anonymized client state dump containing netbird states.
mutex.prof: Mutex profiling information.
goroutine.prof: Goroutine profiling information.
block.prof: Block profiling information.
heap.prof: Heap profiling information (snapshot of memory allocations).
Anonymization Process
@ -92,11 +94,14 @@ The state file follows the same anonymization rules as other files:
- Domain names are consistently anonymized
- Technical identifiers and non-sensitive data remain unchanged
Mutex, Goroutines, and Block Profiling Files
The goroutine, block, and mutex profiling files contains process information that might help the NetBird team diagnose performance issues. The information in these files don't contain personal data.
Mutex, Goroutines, Block, and Heap Profiling Files
The goroutine, block, mutex, and heap profiling files contain process information that might help the NetBird team diagnose performance or memory issues. The information in these files doesn't contain personal data.
You can check each using the following go command:
go tool pprof -http=:8088 mutex.prof
go tool pprof -http=:8088 <profile_name>.prof
For example, to view the heap profile:
go tool pprof -http=:8088 heap.prof
This will open a web browser tab with the profiling information.
@ -180,7 +185,7 @@ func (s *Server) DebugBundle(_ context.Context, req *proto.DebugBundleRequest) (
func (s *Server) createArchive(bundlePath *os.File, req *proto.DebugBundleRequest) error {
archive := zip.NewWriter(bundlePath)
if err := s.addReadme(req, archive); err != nil {
if err := s.addReadme(archive); err != nil {
return fmt.Errorf("add readme: %w", err)
}
@ -242,12 +247,10 @@ func (s *Server) addSystemInfo(req *proto.DebugBundleRequest, anonymizer *anonym
}
}
func (s *Server) addReadme(req *proto.DebugBundleRequest, archive *zip.Writer) error {
if req.GetAnonymize() {
readmeReader := strings.NewReader(readmeContent)
if err := addFileToZip(archive, readmeReader, "README.txt"); err != nil {
return fmt.Errorf("add README file to zip: %w", err)
}
func (s *Server) addReadme(archive *zip.Writer) error {
readmeReader := strings.NewReader(readmeContent)
if err := addFileToZip(archive, readmeReader, "README.txt"); err != nil {
return fmt.Errorf("add README file to zip: %w", err)
}
return nil
}
@ -334,7 +337,7 @@ func (s *Server) addProf(req *proto.DebugBundleRequest, anonymizer *anonymize.An
time.Sleep(5 * time.Second)
for _, profile := range []string{"goroutine", "block", "mutex"} {
for _, profile := range []string{"goroutine", "block", "mutex", "heap"} {
var buff []byte
myBuff := bytes.NewBuffer(buff)
err := pprof.Lookup(profile).WriteTo(myBuff, 0)