lib/backup/actions: update vm_backups_uploaded_bytes_total metric along the file upload instead of after the file upload

This solves two issues:

1. The vm_backups_uploaded_bytes_total metric will grow more smoothly
2. This prevents from int overflow at metrics.Counter.Add() when uploading files bigger than 2GiB
This commit is contained in:
Aliaksandr Valialkin 2024-02-24 01:07:18 +02:00
parent ece86cd314
commit 906a35bdbb
No known key found for this signature in database
GPG key ID: 52C003EE2BCDB9EB

View file

@ -170,7 +170,6 @@ func runBackup(src *fslocal.FS, dst common.RemoteFS, origin common.OriginFS, con
prc := 100 * float64(n) / float64(uploadSize)
logger.Infof("uploaded %d out of %d bytes (%.2f%%) from %s to %s in %s", n, uploadSize, prc, src, dst, elapsed)
})
bytesUploadedTotal.Add(int(bytesUploaded.Load()))
if err != nil {
return err
}
@ -191,6 +190,7 @@ type statReader struct {
func (sr *statReader) Read(p []byte) (int, error) {
n, err := sr.r.Read(p)
sr.bytesRead.Add(uint64(n))
bytesUploadedTotal.Add(int(n))
return n, err
}