Skip to content

Commit

Permalink
Merge pull request #673 from arshadd-b/fix-duration
Browse files Browse the repository at this point in the history
fix wrong duration showed for image import
  • Loading branch information
ppc64le-cloud-bot authored Sep 24, 2024
2 parents d2d3bd1 + 1486dcc commit 3e6cd5f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
5 changes: 2 additions & 3 deletions cmd/image/import/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ pvsadm image import -n upstream-core-lon04 -b <BUCKETNAME> --object rhel-83-1003
return false, fmt.Errorf("image import job failed to complete, err: %v", err)
}
if *job.Status.State == jobStateCompleted {
klog.Infof("Image imported successfully, took %s", time.Since(start))
klog.V(2).Infof("Image uploaded successfully, took %s", time.Since(start).Round(time.Second))
return true, nil
}
if *job.Status.State == jobStateFailed {
Expand Down Expand Up @@ -296,14 +296,13 @@ pvsadm image import -n upstream-core-lon04 -b <BUCKETNAME> --object rhel-83-1003
return nil
}
klog.Infof("Waiting for image %s to be active. Please wait...", opt.ImageName)
start = time.Now()
return utils.PollUntil(time.Tick(10*time.Second), time.After(opt.WatchTimeout), func() (bool, error) {
img, err := pvmclient.ImgClient.Get(*image.ImageID)
if err != nil {
return false, fmt.Errorf("failed to import the image, err: %v\n\nRun the command \"pvsadm get events -i %s\" to get more information about the failure", err, pvmclient.InstanceID)
}
if img.State == imageStateActive {
klog.Infof("Successfully imported the image: %s with ID: %s in %s", *image.Name, *image.ImageID, time.Since(start))
klog.Infof("Successfully imported the image: %s with ID: %s Total time taken: %s", *image.Name, *image.ImageID, time.Since(start).Round(time.Second))
return true, nil
}
klog.Infof("Waiting for image to be active. Current state: %s", img.State)
Expand Down
4 changes: 2 additions & 2 deletions cmd/image/sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func copyWorker(copyJobs <-chan copyWorkload, results chan<- bool, workerId int)
klog.Errorf("copy object %s failed, err: %v", copyJob.srcObject, err)
results <- false
}
duration := time.Since(start)
duration := time.Since(start).Round(time.Second)
klog.Infof("Copying object: %s from bucket: %s to bucket: %s took %v", copyJob.srcObject, copyJob.srcBucket, copyJob.tgtBucket, duration)
results <- true
}
Expand Down Expand Up @@ -279,7 +279,7 @@ Sample spec.yaml file:
}

// Calculate total elapsed time
duration := time.Since(start)
duration := time.Since(start).Round(time.Second)
klog.Infof("Total elapsed time: %v", duration)
return nil
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/s3client.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,6 @@ func (c *S3Client) UploadObject(fileName, objectName, bucketName string) error {
return err
}
fmt.Println()
klog.Infof("Upload completed successfully in %f seconds to location %s", time.Since(startTime).Seconds(), result.Location)
klog.Infof("Upload completed successfully in %s seconds to location %s", time.Since(startTime).Round(time.Second), result.Location)
return nil
}

0 comments on commit 3e6cd5f

Please sign in to comment.