Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adjust warn if slow for ps and volume #7410

Merged
merged 3 commits into from
Apr 4, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions pkg/drivers/kic/oci/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down