From 6b15ee04861006fe56d533003f307f815deb0de7 Mon Sep 17 00:00:00 2001 From: Adrien Delorme Date: Fri, 24 May 2024 11:29:44 +0200 Subject: [PATCH] fix(metrics): correct image pull throughput calculation Signed-off-by: Adrien Delorme --- internal/cri/server/images/image_pull.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/internal/cri/server/images/image_pull.go b/internal/cri/server/images/image_pull.go index 4d4ba20364ec..cc7cdd4096c6 100644 --- a/internal/cri/server/images/image_pull.go +++ b/internal/cri/server/images/image_pull.go @@ -235,13 +235,12 @@ func (c *CRIImageService) PullImage(ctx context.Context, name string, credential } } - const mbToByte = 1024 * 1024 - size, _ := image.Size(ctx) - imagePullingSpeed := float64(size) / mbToByte / time.Since(startTime).Seconds() + sizeByte, _ := image.Size(ctx) + imagePullingSpeed := float64(sizeByte) / time.Since(startTime).Seconds() imagePullThroughput.Observe(imagePullingSpeed) log.G(ctx).Infof("Pulled image %q with image id %q, repo tag %q, repo digest %q, size %q in %s", name, imageID, - repoTag, repoDigest, strconv.FormatInt(size, 10), time.Since(startTime)) + repoTag, repoDigest, strconv.FormatInt(sizeByte, 10), time.Since(startTime)) // NOTE(random-liu): the actual state in containerd is the source of truth, even we maintain // in-memory image store, it's only for in-memory indexing. The image could be removed // by someone else anytime, before/during/after we create the metadata. We should always