mirror of
https://github.com/coder/coder.git
synced 2025-07-15 22:20:27 +00:00
chore: allow multiple agent subsystems, add exectrace (#8933)
This commit is contained in:
@ -14,6 +14,7 @@ import (
|
||||
"net/netip"
|
||||
"net/url"
|
||||
"runtime/pprof"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
@ -219,11 +220,31 @@ func (api *API) postWorkspaceAgentStartup(rw http.ResponseWriter, r *http.Reques
|
||||
return
|
||||
}
|
||||
|
||||
// Validate subsystems.
|
||||
seen := make(map[codersdk.AgentSubsystem]bool)
|
||||
for _, s := range req.Subsystems {
|
||||
if !s.Valid() {
|
||||
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
|
||||
Message: "Invalid workspace agent subsystem provided.",
|
||||
Detail: fmt.Sprintf("invalid subsystem: %q", s),
|
||||
})
|
||||
return
|
||||
}
|
||||
if seen[s] {
|
||||
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
|
||||
Message: "Invalid workspace agent subsystem provided.",
|
||||
Detail: fmt.Sprintf("duplicate subsystem: %q", s),
|
||||
})
|
||||
return
|
||||
}
|
||||
seen[s] = true
|
||||
}
|
||||
|
||||
if err := api.Database.UpdateWorkspaceAgentStartupByID(ctx, database.UpdateWorkspaceAgentStartupByIDParams{
|
||||
ID: apiAgent.ID,
|
||||
Version: req.Version,
|
||||
ExpandedDirectory: req.ExpandedDirectory,
|
||||
Subsystem: convertWorkspaceAgentSubsystem(req.Subsystem),
|
||||
Subsystems: convertWorkspaceAgentSubsystems(req.Subsystems),
|
||||
}); err != nil {
|
||||
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
|
||||
Message: "Error setting agent version",
|
||||
@ -1277,6 +1298,11 @@ func convertWorkspaceAgent(derpMap *tailcfg.DERPMap, coordinator tailnet.Coordin
|
||||
if dbAgent.TroubleshootingURL != "" {
|
||||
troubleshootingURL = dbAgent.TroubleshootingURL
|
||||
}
|
||||
subsystems := make([]codersdk.AgentSubsystem, len(dbAgent.Subsystems))
|
||||
for i, subsystem := range dbAgent.Subsystems {
|
||||
subsystems[i] = codersdk.AgentSubsystem(subsystem)
|
||||
}
|
||||
|
||||
workspaceAgent := codersdk.WorkspaceAgent{
|
||||
ID: dbAgent.ID,
|
||||
CreatedAt: dbAgent.CreatedAt,
|
||||
@ -1302,7 +1328,7 @@ func convertWorkspaceAgent(derpMap *tailcfg.DERPMap, coordinator tailnet.Coordin
|
||||
LoginBeforeReady: dbAgent.StartupScriptBehavior != database.StartupScriptBehaviorBlocking,
|
||||
ShutdownScript: dbAgent.ShutdownScript.String,
|
||||
ShutdownScriptTimeoutSeconds: dbAgent.ShutdownScriptTimeoutSeconds,
|
||||
Subsystem: codersdk.AgentSubsystem(dbAgent.Subsystem),
|
||||
Subsystems: subsystems,
|
||||
}
|
||||
node := coordinator.Node(dbAgent.ID)
|
||||
if node != nil {
|
||||
@ -2114,11 +2140,23 @@ func convertWorkspaceAgentLog(logEntry database.WorkspaceAgentLog) codersdk.Work
|
||||
}
|
||||
}
|
||||
|
||||
func convertWorkspaceAgentSubsystem(ss codersdk.AgentSubsystem) database.WorkspaceAgentSubsystem {
|
||||
switch ss {
|
||||
case codersdk.AgentSubsystemEnvbox:
|
||||
return database.WorkspaceAgentSubsystemEnvbox
|
||||
default:
|
||||
return database.WorkspaceAgentSubsystemNone
|
||||
func convertWorkspaceAgentSubsystems(ss []codersdk.AgentSubsystem) []database.WorkspaceAgentSubsystem {
|
||||
out := make([]database.WorkspaceAgentSubsystem, 0, len(ss))
|
||||
for _, s := range ss {
|
||||
switch s {
|
||||
case codersdk.AgentSubsystemEnvbox:
|
||||
out = append(out, database.WorkspaceAgentSubsystemEnvbox)
|
||||
case codersdk.AgentSubsystemEnvbuilder:
|
||||
out = append(out, database.WorkspaceAgentSubsystemEnvbuilder)
|
||||
case codersdk.AgentSubsystemExectrace:
|
||||
out = append(out, database.WorkspaceAgentSubsystemExectrace)
|
||||
default:
|
||||
// Invalid, drop it.
|
||||
}
|
||||
}
|
||||
|
||||
sort.Slice(out, func(i, j int) bool {
|
||||
return out[i] < out[j]
|
||||
})
|
||||
return out
|
||||
}
|
||||
|
Reference in New Issue
Block a user