feat: add computed workspace and agent health fields to the api (#8280)

This commit is contained in:
Mathias Fredriksson
2023-07-10 12:40:11 +03:00
committed by GitHub
parent eabf929676
commit b73f9d8e86
16 changed files with 509 additions and 26 deletions

View File

@ -1110,6 +1110,15 @@ func convertWorkspace(
lockedAt = &workspace.LockedAt.Time
}
failingAgents := []uuid.UUID{}
for _, resource := range workspaceBuild.Resources {
for _, agent := range resource.Agents {
if !agent.Health.Healthy {
failingAgents = append(failingAgents, agent.ID)
}
}
}
var (
ttlMillis = convertWorkspaceTTLMillis(workspace.Ttl)
deletingAt = calculateDeletingAt(workspace, template, workspaceBuild)
@ -1135,6 +1144,10 @@ func convertWorkspace(
LastUsedAt: workspace.LastUsedAt,
DeletingAt: deletingAt,
LockedAt: lockedAt,
Health: codersdk.WorkspaceHealth{
Healthy: len(failingAgents) == 0,
FailingAgents: failingAgents,
},
}
}