From e98e67856d357218834c200f71d61c742408c220 Mon Sep 17 00:00:00 2001 From: arshadda Date: Mon, 23 Sep 2024 11:13:51 +0530 Subject: [PATCH] fix wrong duration showed for image import --- cmd/image/import/import.go | 4 ++-- cmd/image/sync/sync.go | 4 ++-- pkg/client/s3client.go | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cmd/image/import/import.go b/cmd/image/import/import.go index 7d52052f..8cc4ff7b 100644 --- a/cmd/image/import/import.go +++ b/cmd/image/import/import.go @@ -268,7 +268,7 @@ pvsadm image import -n upstream-core-lon04 -b --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.Infof("Image imported successfully, took %s", time.Since(start).Round(time.Second)) return true, nil } if *job.Status.State == jobStateFailed { @@ -303,7 +303,7 @@ pvsadm image import -n upstream-core-lon04 -b --object rhel-83-1003 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 in %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) diff --git a/cmd/image/sync/sync.go b/cmd/image/sync/sync.go index 9b5a1b17..5169750c 100644 --- a/cmd/image/sync/sync.go +++ b/cmd/image/sync/sync.go @@ -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 } @@ -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 }, diff --git a/pkg/client/s3client.go b/pkg/client/s3client.go index 955ba871..8950f60b 100644 --- a/pkg/client/s3client.go +++ b/pkg/client/s3client.go @@ -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 %f seconds to location %s", time.Since(startTime).Round(time.Second), result.Location) return nil }