Skip to content

Commit

Permalink
fix(managerclient): progress, round success % down and error % up
Browse files Browse the repository at this point in the history
This approach is safer than printing 0% error when only a fraction of a task has failed.

Fixes #3581
  • Loading branch information
Michal-Leszczynski committed Sep 26, 2023
1 parent 060ca8b commit bcd9b3f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
18 changes: 7 additions & 11 deletions pkg/managerclient/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,9 @@ func FormatRepairProgress(total, success, failed int64) string {
if total == 0 {
return "-"
}
out := fmt.Sprintf("%.f%%",
float64(success)*100/float64(total),
)
out := fmt.Sprintf("%.f%%", math.Floor(float64(success)*100/float64(total)))
if failed > 0 {
out += fmt.Sprintf("/%.f%%", float64(failed)*100/float64(total))
out += fmt.Sprintf("/%.f%%", math.Ceil(float64(failed)*100/float64(total)))
}
return out
}
Expand Down Expand Up @@ -128,11 +126,9 @@ func FormatUploadProgress(size, uploaded, skipped, failed int64) string {
return "100%"
}
transferred := uploaded + skipped
out := fmt.Sprintf("%d%%",
transferred*100/size,
)
out := fmt.Sprintf("%.f%%", math.Floor(float64(transferred)*100/float64(size)))
if failed > 0 {
out += fmt.Sprintf("/%d%%", failed*100/size)
out += fmt.Sprintf("/%.f%%", math.Ceil(float64(failed)*100/float64(size)))
}
return out
}
Expand All @@ -142,10 +138,10 @@ func FormatRestoreProgress(size, restored, downloaded, failed int64) string {
if size == 0 {
return "100%"
}
out := fmt.Sprintf("%d%%", restored*100/size)
out += fmt.Sprintf(" | %d%%", downloaded*100/size)
out := fmt.Sprintf("%.f%%", math.Floor(float64(restored)*100/float64(size)))
out += fmt.Sprintf(" | %.f%%", math.Floor(float64(downloaded)*100/float64(size)))
if failed > 0 {
out += fmt.Sprintf(" / failed: %d%%", failed*100/size)
out += fmt.Sprintf(" / failed: %.f%%", math.Ceil(float64(failed)*100/float64(size)))
}
return out
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/managerclient/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,14 +264,14 @@ func TestFormatRepairProgress(t *testing.T) {
Total: 1536,
Success: 1228,
Failed: 308,
Golden: "80%/20%",
Golden: "79%/21%",
},
{
Name: "partial failure not-complete",
Total: 1536,
Success: 1229,
Failed: 154,
Golden: "80%/10%",
Golden: "80%/11%",
},
}

Expand Down

0 comments on commit bcd9b3f

Please sign in to comment.