Skip to content

Commit

Permalink
add upload size to deploy metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
ianic committed Oct 15, 2021
1 parent 6e0fca9 commit af21295
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
21 changes: 20 additions & 1 deletion cli/cmd/deploy/deploy.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package deploy

import (
"fmt"
"time"

"github.com/mantil-io/mantil/api/dto"
Expand Down Expand Up @@ -33,6 +34,7 @@ type Cmd struct {
functionsForUpload []uploadData
buildDuration time.Duration
uploadDuration time.Duration
uploadBytes int64
updateDuration time.Duration
}

Expand Down Expand Up @@ -126,9 +128,10 @@ func (d *Cmd) deploy() error {
ui.Info("")
}

ui.Info("Build time: %v, upload: %v, update: %v",
ui.Info("Build time: %v, upload: %v (%s), update: %v",
d.buildDuration.Round(time.Millisecond),
d.uploadDuration.Round(time.Millisecond),
byteCountIEC(d.uploadBytes),
d.updateDuration.Round(time.Millisecond))
return nil
}
Expand Down Expand Up @@ -291,3 +294,19 @@ func timer(dur *time.Duration, cb func() error) error {
}
return nil
}

// stolen from: https://yourbasic.org/golang/formatting-byte-size-to-human-readable-format/
// ubuntu units policy: https://wiki.ubuntu.com/UnitsPolicy
func byteCountIEC(b int64) string {
const unit = 1024
if b < unit {
return fmt.Sprintf("%d B", b)
}
div, exp := int64(unit), 0
for n := b / unit; n >= unit; n /= unit {
div *= unit
exp++
}
return fmt.Sprintf("%.1f %ciB",
float64(b)/float64(div), "KMGTPE"[exp])
}
1 change: 1 addition & 0 deletions cli/cmd/deploy/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ func (d *Cmd) uploadBinaryToS3(key, binaryPath string) error {
if err != nil {
return err
}
d.uploadBytes += int64(len(buf))
if err := d.awsClient.PutObjectToS3Bucket(d.ctx.Account.Bucket, key, buf); err != nil {
return err
}
Expand Down

0 comments on commit af21295

Please sign in to comment.