From 2662c4852d57e983288126f9675d3caa324a27a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Tron=C3=AD=C4=8Dek?= Date: Tue, 7 Nov 2023 17:37:59 +0000 Subject: [PATCH] local cli: better logging for `ws stop` --- components/local-app/cmd/workspace-stop.go | 44 ++++++++++++---------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/components/local-app/cmd/workspace-stop.go b/components/local-app/cmd/workspace-stop.go index 32207dc49f8fa0..0bb8239db8ddd1 100644 --- a/components/local-app/cmd/workspace-stop.go +++ b/components/local-app/cmd/workspace-stop.go @@ -34,38 +34,33 @@ var workspaceStopCommand = &cobra.Command{ return err } - slog.Info("stopping workspace...") + slog.Debug("stopping workspace...") wsInfo, err := gitpod.Workspaces.StopWorkspace(ctx, connect.NewRequest(&v1.StopWorkspaceRequest{WorkspaceId: workspaceID})) if err != nil { return err } - currentPhase := wsInfo.Msg.GetResult().Status.Instance.Status.Phase - - if currentPhase == v1.WorkspaceInstanceStatus_PHASE_STOPPED { + wsPhase := wsInfo.Msg.GetResult().Status.Instance.Status.Phase + switch wsPhase { + case v1.WorkspaceInstanceStatus_PHASE_STOPPED: slog.Info("workspace is already stopped") - return nil - } - if currentPhase == v1.WorkspaceInstanceStatus_PHASE_STOPPING { + case v1.WorkspaceInstanceStatus_PHASE_STOPPING: slog.Info("workspace is already stopping") - return nil } + if stopDontWait { slog.Info("workspace stopping") return nil } stream, err := gitpod.Workspaces.StreamWorkspaceStatus(ctx, connect.NewRequest(&v1.StreamWorkspaceStatusRequest{WorkspaceId: workspaceID})) - if err != nil { return err } slog.Info("waiting for workspace to stop...") - slog.Info("workspace " + prettyprint.FormatWorkspacePhase(currentPhase)) previousStatus := "" - for stream.Receive() { msg := stream.Msg() if msg == nil { @@ -73,15 +68,26 @@ var workspaceStopCommand = &cobra.Command{ continue } - if msg.GetResult().Instance.Status.Phase == v1.WorkspaceInstanceStatus_PHASE_STOPPED { - slog.Info("workspace stopped") + wsPhase = msg.GetResult().Instance.Status.Phase + switch wsPhase { + case v1.WorkspaceInstanceStatus_PHASE_STOPPED: + { + slog.Info("workspace stopped") + return nil + } + case v1.WorkspaceInstanceStatus_PHASE_RUNNING: + // Skip reporting the "running" status as it is often the initial state and seems confusing to the user. + // There is some delay between requesting a workspace to stop and it actually stopping, so we don't want + // to report "running" in the meantime. break - } - - currentStatus := prettyprint.FormatWorkspacePhase(msg.GetResult().Instance.Status.Phase) - if currentStatus != previousStatus { - slog.Info("workspace " + currentStatus) - previousStatus = currentStatus + default: + { + currentStatus := prettyprint.FormatWorkspacePhase(wsPhase) + if currentStatus != previousStatus { + slog.Info("workspace status: " + currentStatus) + previousStatus = currentStatus + } + } } }