From f99781ec1d2394c3552056b3a091d9c40a708ffe Mon Sep 17 00:00:00 2001 From: Priya Wadhwa Date: Wed, 26 Aug 2020 12:11:11 -0400 Subject: [PATCH 1/2] print download progress every second; previously we were printing 6000x/sec which is unnecessary --- pkg/minikube/download/json_output.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pkg/minikube/download/json_output.go b/pkg/minikube/download/json_output.go index 7a19838883bd..20c4842eb72c 100644 --- a/pkg/minikube/download/json_output.go +++ b/pkg/minikube/download/json_output.go @@ -20,6 +20,7 @@ import ( "fmt" "io" "sync" + "time" "github.com/hashicorp/go-getter" "k8s.io/minikube/pkg/minikube/out/register" @@ -44,6 +45,7 @@ func (cpb *jsonOutput) TrackProgress(src string, currentSize, totalSize int64, s artifact: src, current: currentSize, total: totalSize, + Time: time.Now(), }, close: func() error { cpb.lock.Lock() @@ -59,12 +61,17 @@ type jsonReader struct { current int64 total int64 io.Reader + time.Time } func (r *jsonReader) Read(p []byte) (n int, err error) { n, err = r.Reader.Read(p) r.current += int64(n) progress := float64(r.current) / float64(r.total) - register.PrintDownloadProgress(r.artifact, fmt.Sprintf("%v", progress)) + // print progress every second so user isn't overwhelmed with events + if t := time.Now(); t.Sub(r.Time) > time.Second { + register.PrintDownloadProgress(r.artifact, fmt.Sprintf("%v", progress)) + r.Time = t + } return } From 8a2ebd505b40767e94ff72190af6b84023b9ae93 Mon Sep 17 00:00:00 2001 From: Priya Wadhwa Date: Wed, 26 Aug 2020 12:16:17 -0400 Subject: [PATCH 2/2] also output final event when complete --- pkg/minikube/download/json_output.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/minikube/download/json_output.go b/pkg/minikube/download/json_output.go index 20c4842eb72c..483f36c735cc 100644 --- a/pkg/minikube/download/json_output.go +++ b/pkg/minikube/download/json_output.go @@ -69,7 +69,7 @@ func (r *jsonReader) Read(p []byte) (n int, err error) { r.current += int64(n) progress := float64(r.current) / float64(r.total) // print progress every second so user isn't overwhelmed with events - if t := time.Now(); t.Sub(r.Time) > time.Second { + if t := time.Now(); t.Sub(r.Time) > time.Second || progress == 1 { register.PrintDownloadProgress(r.artifact, fmt.Sprintf("%v", progress)) r.Time = t }