From f64322576a86c5b35489bf1adfca73e03aaba4ef Mon Sep 17 00:00:00 2001 From: Dmitrii Stepanov Date: Mon, 29 May 2023 18:44:46 +0300 Subject: [PATCH] [#402] cli: Add estimated evacuation time left Signed-off-by: Dmitrii Stepanov --- cmd/frostfs-cli/modules/control/evacuation.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/cmd/frostfs-cli/modules/control/evacuation.go b/cmd/frostfs-cli/modules/control/evacuation.go index 45152fa0a1..4eb6505cf4 100644 --- a/cmd/frostfs-cli/modules/control/evacuation.go +++ b/cmd/frostfs-cli/modules/control/evacuation.go @@ -212,9 +212,28 @@ func printStatus(cmd *cobra.Command, resp *control.GetShardEvacuationStatusRespo appendError(sb, resp) appendStartedAt(sb, resp) appendDuration(sb, resp) + appendEstimation(sb, resp) cmd.Println(sb.String()) } +func appendEstimation(sb *strings.Builder, resp *control.GetShardEvacuationStatusResponse) { + if resp.GetBody().GetStatus() != control.GetShardEvacuationStatusResponse_Body_RUNNING || + resp.GetBody().GetDuration() == nil || + resp.GetBody().GetTotal() == 0 || + resp.GetBody().GetEvacuated()+resp.GetBody().GetFailed() == 0 { + return + } + + durationSeconds := float64(resp.GetBody().GetDuration().GetSeconds()) + evacuated := float64(resp.GetBody().GetEvacuated() + resp.GetBody().GetFailed()) + avgObjEvacuationTimeSeconds := durationSeconds / evacuated + objectsLeft := float64(resp.GetBody().GetTotal()) - evacuated + leftSeconds := avgObjEvacuationTimeSeconds * objectsLeft + leftMinutes := int(leftSeconds / 60) + + sb.WriteString(fmt.Sprintf(" Estimated time left: %d minutes.", leftMinutes)) +} + func appendDuration(sb *strings.Builder, resp *control.GetShardEvacuationStatusResponse) { if resp.GetBody().GetDuration() != nil { duration := time.Second * time.Duration(resp.GetBody().GetDuration().GetSeconds())