[client] Don't fail debug if log file is console (#3103)

This commit is contained in:
Viktor Liu 2024-12-24 15:05:23 +01:00 committed by GitHub
parent ad9f044aad
commit 0dbaddc7be
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -139,10 +139,6 @@ func (s *Server) DebugBundle(_ context.Context, req *proto.DebugBundleRequest) (
s.mutex.Lock() s.mutex.Lock()
defer s.mutex.Unlock() defer s.mutex.Unlock()
if s.logFile == "console" {
return nil, fmt.Errorf("log file is set to console, cannot create debug bundle")
}
bundlePath, err := os.CreateTemp("", "netbird.debug.*.zip") bundlePath, err := os.CreateTemp("", "netbird.debug.*.zip")
if err != nil { if err != nil {
return nil, fmt.Errorf("create zip file: %w", err) return nil, fmt.Errorf("create zip file: %w", err)
@ -185,6 +181,30 @@ func (s *Server) createArchive(bundlePath *os.File, req *proto.DebugBundleReques
} }
if req.GetSystemInfo() { if req.GetSystemInfo() {
s.addSystemInfo(req, anonymizer, archive)
}
if err := s.addNetworkMap(req, anonymizer, archive); err != nil {
return fmt.Errorf("add network map: %w", err)
}
if err := s.addStateFile(req, anonymizer, archive); err != nil {
log.Errorf("Failed to add state file to debug bundle: %v", err)
}
if s.logFile != "console" {
if err := s.addLogfile(req, anonymizer, archive); err != nil {
return fmt.Errorf("add log file: %w", err)
}
}
if err := archive.Close(); err != nil {
return fmt.Errorf("close archive writer: %w", err)
}
return nil
}
func (s *Server) addSystemInfo(req *proto.DebugBundleRequest, anonymizer *anonymize.Anonymizer, archive *zip.Writer) {
if err := s.addRoutes(req, anonymizer, archive); err != nil { if err := s.addRoutes(req, anonymizer, archive); err != nil {
log.Errorf("Failed to add routes to debug bundle: %v", err) log.Errorf("Failed to add routes to debug bundle: %v", err)
} }
@ -198,24 +218,6 @@ func (s *Server) createArchive(bundlePath *os.File, req *proto.DebugBundleReques
} }
} }
if err := s.addNetworkMap(req, anonymizer, archive); err != nil {
return fmt.Errorf("add network map: %w", err)
}
if err := s.addStateFile(req, anonymizer, archive); err != nil {
log.Errorf("Failed to add state file to debug bundle: %v", err)
}
if err := s.addLogfile(req, anonymizer, archive); err != nil {
return fmt.Errorf("add log file: %w", err)
}
if err := archive.Close(); err != nil {
return fmt.Errorf("close archive writer: %w", err)
}
return nil
}
func (s *Server) addReadme(req *proto.DebugBundleRequest, archive *zip.Writer) error { func (s *Server) addReadme(req *proto.DebugBundleRequest, archive *zip.Writer) error {
if req.GetAnonymize() { if req.GetAnonymize() {
readmeReader := strings.NewReader(readmeContent) readmeReader := strings.NewReader(readmeContent)