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

Commitd467160

Browse files
authored
feat(cli): show workspace health in show (#8548)
1 parent6b978be commitd467160

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

‎cli/cliui/resources.go‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ func WorkspaceResources(writer io.Writer, resources []codersdk.WorkspaceResource
5050
row:= table.Row{"Resource"}
5151
if!options.HideAgentState {
5252
row=append(row,"Status")
53+
row=append(row,"Health")
5354
row=append(row,"Version")
5455
}
5556
if!options.HideAccess {
@@ -81,6 +82,7 @@ func WorkspaceResources(writer io.Writer, resources []codersdk.WorkspaceResource
8182
DefaultStyles.Bold.Render(resourceAddress),
8283
"",
8384
"",
85+
"",
8486
})
8587
// Display all agents associated with the resource.
8688
forindex,agent:=rangeresource.Agents {
@@ -93,13 +95,13 @@ func WorkspaceResources(writer io.Writer, resources []codersdk.WorkspaceResource
9395
fmt.Sprintf("%s─ %s (%s, %s)",pipe,agent.Name,agent.OperatingSystem,agent.Architecture),
9496
}
9597
if!options.HideAgentState {
96-
varagentStatusstring
97-
varagentVersionstring
98+
varagentStatus,agentHealth,agentVersionstring
9899
if!options.HideAgentState {
99100
agentStatus=renderAgentStatus(agent)
101+
agentHealth=renderAgentHealth(agent)
100102
agentVersion=renderAgentVersion(agent.Version,options.ServerVersion)
101103
}
102-
row=append(row,agentStatus,agentVersion)
104+
row=append(row,agentStatus,agentHealth,agentVersion)
103105
}
104106
if!options.HideAccess {
105107
sshCommand:="coder ssh "+options.WorkspaceName
@@ -141,6 +143,13 @@ func renderAgentStatus(agent codersdk.WorkspaceAgent) string {
141143
}
142144
}
143145

146+
funcrenderAgentHealth(agent codersdk.WorkspaceAgent)string {
147+
ifagent.Health.Healthy {
148+
returnDefaultStyles.Keyword.Render("✔ healthy")
149+
}
150+
returnDefaultStyles.Error.Render("✘ "+agent.Health.Reason)
151+
}
152+
144153
funcrenderAgentVersion(agentVersion,serverVersionstring)string {
145154
ifagentVersion=="" {
146155
agentVersion="(unknown)"

‎cli/cliui/resources_test.go‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ func TestWorkspaceResources(t *testing.T) {
2929
LifecycleState:codersdk.WorkspaceAgentLifecycleCreated,
3030
Architecture:"amd64",
3131
OperatingSystem:"linux",
32+
Health: codersdk.WorkspaceAgentHealth{Healthy:true},
3233
}},
3334
}}, cliui.WorkspaceResourcesOptions{
3435
WorkspaceName:"example",
@@ -65,6 +66,7 @@ func TestWorkspaceResources(t *testing.T) {
6566
Name:"dev",
6667
OperatingSystem:"linux",
6768
Architecture:"amd64",
69+
Health: codersdk.WorkspaceAgentHealth{Healthy:true},
6870
}},
6971
}, {
7072
Transition:codersdk.WorkspaceTransitionStart,
@@ -76,13 +78,18 @@ func TestWorkspaceResources(t *testing.T) {
7678
Name:"go",
7779
Architecture:"amd64",
7880
OperatingSystem:"linux",
81+
Health: codersdk.WorkspaceAgentHealth{Healthy:true},
7982
}, {
8083
DisconnectedAt:&disconnected,
8184
Status:codersdk.WorkspaceAgentDisconnected,
8285
LifecycleState:codersdk.WorkspaceAgentLifecycleReady,
8386
Name:"postgres",
8487
Architecture:"amd64",
8588
OperatingSystem:"linux",
89+
Health: codersdk.WorkspaceAgentHealth{
90+
Healthy:false,
91+
Reason:"agent has lost connection",
92+
},
8693
}},
8794
}}, cliui.WorkspaceResourcesOptions{
8895
WorkspaceName:"dev",
@@ -94,6 +101,12 @@ func TestWorkspaceResources(t *testing.T) {
94101
}()
95102
ptty.ExpectMatch("google_compute_disk.root")
96103
ptty.ExpectMatch("google_compute_instance.dev")
104+
ptty.ExpectMatch("healthy")
105+
ptty.ExpectMatch("coder ssh dev.dev")
106+
ptty.ExpectMatch("kubernetes_pod.dev")
107+
ptty.ExpectMatch("healthy")
108+
ptty.ExpectMatch("coder ssh dev.go")
109+
ptty.ExpectMatch("agent has lost connection")
97110
ptty.ExpectMatch("coder ssh dev.postgres")
98111
<-done
99112
})

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp