diff --git a/coderd/apidoc/docs.go b/coderd/apidoc/docs.go index 76daf4c798e2f..991f5095870f3 100644 --- a/coderd/apidoc/docs.go +++ b/coderd/apidoc/docs.go @@ -11142,6 +11142,9 @@ const docTemplate = `{ "codersdk.WorkspaceAgent": { "type": "object", "properties": { + "api_version": { + "type": "string" + }, "apps": { "type": "array", "items": { diff --git a/coderd/apidoc/swagger.json b/coderd/apidoc/swagger.json index a6908efc1e61e..34c599bb9a04b 100644 --- a/coderd/apidoc/swagger.json +++ b/coderd/apidoc/swagger.json @@ -10108,6 +10108,9 @@ "codersdk.WorkspaceAgent": { "type": "object", "properties": { + "api_version": { + "type": "string" + }, "apps": { "type": "array", "items": { diff --git a/coderd/database/dbmem/dbmem.go b/coderd/database/dbmem/dbmem.go index a0e48473602ad..3a0f32cc8e79d 100644 --- a/coderd/database/dbmem/dbmem.go +++ b/coderd/database/dbmem/dbmem.go @@ -6308,6 +6308,7 @@ func (q *FakeQuerier) UpdateWorkspaceAgentStartupByID(_ context.Context, arg dat } agent.Version = arg.Version + agent.APIVersion = arg.APIVersion agent.ExpandedDirectory = arg.ExpandedDirectory agent.Subsystems = arg.Subsystems q.workspaceAgents[index] = agent diff --git a/coderd/database/queries.sql.go b/coderd/database/queries.sql.go index b1eb3af14719e..ff5aa26afaac8 100644 --- a/coderd/database/queries.sql.go +++ b/coderd/database/queries.sql.go @@ -8039,7 +8039,8 @@ UPDATE SET version = $2, expanded_directory = $3, - subsystems = $4 + subsystems = $4, + api_version = $5 WHERE id = $1 ` @@ -8049,6 +8050,7 @@ type UpdateWorkspaceAgentStartupByIDParams struct { Version string `db:"version" json:"version"` ExpandedDirectory string `db:"expanded_directory" json:"expanded_directory"` Subsystems []WorkspaceAgentSubsystem `db:"subsystems" json:"subsystems"` + APIVersion string `db:"api_version" json:"api_version"` } func (q *sqlQuerier) UpdateWorkspaceAgentStartupByID(ctx context.Context, arg UpdateWorkspaceAgentStartupByIDParams) error { @@ -8057,6 +8059,7 @@ func (q *sqlQuerier) UpdateWorkspaceAgentStartupByID(ctx context.Context, arg Up arg.Version, arg.ExpandedDirectory, pq.Array(arg.Subsystems), + arg.APIVersion, ) return err } diff --git a/coderd/database/queries/workspaceagents.sql b/coderd/database/queries/workspaceagents.sql index 9ecede976c372..7dd2aaa29d6f7 100644 --- a/coderd/database/queries/workspaceagents.sql +++ b/coderd/database/queries/workspaceagents.sql @@ -69,7 +69,8 @@ UPDATE SET version = $2, expanded_directory = $3, - subsystems = $4 + subsystems = $4, + api_version = $5 WHERE id = $1; diff --git a/coderd/workspaceagents.go b/coderd/workspaceagents.go index d6f3a44371e1a..dc2d240384475 100644 --- a/coderd/workspaceagents.go +++ b/coderd/workspaceagents.go @@ -250,6 +250,8 @@ func (api *API) workspaceAgentManifest(rw http.ResponseWriter, r *http.Request) }) } +const AgentAPIVersionREST = "1.0" + // @Summary Submit workspace agent startup // @ID submit-workspace-agent-startup // @Security CoderSessionToken @@ -321,6 +323,7 @@ func (api *API) postWorkspaceAgentStartup(rw http.ResponseWriter, r *http.Reques Version: req.Version, ExpandedDirectory: req.ExpandedDirectory, Subsystems: convertWorkspaceAgentSubsystems(req.Subsystems), + APIVersion: AgentAPIVersionREST, }); err != nil { httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{ Message: "Error setting agent version", @@ -1542,6 +1545,7 @@ func convertWorkspaceAgent(derpMap *tailcfg.DERPMap, coordinator tailnet.Coordin LogsOverflowed: dbAgent.LogsOverflowed, LogSources: logSources, Version: dbAgent.Version, + APIVersion: dbAgent.APIVersion, EnvironmentVariables: envs, Directory: dbAgent.Directory, ExpandedDirectory: dbAgent.ExpandedDirectory, diff --git a/coderd/workspaceagents_test.go b/coderd/workspaceagents_test.go index 10028f91fa3f3..6ca37b1355f4c 100644 --- a/coderd/workspaceagents_test.go +++ b/coderd/workspaceagents_test.go @@ -21,6 +21,7 @@ import ( "cdr.dev/slog" "cdr.dev/slog/sloggers/slogtest" "github.com/coder/coder/v2/agent/agenttest" + "github.com/coder/coder/v2/coderd" "github.com/coder/coder/v2/coderd/coderdtest" "github.com/coder/coder/v2/coderd/database" "github.com/coder/coder/v2/coderd/database/dbtime" @@ -1367,6 +1368,7 @@ func TestWorkspaceAgent_Startup(t *testing.T) { require.Equal(t, expectedDir, wsagent.ExpandedDirectory) // Sorted require.Equal(t, expectedSubsystems, wsagent.Subsystems) + require.Equal(t, coderd.AgentAPIVersionREST, wsagent.APIVersion) }) t.Run("InvalidSemver", func(t *testing.T) { diff --git a/codersdk/deployment_test.go b/codersdk/deployment_test.go index d6846557cd9cc..362cda8e0bd17 100644 --- a/codersdk/deployment_test.go +++ b/codersdk/deployment_test.go @@ -218,7 +218,7 @@ func TestTimezoneOffsets(t *testing.T) { // Name: "Eastern", // Loc: must(time.LoadLocation("America/New_York")), // ExpectedOffset: -4, - //}, + // }, //{ // Name: "Central", // Loc: must(time.LoadLocation("America/Chicago")), diff --git a/codersdk/workspaceagents.go b/codersdk/workspaceagents.go index c59321d607e14..1f098a77f6565 100644 --- a/codersdk/workspaceagents.go +++ b/codersdk/workspaceagents.go @@ -166,6 +166,7 @@ type WorkspaceAgent struct { Directory string `json:"directory,omitempty"` ExpandedDirectory string `json:"expanded_directory,omitempty"` Version string `json:"version"` + APIVersion string `json:"api_version"` Apps []WorkspaceApp `json:"apps"` // DERPLatency is mapped by region name (e.g. "New York City", "Seattle"). DERPLatency map[string]DERPRegion `json:"latency,omitempty"` diff --git a/docs/api/agents.md b/docs/api/agents.md index 0c620f2f95ee5..91f596582f0e1 100644 --- a/docs/api/agents.md +++ b/docs/api/agents.md @@ -699,6 +699,7 @@ curl -X GET http://coder-server:8080/api/v2/workspaceagents/{workspaceagent} \ ```json { + "api_version": "string", "apps": [ { "command": "string", diff --git a/docs/api/builds.md b/docs/api/builds.md index a1e8f25a6e69d..50072c8aa0d46 100644 --- a/docs/api/builds.md +++ b/docs/api/builds.md @@ -58,6 +58,7 @@ curl -X GET http://coder-server:8080/api/v2/users/{user}/workspace/{workspacenam { "agents": [ { + "api_version": "string", "apps": [ { "command": "string", @@ -238,6 +239,7 @@ curl -X GET http://coder-server:8080/api/v2/workspacebuilds/{workspacebuild} \ { "agents": [ { + "api_version": "string", "apps": [ { "command": "string", @@ -557,6 +559,7 @@ curl -X GET http://coder-server:8080/api/v2/workspacebuilds/{workspacebuild}/res { "agents": [ { + "api_version": "string", "apps": [ { "command": "string", @@ -677,6 +680,7 @@ Status Code **200** | ------------------------------- | ------------------------------------------------------------------------------------------------------ | -------- | ------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `[array item]` | array | false | | | | `» agents` | array | false | | | +| `»» api_version` | string | false | | | | `»» apps` | array | false | | | | `»»» command` | string | false | | | | `»»» display_name` | string | false | | Display name is a friendly name for the app. | @@ -844,6 +848,7 @@ curl -X GET http://coder-server:8080/api/v2/workspacebuilds/{workspacebuild}/sta { "agents": [ { + "api_version": "string", "apps": [ { "command": "string", @@ -1029,6 +1034,7 @@ curl -X GET http://coder-server:8080/api/v2/workspaces/{workspace}/builds \ { "agents": [ { + "api_version": "string", "apps": [ { "command": "string", @@ -1185,6 +1191,7 @@ Status Code **200** | `» reason` | [codersdk.BuildReason](schemas.md#codersdkbuildreason) | false | | | | `» resources` | array | false | | | | `»» agents` | array | false | | | +| `»»» api_version` | string | false | | | | `»»» apps` | array | false | | | | `»»»» command` | string | false | | | | `»»»» display_name` | string | false | | Display name is a friendly name for the app. | @@ -1405,6 +1412,7 @@ curl -X POST http://coder-server:8080/api/v2/workspaces/{workspace}/builds \ { "agents": [ { + "api_version": "string", "apps": [ { "command": "string", diff --git a/docs/api/schemas.md b/docs/api/schemas.md index 61e227b2b3f4d..23985414d0727 100644 --- a/docs/api/schemas.md +++ b/docs/api/schemas.md @@ -5642,6 +5642,7 @@ If the schedule is empty, the user will be updated to use the default schedule.| { "agents": [ { + "api_version": "string", "apps": [ { "command": "string", @@ -5812,6 +5813,7 @@ If the schedule is empty, the user will be updated to use the default schedule.| ```json { + "api_version": "string", "apps": [ { "command": "string", @@ -5903,6 +5905,7 @@ If the schedule is empty, the user will be updated to use the default schedule.| | Name | Type | Required | Restrictions | Description | | ---------------------------- | -------------------------------------------------------------------------------------------- | -------- | ------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `api_version` | string | false | | | | `apps` | array of [codersdk.WorkspaceApp](#codersdkworkspaceapp) | false | | | | `architecture` | string | false | | | | `connection_timeout_seconds` | integer | false | | | @@ -6331,6 +6334,7 @@ If the schedule is empty, the user will be updated to use the default schedule.| { "agents": [ { + "api_version": "string", "apps": [ { "command": "string", @@ -6660,6 +6664,7 @@ If the schedule is empty, the user will be updated to use the default schedule.| { "agents": [ { + "api_version": "string", "apps": [ { "command": "string", @@ -6896,6 +6901,7 @@ If the schedule is empty, the user will be updated to use the default schedule.| { "agents": [ { + "api_version": "string", "apps": [ { "command": "string", diff --git a/docs/api/templates.md b/docs/api/templates.md index 08de540e2a7f2..279ab1ff5cfb7 100644 --- a/docs/api/templates.md +++ b/docs/api/templates.md @@ -1704,6 +1704,7 @@ curl -X GET http://coder-server:8080/api/v2/templateversions/{templateversion}/d { "agents": [ { + "api_version": "string", "apps": [ { "command": "string", @@ -1824,6 +1825,7 @@ Status Code **200** | ------------------------------- | ------------------------------------------------------------------------------------------------------ | -------- | ------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `[array item]` | array | false | | | | `» agents` | array | false | | | +| `»» api_version` | string | false | | | | `»» apps` | array | false | | | | `»»» command` | string | false | | | | `»»» display_name` | string | false | | Display name is a friendly name for the app. | @@ -2120,6 +2122,7 @@ curl -X GET http://coder-server:8080/api/v2/templateversions/{templateversion}/r { "agents": [ { + "api_version": "string", "apps": [ { "command": "string", @@ -2240,6 +2243,7 @@ Status Code **200** | ------------------------------- | ------------------------------------------------------------------------------------------------------ | -------- | ------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `[array item]` | array | false | | | | `» agents` | array | false | | | +| `»» api_version` | string | false | | | | `»» apps` | array | false | | | | `»»» command` | string | false | | | | `»»» display_name` | string | false | | Display name is a friendly name for the app. | diff --git a/docs/api/workspaces.md b/docs/api/workspaces.md index 3ade42b54e9c9..3d53fad1711ee 100644 --- a/docs/api/workspaces.md +++ b/docs/api/workspaces.md @@ -90,6 +90,7 @@ curl -X POST http://coder-server:8080/api/v2/organizations/{organization}/member { "agents": [ { + "api_version": "string", "apps": [ { "command": "string", @@ -299,6 +300,7 @@ curl -X GET http://coder-server:8080/api/v2/users/{user}/workspace/{workspacenam { "agents": [ { + "api_version": "string", "apps": [ { "command": "string", @@ -511,6 +513,7 @@ curl -X GET http://coder-server:8080/api/v2/workspaces \ { "agents": [ { + "api_version": "string", "apps": [ { "command": "string", @@ -717,6 +720,7 @@ curl -X GET http://coder-server:8080/api/v2/workspaces/{workspace} \ { "agents": [ { + "api_version": "string", "apps": [ { "command": "string", @@ -1042,6 +1046,7 @@ curl -X PUT http://coder-server:8080/api/v2/workspaces/{workspace}/dormant \ { "agents": [ { + "api_version": "string", "apps": [ { "command": "string", diff --git a/site/src/api/typesGenerated.ts b/site/src/api/typesGenerated.ts index 975e2b8897197..ce7facdc55522 100644 --- a/site/src/api/typesGenerated.ts +++ b/site/src/api/typesGenerated.ts @@ -1387,6 +1387,7 @@ export interface WorkspaceAgent { readonly directory?: string; readonly expanded_directory?: string; readonly version: string; + readonly api_version: string; readonly apps: WorkspaceApp[]; readonly latency?: Record; readonly connection_timeout_seconds: number; diff --git a/site/src/testHelpers/entities.ts b/site/src/testHelpers/entities.ts index 47c8e4d4a1468..9a95ef245e3ca 100644 --- a/site/src/testHelpers/entities.ts +++ b/site/src/testHelpers/entities.ts @@ -585,6 +585,7 @@ export const MockWorkspaceAgent: TypesGen.WorkspaceAgent = { status: "connected", updated_at: "", version: MockBuildInfo.version, + api_version: "1.0", latency: { "Coder Embedded DERP": { latency_ms: 32.55,