@@ -292,9 +292,7 @@ func runCommand(ctx context.Context, workDir, cmdPath, kubeconfig string, withCP
292292 }
293293 startTime := time .Now ()
294294
295- wg .Add (1 )
296- go func () {
297- defer wg .Done ()
295+ wg .Go (func () {
298296 err := cmd .Wait ()
299297 if err != nil {
300298 select {
@@ -325,7 +323,7 @@ func runCommand(ctx context.Context, workDir, cmdPath, kubeconfig string, withCP
325323 if err != nil {
326324 log .Error (err , "Writing cmd stats" )
327325 }
328- }( )
326+ })
329327 return nil
330328}
331329
@@ -346,9 +344,7 @@ func runGenerator(ctx context.Context, cfg *rest.Config, generatorConfig string,
346344 }
347345
348346 statTime := time .Now ()
349- wg .Add (1 )
350- go func () {
351- defer wg .Done ()
347+ wg .Go (func () {
352348 defer close (genDone )
353349 err := generator .Generate (ctx , c , cohorts )
354350 if err != nil {
@@ -357,7 +353,7 @@ func runGenerator(ctx context.Context, cfg *rest.Config, generatorConfig string,
357353 return
358354 }
359355 log .Info ("Generator done" , "duration" , time .Since (statTime ))
360- }( )
356+ })
361357
362358 log .Info ("Generator started" , "qps" , cfg .QPS , "burst" , cfg .Burst )
363359 return nil
@@ -366,17 +362,15 @@ func runGenerator(ctx context.Context, cfg *rest.Config, generatorConfig string,
366362func startRecorder (ctx context.Context , errCh chan <- error , wg * sync.WaitGroup , genDone <- chan struct {}, recordTimeout time.Duration ) (* recorder.Recorder , error ) {
367363 log := ctrl .LoggerFrom (ctx ).WithName ("Start recorder" )
368364 recorder := recorder .New (recordTimeout )
369- wg .Add (1 )
370- go func () {
371- defer wg .Done ()
365+ wg .Go (func () {
372366 err := recorder .Run (ctx , genDone )
373367 if err != nil {
374368 log .Error (err , "Recorder run" )
375369 } else {
376370 log .Info ("Recorder done" )
377371 }
378372 errCh <- err
379- }( )
373+ })
380374
381375 log .Info ("Recorder started" , "timeout" , recordTimeout )
382376 return recorder , nil
@@ -408,17 +402,15 @@ func runManager(ctx context.Context, cfg *rest.Config, errCh chan<- error, wg *s
408402 return err
409403 }
410404
411- wg .Add (1 )
412- go func () {
413- defer wg .Done ()
405+ wg .Go (func () {
414406 log .Info ("Starting manager" )
415407 if err := mgr .Start (ctx ); err != nil {
416408 log .Error (err , "Could not run manager" )
417409 errCh <- err
418410 } else {
419411 log .Info ("End manager" )
420412 }
421- }( )
413+ })
422414
423415 log .Info ("Manager started" )
424416 return nil
@@ -429,17 +421,15 @@ func runScraper(ctx context.Context, interval time.Duration, output, url string,
429421
430422 s := scraper .NewScraper (interval , url , "%d.prometheus" )
431423
432- wg .Add (1 )
433- go func () {
434- defer wg .Done ()
424+ wg .Go (func () {
435425 err := s .Run (ctx , output )
436426 if err != nil {
437427 log .Error (err , "Running the scraper" )
438428 errCh <- err
439429 return
440430 }
441431 log .Info ("Scrape done" )
442- }( )
432+ })
443433
444434 log .Info ("Scrape started" )
445435 return nil
0 commit comments