mirror of
https://github.com/replicatedhq/troubleshoot.git
synced 2026-04-15 07:16:34 +00:00
Merge pull request #354 from areed/fs-perf-timeout
Add timeout to filesystem performance collector
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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"`
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user