Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat(cli): show workspace health in show-command#8548

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
mafredri merged 1 commit intomainfrommafredri/feat-cli-show-health
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletionscli/cliui/resources.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -50,6 +50,7 @@ func WorkspaceResources(writer io.Writer, resources []codersdk.WorkspaceResource
row := table.Row{"Resource"}
if !options.HideAgentState {
row = append(row, "Status")
row = append(row, "Health")
row = append(row, "Version")
}
if !options.HideAccess {
Expand DownExpand Up@@ -81,6 +82,7 @@ func WorkspaceResources(writer io.Writer, resources []codersdk.WorkspaceResource
DefaultStyles.Bold.Render(resourceAddress),
"",
"",
"",
})
// Display all agents associated with the resource.
for index, agent := range resource.Agents {
Expand All@@ -93,13 +95,13 @@ func WorkspaceResources(writer io.Writer, resources []codersdk.WorkspaceResource
fmt.Sprintf("%s─ %s (%s, %s)", pipe, agent.Name, agent.OperatingSystem, agent.Architecture),
}
if !options.HideAgentState {
var agentStatus string
var agentVersion string
var agentStatus, agentHealth, agentVersion string
if !options.HideAgentState {
agentStatus = renderAgentStatus(agent)
agentHealth = renderAgentHealth(agent)
agentVersion = renderAgentVersion(agent.Version, options.ServerVersion)
}
row = append(row, agentStatus, agentVersion)
row = append(row, agentStatus,agentHealth,agentVersion)
}
if !options.HideAccess {
sshCommand := "coder ssh " + options.WorkspaceName
Expand DownExpand Up@@ -141,6 +143,13 @@ func renderAgentStatus(agent codersdk.WorkspaceAgent) string {
}
}

func renderAgentHealth(agent codersdk.WorkspaceAgent) string {
if agent.Health.Healthy {
return DefaultStyles.Keyword.Render("✔ healthy")
}
return DefaultStyles.Error.Render("✘ " + agent.Health.Reason)
}

func renderAgentVersion(agentVersion, serverVersion string) string {
if agentVersion == "" {
agentVersion = "(unknown)"
Expand Down
13 changes: 13 additions & 0 deletionscli/cliui/resources_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -29,6 +29,7 @@ func TestWorkspaceResources(t *testing.T) {
LifecycleState: codersdk.WorkspaceAgentLifecycleCreated,
Architecture: "amd64",
OperatingSystem: "linux",
Health: codersdk.WorkspaceAgentHealth{Healthy: true},
}},
}}, cliui.WorkspaceResourcesOptions{
WorkspaceName: "example",
Expand DownExpand Up@@ -65,6 +66,7 @@ func TestWorkspaceResources(t *testing.T) {
Name: "dev",
OperatingSystem: "linux",
Architecture: "amd64",
Health: codersdk.WorkspaceAgentHealth{Healthy: true},
}},
}, {
Transition: codersdk.WorkspaceTransitionStart,
Expand All@@ -76,13 +78,18 @@ func TestWorkspaceResources(t *testing.T) {
Name: "go",
Architecture: "amd64",
OperatingSystem: "linux",
Health: codersdk.WorkspaceAgentHealth{Healthy: true},
}, {
DisconnectedAt: &disconnected,
Status: codersdk.WorkspaceAgentDisconnected,
LifecycleState: codersdk.WorkspaceAgentLifecycleReady,
Name: "postgres",
Architecture: "amd64",
OperatingSystem: "linux",
Health: codersdk.WorkspaceAgentHealth{
Healthy: false,
Reason: "agent has lost connection",
},
}},
}}, cliui.WorkspaceResourcesOptions{
WorkspaceName: "dev",
Expand All@@ -94,6 +101,12 @@ func TestWorkspaceResources(t *testing.T) {
}()
ptty.ExpectMatch("google_compute_disk.root")
ptty.ExpectMatch("google_compute_instance.dev")
ptty.ExpectMatch("healthy")
ptty.ExpectMatch("coder ssh dev.dev")
ptty.ExpectMatch("kubernetes_pod.dev")
ptty.ExpectMatch("healthy")
ptty.ExpectMatch("coder ssh dev.go")
ptty.ExpectMatch("agent has lost connection")
ptty.ExpectMatch("coder ssh dev.postgres")
<-done
})
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp