Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f0b584f

Browse files
committedMar 28, 2025
feat: add app status tracking to the backend
1 parent ac74c65 commit f0b584f

32 files changed

+1600
-58
lines changed
 

‎cli/testdata/coder_list_--output_json.golden

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
"most_recently_seen": null
7070
}
7171
},
72+
"latest_app_status": null,
7273
"outdated": false,
7374
"name": "test-workspace",
7475
"autostart_schedule": "CRON_TZ=US/Central 30 9 * * 1-5",

‎coderd/apidoc/docs.go

Lines changed: 126 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎coderd/apidoc/swagger.json

Lines changed: 116 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎coderd/coderd.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,6 +1228,7 @@ func New(options *Options) *API {
12281228
}))
12291229
r.Get("/rpc", api.workspaceAgentRPC)
12301230
r.Patch("/logs", api.patchWorkspaceAgentLogs)
1231+
r.Patch("/app-status", api.patchWorkspaceAgentAppStatus)
12311232
// Deprecated: Required to support legacy agents
12321233
r.Get("/gitauth", api.workspaceAgentsGitAuth)
12331234
r.Get("/external-auth", api.workspaceAgentsExternalAuth)

‎coderd/database/db2sdk/db2sdk.go

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ func AppSubdomain(dbApp database.WorkspaceApp, agentName, workspaceName, ownerNa
487487
}.String()
488488
}
489489

490-
func Apps(dbApps []database.WorkspaceApp, agent database.WorkspaceAgent, ownerName string, workspace database.Workspace) []codersdk.WorkspaceApp {
490+
func Apps(dbApps []database.WorkspaceApp, statuses []database.WorkspaceAppStatus, agent database.WorkspaceAgent, ownerName string, workspace database.Workspace) []codersdk.WorkspaceApp {
491491
sort.Slice(dbApps, func(i, j int) bool {
492492
if dbApps[i].DisplayOrder != dbApps[j].DisplayOrder {
493493
return dbApps[i].DisplayOrder < dbApps[j].DisplayOrder
@@ -498,8 +498,14 @@ func Apps(dbApps []database.WorkspaceApp, agent database.WorkspaceAgent, ownerNa
498498
return dbApps[i].Slug < dbApps[j].Slug
499499
})
500500

501+
statusesByAppID := map[uuid.UUID][]database.WorkspaceAppStatus{}
502+
for _, status := range statuses {
503+
statusesByAppID[status.AppID] = append(statusesByAppID[status.AppID], status)
504+
}
505+
501506
apps := make([]codersdk.WorkspaceApp, 0)
502507
for _, dbApp := range dbApps {
508+
statuses := statusesByAppID[dbApp.ID]
503509
apps = append(apps, codersdk.WorkspaceApp{
504510
ID: dbApp.ID,
505511
URL: dbApp.Url.String,
@@ -516,14 +522,33 @@ func Apps(dbApps []database.WorkspaceApp, agent database.WorkspaceAgent, ownerNa
516522
Interval: dbApp.HealthcheckInterval,
517523
Threshold: dbApp.HealthcheckThreshold,
518524
},
519-
Health: codersdk.WorkspaceAppHealth(dbApp.Health),
520-
Hidden: dbApp.Hidden,
521-
OpenIn: codersdk.WorkspaceAppOpenIn(dbApp.OpenIn),
525+
Health: codersdk.WorkspaceAppHealth(dbApp.Health),
526+
Hidden: dbApp.Hidden,
527+
OpenIn: codersdk.WorkspaceAppOpenIn(dbApp.OpenIn),
528+
Statuses: WorkspaceAppStatuses(statuses),
522529
})
523530
}
524531
return apps
525532
}
526533

534+
func WorkspaceAppStatuses(statuses []database.WorkspaceAppStatus) []codersdk.WorkspaceAppStatus {
535+
return List(statuses, WorkspaceAppStatus)
536+
}
537+
538+
func WorkspaceAppStatus(status database.WorkspaceAppStatus) codersdk.WorkspaceAppStatus {
539+
return codersdk.WorkspaceAppStatus{
540+
ID: status.ID,
541+
CreatedAt: status.CreatedAt,
542+
AgentID: status.AgentID,
543+
AppID: status.AppID,
544+
NeedsUserAttention: status.NeedsUserAttention,
545+
URI: status.Uri.String,
546+
Icon: status.Icon.String,
547+
Message: status.Message,
548+
State: codersdk.WorkspaceAppStatusState(status.State),
549+
}
550+
}
551+
527552
func ProvisionerDaemon(dbDaemon database.ProvisionerDaemon) codersdk.ProvisionerDaemon {
528553
result := codersdk.ProvisionerDaemon{
529554
ID: dbDaemon.ID,
There was a problem loading the remainder of the diff.

0 commit comments

Comments
 (0)
Failed to load comments.