-
Notifications
You must be signed in to change notification settings - Fork 1.3k
local cli: better logging for ws stop
#19031
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,54 +34,64 @@ 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 | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In Golang we used to |
||
|
||
defer stream.Close() | ||
|
||
slog.Info("waiting for workspace to stop...") | ||
slog.Info("workspace " + prettyprint.FormatWorkspacePhase(currentPhase)) | ||
|
||
previousStatus := "" | ||
|
||
for stream.Receive() { | ||
msg := stream.Msg() | ||
if msg == nil { | ||
slog.Debug("no message received") | ||
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 | ||
mustard-mh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
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 | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -164,9 +164,11 @@ func ObserveWorkspaceUntilStarted(ctx context.Context, clnt *client.Gitpod, work | |
return ws.Status, nil | ||
} | ||
|
||
var wsStatus string | ||
slog.Info("waiting for workspace to start...", "workspaceID", workspaceID) | ||
if HasInstanceStatus(wsInfo.Msg.Result) { | ||
slog.Info("workspace " + prettyprint.FormatWorkspacePhase(wsInfo.Msg.Result.Status.Instance.Status.Phase)) | ||
slog.Info("workspace status: " + prettyprint.FormatWorkspacePhase(wsInfo.Msg.Result.Status.Instance.Status.Phase)) | ||
wsStatus = prettyprint.FormatWorkspacePhase(wsInfo.Msg.Result.Status.Instance.Status.Phase) | ||
} | ||
|
||
var ( | ||
|
@@ -186,7 +188,8 @@ func ObserveWorkspaceUntilStarted(ctx context.Context, clnt *client.Gitpod, work | |
continue | ||
} | ||
|
||
previousStatus := "" | ||
defer stream.Close() | ||
|
||
for stream.Receive() { | ||
msg := stream.Msg() | ||
if msg == nil { | ||
|
@@ -200,13 +203,13 @@ func ObserveWorkspaceUntilStarted(ctx context.Context, clnt *client.Gitpod, work | |
return ws, nil | ||
} | ||
|
||
var currentStatus string | ||
if HasInstanceStatus(wsInfo.Msg.Result) { | ||
currentStatus = prettyprint.FormatWorkspacePhase(wsInfo.Msg.Result.Status.Instance.Status.Phase) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This actually made it so that the status never got updates (should be |
||
} | ||
if currentStatus != previousStatus { | ||
slog.Info("workspace " + currentStatus) | ||
previousStatus = currentStatus | ||
newWsStatus := prettyprint.FormatWorkspacePhase(ws.Instance.Status.Phase) | ||
// De-duplicate status messages | ||
if wsStatus != newWsStatus { | ||
slog.Info("workspace status: " + newWsStatus) | ||
wsStatus = newWsStatus | ||
} | ||
} | ||
} | ||
if err := stream.Err(); err != nil { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By default, we only output the
waiting for workspace to stop...
which can be found below. We essentially had 2 very similar messages, which are more useful for debugging than actually using the CLI.