Skip to content

Commit 8ea956f

Browse files
authored
feat: add app status tracking to the backend (#17163)
This does ~95% of the backend work required to integrate the AI work. Most left to integrate from the tasks branch is just frontend, which will be a lot smaller I believe. The real difference between this branch and that one is the abstraction -- this now attaches statuses to apps, and returns the latest status reported as part of a workspace. This change enables us to have a similar UX to in the tasks branch, but for agents other than Claude Code as well. Any app can report status now.
1 parent 489641d commit 8ea956f

35 files changed

+1668
-69
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: 127 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: 117 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,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy