@@ -19,6 +19,11 @@ import (
1919 "k8s.io/klog/v2"
2020)
2121
22+ const (
23+ FioJobName = "fsperf"
24+ DefaultFioRunTime = "120"
25+ )
26+
2227type Durations []time.Duration
2328
2429func (d Durations ) Len () int {
@@ -367,22 +372,47 @@ func parseCollectorOptions(hostCollector *troubleshootv1beta2.FilesystemPerforma
367372 return nil , nil , errors .New ("Directory is required to collect filesystem performance info" )
368373 }
369374
375+ runtime , err := getFioRuntime (hostCollector .RunTime )
376+ if err != nil {
377+ return nil , nil , err
378+ }
379+
370380 latencyBenchmarkOptions := FioJobOptions {
371381 RW : "write" ,
372382 IOEngine : "sync" ,
373383 FDataSync : "1" ,
374384 Directory : hostCollector .Directory ,
375385 Size : strconv .FormatUint (fileSize , 10 ),
376386 BS : strconv .FormatUint (operationSize , 10 ),
377- Name : "fsperf" ,
378- RunTime : "120" ,
387+ Name : FioJobName ,
388+ RunTime : runtime ,
379389 }
380390
381391 command := buildFioCommand (latencyBenchmarkOptions )
382392
383393 return command , & latencyBenchmarkOptions , nil
384394}
385395
396+ // getFioRuntime returns the runTime value or the default if runTime is nil, empty or <= 0.
397+ // This attepmts to maintain backwards compatibility prior to adding runTime to the collector spec,
398+ // defaulting to 120 seconds.
399+ func getFioRuntime (runTime * string ) (string , error ) {
400+ if runTime == nil {
401+ return DefaultFioRunTime , nil
402+ }
403+ if * runTime == "" {
404+ return "" , nil // disable
405+ }
406+ i , err := strconv .Atoi (* runTime )
407+ if err != nil {
408+ return "" , errors .Wrapf (err , "failed to parse runTime %q" , * runTime )
409+ }
410+ if i <= 0 {
411+ return "" , nil // disable
412+ }
413+ return * runTime , nil
414+ }
415+
386416func buildFioCommand (opts FioJobOptions ) []string {
387417 command := []string {"fio" }
388418 v := reflect .ValueOf (opts )
@@ -407,7 +437,7 @@ func collectFioResults(ctx context.Context, hostCollector *troubleshootv1beta2.F
407437 }
408438
409439 klog .V (2 ).Infof ("collecting fio results: %s" , strings .Join (command , " " ))
410- output , err := exec .CommandContext (ctx , command [0 ], command [1 :]... ).Output ()
440+ output , err := exec .CommandContext (ctx , command [0 ], command [1 :]... ).Output () // #nosec G204
411441 if err != nil {
412442 if exitErr , ok := err .(* exec.ExitError ); ok {
413443 if exitErr .ExitCode () == 1 {
0 commit comments