@@ -109,7 +109,10 @@ func (s *scaletestTracingFlags) provider(ctx context.Context) (trace.TracerProvi
109
109
return tracerProvider , func (ctx context.Context ) error {
110
110
var err error
111
111
closeTracingOnce .Do (func () {
112
- err = closeTracing (ctx )
112
+ // Allow time to upload traces even if ctx is canceled
113
+ traceCtx , traceCancel := context .WithTimeout (context .Background (), 10 * time .Second )
114
+ defer traceCancel ()
115
+ err = closeTracing (traceCtx )
113
116
})
114
117
115
118
return err
@@ -637,10 +640,11 @@ func (r *RootCmd) scaletestCreateWorkspaces() *clibase.Cmd {
637
640
}
638
641
defer func () {
639
642
// Allow time for traces to flush even if command context is
640
- // canceled.
641
- ctx , cancel := context .WithTimeout (context .Background (), 10 * time .Second )
642
- defer cancel ()
643
- _ = closeTracing (ctx )
643
+ // canceled. This is a no-op if tracing is not enabled.
644
+ _ , _ = fmt .Fprintln (inv .Stderr , "\n Uploading traces..." )
645
+ if err := closeTracing (ctx ); err != nil {
646
+ _ , _ = fmt .Fprintf (inv .Stderr , "\n Error uploading traces: %+v\n " , err )
647
+ }
644
648
}()
645
649
tracer := tracerProvider .Tracer (scaletestTracerName )
646
650
@@ -754,17 +758,6 @@ func (r *RootCmd) scaletestCreateWorkspaces() *clibase.Cmd {
754
758
return xerrors .Errorf ("cleanup tests: %w" , err )
755
759
}
756
760
757
- // Upload traces.
758
- if tracingEnabled {
759
- _ , _ = fmt .Fprintln (inv .Stderr , "\n Uploading traces..." )
760
- ctx , cancel := context .WithTimeout (ctx , 1 * time .Minute )
761
- defer cancel ()
762
- err := closeTracing (ctx )
763
- if err != nil {
764
- _ , _ = fmt .Fprintf (inv .Stderr , "\n Error uploading traces: %+v\n " , err )
765
- }
766
- }
767
-
768
761
if res .TotalFail > 0 {
769
762
return xerrors .New ("load test failed, see above for more details" )
770
763
}
@@ -905,7 +898,7 @@ func (r *RootCmd) scaletestTrafficGen() *clibase.Cmd {
905
898
var (
906
899
duration time.Duration
907
900
bps int64
908
- client = new ( codersdk.Client )
901
+ client = & codersdk.Client {}
909
902
tracingFlags = & scaletestTracingFlags {}
910
903
strategy = & scaletestStrategyFlags {}
911
904
cleanupStrategy = & scaletestStrategyFlags {cleanup : true }
@@ -947,10 +940,11 @@ func (r *RootCmd) scaletestTrafficGen() *clibase.Cmd {
947
940
}
948
941
defer func () {
949
942
// Allow time for traces to flush even if command context is
950
- // canceled.
951
- ctx , cancel := context .WithTimeout (context .Background (), 10 * time .Second )
952
- defer cancel ()
953
- _ = closeTracing (ctx )
943
+ // canceled. This is a no-op if tracing is not enabled.
944
+ _ , _ = fmt .Fprintln (inv .Stderr , "\n Uploading traces..." )
945
+ if err := closeTracing (ctx ); err != nil {
946
+ _ , _ = fmt .Fprintf (inv .Stderr , "\n Error uploading traces: %+v\n " , err )
947
+ }
954
948
}()
955
949
tracer := tracerProvider .Tracer (scaletestTracerName )
956
950
@@ -1018,17 +1012,6 @@ func (r *RootCmd) scaletestTrafficGen() *clibase.Cmd {
1018
1012
}
1019
1013
}
1020
1014
1021
- // Upload traces.
1022
- if tracingEnabled {
1023
- _ , _ = fmt .Fprintln (inv .Stderr , "\n Uploading traces..." )
1024
- ctx , cancel := context .WithTimeout (ctx , 1 * time .Minute )
1025
- defer cancel ()
1026
- err := closeTracing (ctx )
1027
- if err != nil {
1028
- _ , _ = fmt .Fprintf (inv .Stderr , "\n Error uploading traces: %+v\n " , err )
1029
- }
1030
- }
1031
-
1032
1015
if res .TotalFail > 0 {
1033
1016
return xerrors .New ("load test failed, see above for more details" )
1034
1017
}
0 commit comments