diff --git a/examples/preflight/host/filesystem-performance.yaml b/examples/preflight/host/filesystem-performance.yaml index b94cf3de..0e6ba947 100644 --- a/examples/preflight/host/filesystem-performance.yaml +++ b/examples/preflight/host/filesystem-performance.yaml @@ -6,12 +6,13 @@ spec: collectors: - filesystemPerformance: collectorName: etcd-perf + timeout: 2m directory: /var/lib/etcd fileSize: 22Mi operationSizeBytes: 2300 datasync: true enableBackgroundIOPS: true - backgroundIOPSWarmupSeconds: 60 + backgroundIOPSWarmupSeconds: 10 backgroundWriteIOPS: 300 backgroundWriteIOPSJobs: 6 backgroundReadIOPS: 50 diff --git a/pkg/apis/troubleshoot/v1beta2/hostcollector_shared.go b/pkg/apis/troubleshoot/v1beta2/hostcollector_shared.go index 888e12fc..4b4eaf6b 100644 --- a/pkg/apis/troubleshoot/v1beta2/hostcollector_shared.go +++ b/pkg/apis/troubleshoot/v1beta2/hostcollector_shared.go @@ -91,6 +91,8 @@ type FilesystemPerformance struct { // Whether to call datasync on the file after each write. Skipped if Sync is also true. Does not // apply to background IOPS task. Datasync bool `json:"datasync,omitempty"` + // Total timeout, including background IOPS setup and warmup if enabled. + Timeout string `json:"timeout,omitempty"` // Enable the background IOPS feature. EnableBackgroundIOPS bool `json:"enableBackgroundIOPS"` diff --git a/pkg/client/troubleshootclientset/fake/register.go b/pkg/client/troubleshootclientset/fake/register.go index 8010c884..89d94f58 100644 --- a/pkg/client/troubleshootclientset/fake/register.go +++ b/pkg/client/troubleshootclientset/fake/register.go @@ -29,7 +29,7 @@ import ( var scheme = runtime.NewScheme() var codecs = serializer.NewCodecFactory(scheme) -var parameterCodec = runtime.NewParameterCodec(scheme) + var localSchemeBuilder = runtime.SchemeBuilder{ troubleshootv1beta1.AddToScheme, troubleshootv1beta2.AddToScheme, diff --git a/pkg/collect/host_filesystem_performance_linux.go b/pkg/collect/host_filesystem_performance_linux.go index c21a1b58..aa232a1d 100644 --- a/pkg/collect/host_filesystem_performance_linux.go +++ b/pkg/collect/host_filesystem_performance_linux.go @@ -38,6 +38,17 @@ func (d Durations) Swap(i, j int) { } func collectHostFilesystemPerformance(hostCollector *troubleshootv1beta2.FilesystemPerformance) (map[string][]byte, error) { + timeout := time.Minute + if hostCollector.Timeout != "" { + d, err := time.ParseDuration(hostCollector.Timeout) + if err != nil { + return nil, errors.Wrapf(err, "failed to parse timeout %q", hostCollector.Timeout) + } + timeout = d + } + ctx, cancel := context.WithTimeout(context.Background(), timeout) + defer cancel() + var operationSize uint64 = 1024 if hostCollector.OperationSizeBytes != 0 { operationSize = hostCollector.OperationSizeBytes @@ -85,10 +96,7 @@ func collectHostFilesystemPerformance(hostCollector *troubleshootv1beta2.Filesys // canceled jobs := hostCollector.BackgroundReadIOPSJobs + hostCollector.BackgroundWriteIOPSJobs done := make(chan bool, jobs) - - ctx, cancel := context.WithCancel(context.Background()) defer func() { - cancel() for i := 0; i < jobs; i++ { <-done } @@ -145,6 +153,10 @@ func collectHostFilesystemPerformance(hostCollector *troubleshootv1beta2.Filesys results = append(results, d) written += uint64(n) + + if ctx.Err() != nil { + break + } } if len(results) == 0 {