client/driver: add waiting layer status count to pull progress status msg

This commit is contained in:
Nick Ethier 2018-05-03 15:14:53 -04:00
parent 77af17efbc
commit d8de354dbf
No known key found for this signature in database
GPG Key ID: 07C1A3ECED90D24A
1 changed files with 23 additions and 13 deletions

View File

@ -21,6 +21,10 @@ const (
// dockerImageProgressReportInterval is the default value set in the
// imageProgressManager when newImageProgressManager is called
dockerImageProgressReportInterval = 10 * time.Second
// dockerImageSlowProgressReportInterval is the default value set in the
// imageProgressManager when newImageProgressManager is called
dockerImageSlowProgressReportInterval = 2 * time.Minute
)
// layerProgress tracks the state and downloaded bytes of a single layer within
@ -88,11 +92,16 @@ func (p *imageProgress) get() (string, time.Time) {
return "No progress", p.timestamp
}
var pulled, pulling int
var pulled, pulling, waiting int
for _, l := range p.layers {
if l.status == layerProgressStatusDownloading {
switch {
case l.status == layerProgressStatusStarting ||
l.status == layerProgressStatusWaiting:
waiting++
case l.status == layerProgressStatusDownloading ||
l.status == layerProgressStatusVerifying:
pulling++
} else if l.status > layerProgressStatusVerifying {
case l.status >= layerProgressStatusDownloaded:
pulled++
}
}
@ -105,9 +114,9 @@ func (p *imageProgress) get() (string, time.Time) {
est = (elapsed.Nanoseconds() / cur * total) - elapsed.Nanoseconds()
}
return fmt.Sprintf("Pulled %d/%d (%s/%s) pulling %d layers - est %.1fs remaining",
pulled, len(p.layers), units.BytesSize(float64(cur)), units.BytesSize(float64(total)), pulling,
time.Duration(est).Seconds()), p.timestamp
return fmt.Sprintf("Pulled %d/%d (%s/%s) layers: %d waiting/%d pulling - est %.1fs remaining",
pulled, len(p.layers), units.BytesSize(float64(cur)), units.BytesSize(float64(total)),
waiting, pulling, time.Duration(est).Seconds()), p.timestamp
}
// set takes a status message received from the docker engine api during an image
@ -160,7 +169,7 @@ func (p *imageProgress) totalBytes() int64 {
return b
}
// progressReporterFunc defines the method for handeling inactivity and report
// progressReporterFunc defines the method for handling inactivity and report
// events from the imageProgressManager. The image name, current status message
// and timestamp of last received status update are passed in.
type progressReporterFunc func(image string, msg string, timestamp time.Time)
@ -190,12 +199,13 @@ func newImageProgressManager(
inactivityFunc, reporter, slowReporter progressReporterFunc) *imageProgressManager {
pm := &imageProgressManager{
image: image,
activityDeadline: dockerPullActivityDeadline,
inactivityFunc: inactivityFunc,
reportInterval: dockerImageProgressReportInterval,
reporter: reporter,
slowReporter: slowReporter,
image: image,
activityDeadline: dockerPullActivityDeadline,
inactivityFunc: inactivityFunc,
reportInterval: dockerImageProgressReportInterval,
reporter: reporter,
slowReportInterval: dockerImageSlowProgressReportInterval,
slowReporter: slowReporter,
imageProgress: &imageProgress{
timestamp: time.Now(),
layers: make(map[string]*layerProgress),