Skip to content

Commit

Permalink
Track download rate as well
Browse files Browse the repository at this point in the history
  • Loading branch information
ycombinator committed Oct 17, 2023
1 parent ee57bcc commit 7d86267
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,14 @@ func (dpObs *detailsProgressObserver) Report(sourceURI string, timePast time.Dur
dpObs.mu.Lock()
defer dpObs.mu.Unlock()

dpObs.upgradeDetails.SetDownloadPercent(percentComplete)
dpObs.upgradeDetails.SetDownloadProgress(percentComplete, downloadRate)
}

func (dpObs *detailsProgressObserver) ReportCompleted(sourceURI string, timePast time.Duration, downloadRate float64) {
dpObs.mu.Lock()
defer dpObs.mu.Unlock()

dpObs.upgradeDetails.SetDownloadPercent(1)
dpObs.upgradeDetails.SetDownloadProgress(1, downloadRate)
}

func (dpObs *detailsProgressObserver) ReportFailed(sourceURI string, timePast time.Duration, downloadedBytes, totalBytes, percentComplete, downloadRate float64, err error) {
Expand Down
6 changes: 4 additions & 2 deletions internal/pkg/agent/application/upgrade/details/details.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type Details struct {
type DetailsMetadata struct {
ScheduledAt string
DownloadPercent float64
DownloadRate float64

// FailedState is the state an upgrade was in if/when it failed. Use the
// Fail() method of UpgradeDetails to correctly record details when
Expand Down Expand Up @@ -56,13 +57,14 @@ func (d *Details) SetState(s State) {
d.notifyObservers()
}

// SetDownloadPercent is a convenience method to set the download percent
// SetDownloadProgress is a convenience method to set the download percent
// when the upgrade is in UPG_DOWNLOADING state.
func (d *Details) SetDownloadPercent(downloadPercent float64) {
func (d *Details) SetDownloadProgress(downloadPercent, downloadRate float64) {
d.mu.Lock()
defer d.mu.Unlock()

d.Metadata.DownloadPercent = downloadPercent
d.Metadata.DownloadRate = downloadRate
d.notifyObservers()
}

Expand Down

0 comments on commit 7d86267

Please sign in to comment.