Skip to content

Commit

Permalink
Ensure the program can stop (#60)
Browse files Browse the repository at this point in the history
Improvements to ensure tool stops and log fatal error on critical scenarios.
  • Loading branch information
arnaud-tincelin authored Jun 2, 2021
1 parent ae860e1 commit 9ad4460
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions cmd/aks-periscope/aks-periscope.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ import (
func main() {
zipAndExportMode := true
exporter := &exporter.AzureBlobExporter{}
var waitgroup sync.WaitGroup

This comment has been minimized.

Copy link
@sophsoph321

sophsoph321 Jun 7, 2021

Collaborator

Removing this common waitgroup and replacing it with collector and diagnoser waitgroups for some reason causes my pod to crash while running periscope with this change.


err := utils.CreateCRD()
if err != nil {
log.Printf("Failed to create CRD: %+v", err)
log.Fatalf("Failed to create CRD: %v", err)
}

clusterType := os.Getenv("CLUSTER_TYPE")
Expand Down Expand Up @@ -56,59 +55,65 @@ func main() {
collectors = append(collectors, systemPerfCollector)
}

collectorGrp := new(sync.WaitGroup)

for _, c := range collectors {
waitgroup.Add(1)
collectorGrp.Add(1)
go func(c interfaces.Collector) {
log.Printf("Collector: %s, collect data\n", c.GetName())
defer collectorGrp.Done()

log.Printf("Collector: %s, collect data", c.GetName())
err := c.Collect()
if err != nil {
log.Printf("Collector: %s, collect data failed: %+v\n", c.GetName(), err)
log.Printf("Collector: %s, collect data failed: %v", c.GetName(), err)
return
}

log.Printf("Collector: %s, export data\n", c.GetName())
log.Printf("Collector: %s, export data", c.GetName())
err = c.Export()
if err != nil {
log.Printf("Collector: %s, export data failed: %+v\n", c.GetName(), err)
log.Printf("Collector: %s, export data failed: %v", c.GetName(), err)
}
waitgroup.Done()
}(c)
}

waitgroup.Wait()
collectorGrp.Wait()

diagnosers := []interfaces.Diagnoser{}
diagnosers = append(diagnosers, diagnoser.NewNetworkConfigDiagnoser(dnsCollector, kubeletCmdCollector, exporter))
diagnosers = append(diagnosers, diagnoser.NewNetworkOutboundDiagnoser(networkOutboundCollector, exporter))

diagnoserGrp := new(sync.WaitGroup)

for _, d := range diagnosers {
waitgroup.Add(1)
diagnoserGrp.Add(1)
go func(d interfaces.Diagnoser) {
log.Printf("Diagnoser: %s, diagnose data\n", d.GetName())
defer diagnoserGrp.Done()

log.Printf("Diagnoser: %s, diagnose data", d.GetName())
err := d.Diagnose()
if err != nil {
log.Printf("Diagnoser: %s, diagnose data failed: %+v\n", d.GetName(), err)
log.Printf("Diagnoser: %s, diagnose data failed: %v", d.GetName(), err)
return
}

log.Printf("Diagnoser: %s, export data\n", d.GetName())
log.Printf("Diagnoser: %s, export data", d.GetName())
err = d.Export()
if err != nil {
log.Printf("Diagnoser: %s, export data failed: %+v\n", d.GetName(), err)
log.Printf("Diagnoser: %s, export data failed: %v", d.GetName(), err)
}
waitgroup.Done()
}(d)
}

waitgroup.Wait()
diagnoserGrp.Wait()

if zipAndExportMode {
log.Print("Zip and export result files")
err := zipAndExport(exporter)
if err != nil {
log.Printf("Failed to zip and export result files: %+v", err)
log.Fatalf("Failed to zip and export result files: %v", err)
}
}

select {}
}

// zipAndExport zip the results and export
Expand Down

0 comments on commit 9ad4460

Please sign in to comment.