@@ -24,9 +24,10 @@ import (
2424
2525// Initial state for the debug collection
2626type debugInitialState struct {
27- wasDown bool
28- logLevel proto.LogLevel
29- isLevelTrace bool
27+ wasDown bool
28+ needsRestoreUp bool
29+ logLevel proto.LogLevel
30+ isLevelTrace bool
3031}
3132
3233// Debug collection parameters
@@ -371,46 +372,51 @@ func (s *serviceClient) configureServiceForDebug(
371372 conn proto.DaemonServiceClient ,
372373 state * debugInitialState ,
373374 enablePersistence bool ,
374- ) error {
375+ ) {
375376 if state .wasDown {
376377 if _ , err := conn .Up (s .ctx , & proto.UpRequest {}); err != nil {
377- return fmt .Errorf ("bring service up: %v" , err )
378+ log .Warnf ("failed to bring service up: %v" , err )
379+ } else {
380+ log .Info ("Service brought up for debug" )
381+ time .Sleep (time .Second * 10 )
378382 }
379- log .Info ("Service brought up for debug" )
380- time .Sleep (time .Second * 10 )
381383 }
382384
383385 if ! state .isLevelTrace {
384386 if _ , err := conn .SetLogLevel (s .ctx , & proto.SetLogLevelRequest {Level : proto .LogLevel_TRACE }); err != nil {
385- return fmt .Errorf ("set log level to TRACE: %v" , err )
387+ log .Warnf ("failed to set log level to TRACE: %v" , err )
388+ } else {
389+ log .Info ("Log level set to TRACE for debug" )
386390 }
387- log .Info ("Log level set to TRACE for debug" )
388391 }
389392
390393 if _ , err := conn .Down (s .ctx , & proto.DownRequest {}); err != nil {
391- return fmt .Errorf ("bring service down: %v" , err )
394+ log .Warnf ("failed to bring service down: %v" , err )
395+ } else {
396+ state .needsRestoreUp = ! state .wasDown
397+ time .Sleep (time .Second )
392398 }
393- time .Sleep (time .Second )
394399
395400 if enablePersistence {
396401 if _ , err := conn .SetSyncResponsePersistence (s .ctx , & proto.SetSyncResponsePersistenceRequest {
397402 Enabled : true ,
398403 }); err != nil {
399- return fmt .Errorf ("enable sync response persistence: %v" , err )
404+ log .Warnf ("failed to enable sync response persistence: %v" , err )
405+ } else {
406+ log .Info ("Sync response persistence enabled for debug" )
400407 }
401- log .Info ("Sync response persistence enabled for debug" )
402408 }
403409
404410 if _ , err := conn .Up (s .ctx , & proto.UpRequest {}); err != nil {
405- return fmt .Errorf ("bring service back up: %v" , err )
411+ log .Warnf ("failed to bring service back up: %v" , err )
412+ } else {
413+ state .needsRestoreUp = false
414+ time .Sleep (time .Second * 3 )
406415 }
407- time .Sleep (time .Second * 3 )
408416
409417 if _ , err := conn .StartCPUProfile (s .ctx , & proto.StartCPUProfileRequest {}); err != nil {
410418 log .Warnf ("failed to start CPU profiling: %v" , err )
411419 }
412-
413- return nil
414420}
415421
416422func (s * serviceClient ) collectDebugData (
@@ -424,9 +430,7 @@ func (s *serviceClient) collectDebugData(
424430 var wg sync.WaitGroup
425431 startProgressTracker (ctx , & wg , params .duration , progress )
426432
427- if err := s .configureServiceForDebug (conn , state , params .enablePersistence ); err != nil {
428- return err
429- }
433+ s .configureServiceForDebug (conn , state , params .enablePersistence )
430434
431435 wg .Wait ()
432436 progress .progressBar .Hide ()
@@ -482,17 +486,25 @@ func (s *serviceClient) createDebugBundleFromCollection(
482486
483487// Restore service to original state
484488func (s * serviceClient ) restoreServiceState (conn proto.DaemonServiceClient , state * debugInitialState ) {
489+ if state .needsRestoreUp {
490+ if _ , err := conn .Up (s .ctx , & proto.UpRequest {}); err != nil {
491+ log .Warnf ("failed to restore up state: %v" , err )
492+ } else {
493+ log .Info ("Service state restored to up" )
494+ }
495+ }
496+
485497 if state .wasDown {
486498 if _ , err := conn .Down (s .ctx , & proto.DownRequest {}); err != nil {
487- log .Errorf ( "Failed to restore down state: %v" , err )
499+ log .Warnf ( "failed to restore down state: %v" , err )
488500 } else {
489501 log .Info ("Service state restored to down" )
490502 }
491503 }
492504
493505 if ! state .isLevelTrace {
494506 if _ , err := conn .SetLogLevel (s .ctx , & proto.SetLogLevelRequest {Level : state .logLevel }); err != nil {
495- log .Errorf ( "Failed to restore log level: %v" , err )
507+ log .Warnf ( "failed to restore log level: %v" , err )
496508 } else {
497509 log .Info ("Log level restored to original setting" )
498510 }
0 commit comments