Skip to content

Commit ce81584

Browse files
authored
Merge pull request #354 from areed/fs-perf-timeout
Add timeout to filesystem performance collector
2 parents e218135 + 0a6c983 commit ce81584

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

examples/preflight/host/filesystem-performance.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ spec:
66
collectors:
77
- filesystemPerformance:
88
collectorName: etcd-perf
9+
timeout: 2m
910
directory: /var/lib/etcd
1011
fileSize: 22Mi
1112
operationSizeBytes: 2300
1213
datasync: true
1314
enableBackgroundIOPS: true
14-
backgroundIOPSWarmupSeconds: 60
15+
backgroundIOPSWarmupSeconds: 10
1516
backgroundWriteIOPS: 300
1617
backgroundWriteIOPSJobs: 6
1718
backgroundReadIOPS: 50

pkg/apis/troubleshoot/v1beta2/hostcollector_shared.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ type FilesystemPerformance struct {
9191
// Whether to call datasync on the file after each write. Skipped if Sync is also true. Does not
9292
// apply to background IOPS task.
9393
Datasync bool `json:"datasync,omitempty"`
94+
// Total timeout, including background IOPS setup and warmup if enabled.
95+
Timeout string `json:"timeout,omitempty"`
9496

9597
// Enable the background IOPS feature.
9698
EnableBackgroundIOPS bool `json:"enableBackgroundIOPS"`

pkg/client/troubleshootclientset/fake/register.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/collect/host_filesystem_performance_linux.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,17 @@ func (d Durations) Swap(i, j int) {
3838
}
3939

4040
func collectHostFilesystemPerformance(hostCollector *troubleshootv1beta2.FilesystemPerformance) (map[string][]byte, error) {
41+
timeout := time.Minute
42+
if hostCollector.Timeout != "" {
43+
d, err := time.ParseDuration(hostCollector.Timeout)
44+
if err != nil {
45+
return nil, errors.Wrapf(err, "failed to parse timeout %q", hostCollector.Timeout)
46+
}
47+
timeout = d
48+
}
49+
ctx, cancel := context.WithTimeout(context.Background(), timeout)
50+
defer cancel()
51+
4152
var operationSize uint64 = 1024
4253
if hostCollector.OperationSizeBytes != 0 {
4354
operationSize = hostCollector.OperationSizeBytes
@@ -85,10 +96,7 @@ func collectHostFilesystemPerformance(hostCollector *troubleshootv1beta2.Filesys
8596
// canceled
8697
jobs := hostCollector.BackgroundReadIOPSJobs + hostCollector.BackgroundWriteIOPSJobs
8798
done := make(chan bool, jobs)
88-
89-
ctx, cancel := context.WithCancel(context.Background())
9099
defer func() {
91-
cancel()
92100
for i := 0; i < jobs; i++ {
93101
<-done
94102
}
@@ -145,6 +153,10 @@ func collectHostFilesystemPerformance(hostCollector *troubleshootv1beta2.Filesys
145153
results = append(results, d)
146154

147155
written += uint64(n)
156+
157+
if ctx.Err() != nil {
158+
break
159+
}
148160
}
149161

150162
if len(results) == 0 {

0 commit comments

Comments
 (0)