From 01ecc778096014527c5f7805a29cac994db2f14f Mon Sep 17 00:00:00 2001 From: Paul Annesley Date: Thu, 23 Nov 2023 15:29:54 +1030 Subject: [PATCH] Humanize bytes to base-2 (1024 -> KiB etc) not base-10 (1000 -> KB etc) This matches our server-side display; consistency reduces confusion. (Rails defaults to IEC / base-2 although it calls them e.g. KB not KiB). --- agent/artifact_uploader.go | 2 +- agent/download.go | 2 +- agent/log_streamer.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/agent/artifact_uploader.go b/agent/artifact_uploader.go index 49ac6d3bc6..3d66316334 100644 --- a/agent/artifact_uploader.go +++ b/agent/artifact_uploader.go @@ -531,7 +531,7 @@ func (a *ArtifactUploader) upload(ctx context.Context, artifacts []*api.Artifact p.Spawn(func() { // Show a nice message that we're starting to upload the file - a.logger.Info("Uploading artifact %s %s (%s)", artifact.ID, artifact.Path, humanize.Bytes(uint64(artifact.FileSize))) + a.logger.Info("Uploading artifact %s %s (%s)", artifact.ID, artifact.Path, humanize.IBytes(uint64(artifact.FileSize))) var state string diff --git a/agent/download.go b/agent/download.go index bc9d4fec58..32b74d4e1b 100644 --- a/agent/download.go +++ b/agent/download.go @@ -153,7 +153,7 @@ func (d Download) try(ctx context.Context) error { return fmt.Errorf("Error when copying data %s (%T: %v)", d.conf.URL, err, err) } - d.logger.Info("Successfully downloaded \"%s\" %s", d.conf.Path, humanize.Bytes(uint64(bytes))) + d.logger.Info("Successfully downloaded \"%s\" %s", d.conf.Path, humanize.IBytes(uint64(bytes))) return nil } diff --git a/agent/log_streamer.go b/agent/log_streamer.go index 6cb110d9a0..938745be36 100644 --- a/agent/log_streamer.go +++ b/agent/log_streamer.go @@ -122,7 +122,7 @@ func (ls *LogStreamer) Process(output []byte) { "exceeded the maximum size (%s). Further logs may be dropped "+ "by the server, and a future version of the agent will stop "+ "sending logs at this point.", - humanize.Bytes(ls.bytes), humanize.Bytes(ls.conf.MaxSizeBytes)) + humanize.IBytes(ls.bytes), humanize.IBytes(ls.conf.MaxSizeBytes)) ls.warnedAboutSize = true // In a future version, this will error out, e.g.: //return fmt.Errorf("job log has exceeded max job log size (%d > %d)", ls.bytes, ls.conf.MaxSizeBytes)