Skip to content

Commit 1b1efa1

Browse files
authored
feat(fio): add option to disable runtime (#1601)
1 parent ff31f5a commit 1b1efa1

14 files changed

+288
-15
lines changed

config/crds/troubleshoot.sh_hostcollectors.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,6 +1337,12 @@ spec:
13371337
background IOPS feature if enabled, since those must be fixed at 4096.
13381338
format: int64
13391339
type: integer
1340+
runTime:
1341+
description: |-
1342+
Limit runtime. The test will run until it completes the configured I/O workload or until it
1343+
has run for this specified amount of time, whichever occurs first. When the unit is omitted,
1344+
the value is interpreted in seconds. Defaults to 120 seconds. Set to "0" to disable.
1345+
type: string
13401346
sync:
13411347
description: Whether to call sync on the file after each
13421348
write. Does not apply to background IOPS task.

config/crds/troubleshoot.sh_hostpreflights.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,6 +1337,12 @@ spec:
13371337
background IOPS feature if enabled, since those must be fixed at 4096.
13381338
format: int64
13391339
type: integer
1340+
runTime:
1341+
description: |-
1342+
Limit runtime. The test will run until it completes the configured I/O workload or until it
1343+
has run for this specified amount of time, whichever occurs first. When the unit is omitted,
1344+
the value is interpreted in seconds. Defaults to 120 seconds. Set to "0" to disable.
1345+
type: string
13401346
sync:
13411347
description: Whether to call sync on the file after each
13421348
write. Does not apply to background IOPS task.
@@ -1819,6 +1825,12 @@ spec:
18191825
background IOPS feature if enabled, since those must be fixed at 4096.
18201826
format: int64
18211827
type: integer
1828+
runTime:
1829+
description: |-
1830+
Limit runtime. The test will run until it completes the configured I/O workload or until it
1831+
has run for this specified amount of time, whichever occurs first. When the unit is omitted,
1832+
the value is interpreted in seconds. Defaults to 120 seconds. Set to "0" to disable.
1833+
type: string
18221834
sync:
18231835
description: Whether to call sync on the file after each
18241836
write. Does not apply to background IOPS task.

config/crds/troubleshoot.sh_preflights.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18723,6 +18723,12 @@ spec:
1872318723
background IOPS feature if enabled, since those must be fixed at 4096.
1872418724
format: int64
1872518725
type: integer
18726+
runTime:
18727+
description: |-
18728+
Limit runtime. The test will run until it completes the configured I/O workload or until it
18729+
has run for this specified amount of time, whichever occurs first. When the unit is omitted,
18730+
the value is interpreted in seconds. Defaults to 120 seconds. Set to "0" to disable.
18731+
type: string
1872618732
sync:
1872718733
description: Whether to call sync on the file after each
1872818734
write. Does not apply to background IOPS task.

config/crds/troubleshoot.sh_remotecollectors.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,12 @@ spec:
171171
background IOPS feature if enabled, since those must be fixed at 4096.
172172
format: int64
173173
type: integer
174+
runTime:
175+
description: |-
176+
Limit runtime. The test will run until it completes the configured I/O workload or until it
177+
has run for this specified amount of time, whichever occurs first. When the unit is omitted,
178+
the value is interpreted in seconds. Defaults to 120 seconds. Set to "0" to disable.
179+
type: string
174180
sync:
175181
description: Whether to call sync on the file after each
176182
write. Does not apply to background IOPS task.

config/crds/troubleshoot.sh_supportbundles.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19951,6 +19951,12 @@ spec:
1995119951
background IOPS feature if enabled, since those must be fixed at 4096.
1995219952
format: int64
1995319953
type: integer
19954+
runTime:
19955+
description: |-
19956+
Limit runtime. The test will run until it completes the configured I/O workload or until it
19957+
has run for this specified amount of time, whichever occurs first. When the unit is omitted,
19958+
the value is interpreted in seconds. Defaults to 120 seconds. Set to "0" to disable.
19959+
type: string
1995419960
sync:
1995519961
description: Whether to call sync on the file after each
1995619962
write. Does not apply to background IOPS task.

pkg/analyze/host_filesystem_performance.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,18 @@ func (a *AnalyzeHostFilesystemPerformance) Analyze(
7474
return nil, errors.Wrapf(err, "failed to unmarshal fio results from %s", name)
7575
}
7676

77-
if len(fioResult.Jobs) == 0 {
78-
return nil, errors.Errorf("no jobs found in fio results from %s", name)
77+
var job *collect.FioJobs
78+
for _, j := range fioResult.Jobs {
79+
if j.JobName == collect.FioJobName {
80+
job = &j
81+
break
82+
}
83+
}
84+
if job == nil {
85+
return nil, errors.Errorf("no job named 'fsperf' found in fio results from %s", name)
7986
}
8087

81-
fioWriteLatency := fioResult.Jobs[0].Sync
88+
fioWriteLatency := job.Sync
8289

8390
fsPerf := fioWriteLatency.FSPerfResults()
8491
if err := json.Unmarshal(contents, &fsPerf); err != nil {

pkg/apis/troubleshoot/v1beta2/hostcollector_shared.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@ type FilesystemPerformance struct {
145145
// Whether to call datasync on the file after each write. Skipped if Sync is also true. Does not
146146
// apply to background IOPS task.
147147
Datasync bool `json:"datasync,omitempty"`
148+
// Limit runtime. The test will run until it completes the configured I/O workload or until it
149+
// has run for this specified amount of time, whichever occurs first. When the unit is omitted,
150+
// the value is interpreted in seconds. Defaults to 120 seconds. Set to "0" to disable.
151+
RunTime *string `json:"runTime,omitempty"`
152+
148153
// Total timeout, including background IOPS setup and warmup if enabled.
149154
Timeout string `json:"timeout,omitempty"`
150155

pkg/apis/troubleshoot/v1beta2/remote_collector_shared.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ type RemoteFilesystemPerformance struct {
116116
Datasync bool `json:"datasync,omitempty"`
117117
// Total timeout, including background IOPS setup and warmup if enabled.
118118
Timeout string `json:"timeout,omitempty"`
119+
// Limit runtime. The test will run until it completes the configured I/O workload or until it
120+
// has run for this specified amount of time, whichever occurs first. When the unit is omitted,
121+
// the value is interpreted in seconds. Defaults to 120 seconds. Set to "0" to disable.
122+
RunTime *string `json:"runTime,omitempty"`
119123

120124
// Enable the background IOPS feature.
121125
EnableBackgroundIOPS bool `json:"enableBackgroundIOPS"`

pkg/apis/troubleshoot/v1beta2/zz_generated.deepcopy.go

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/collect/host_filesystem_performance.go

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ import (
1919
"k8s.io/klog/v2"
2020
)
2121

22+
const (
23+
FioJobName = "fsperf"
24+
DefaultFioRunTime = "120"
25+
)
26+
2227
type Durations []time.Duration
2328

2429
func (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+
386416
func 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

Comments
 (0)