Merge pull request #7410 from medyagh/adjust_warn_slow

adjust warn if slow for ps and volume
pull/7415/head
Thomas Strömberg 2020-04-04 10:45:42 -07:00 committed by GitHub
commit 25cbb6e6f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 5 deletions

View File

@ -234,21 +234,26 @@ func ContainerID(ociBinary string, nameOrID string) (string, error) {
}
// WarnIfSlow runs an oci command, warning about performance issues
func WarnIfSlow(arg ...string) ([]byte, error) {
killTime := 15 * time.Second
func WarnIfSlow(args ...string) ([]byte, error) {
killTime := 19 * time.Second
warnTime := 2 * time.Second
if args[1] == "volume" || args[1] == "ps" { // volume and ps requires more time than inspect
killTime = 30 * time.Second
warnTime = 3 * time.Second
}
ctx, cancel := context.WithTimeout(context.Background(), killTime)
defer cancel()
start := time.Now()
glog.Infof("executing with %s timeout: %v", arg, killTime)
cmd := exec.CommandContext(ctx, arg[0], arg[1:]...)
glog.Infof("executing with %s timeout: %v", args, killTime)
cmd := exec.CommandContext(ctx, args[0], args[1:]...)
stdout, err := cmd.Output()
d := time.Since(start)
if d > warnTime {
out.WarningT(`Executing "{{.command}}" took an unusually long time: {{.duration}}`, out.V{"command": strings.Join(cmd.Args, " "), "duration": d})
out.ErrT(out.Tip, `Restarting the {{.name}} service may improve performance.`, out.V{"name": arg[0]})
out.ErrT(out.Tip, `Restarting the {{.name}} service may improve performance.`, out.V{"name": args[0]})
}
if ctx.Err() == context.DeadlineExceeded {