Skip to content

Commit 3762e8d

Browse files
committed
Check if there are logs when displaying features
1 parent 6e1032c commit 3762e8d

File tree

12 files changed

+60
-0
lines changed

12 files changed

+60
-0
lines changed

coderd/apidoc/docs.go

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/workspaceagents.go

+25
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,30 @@ func (api *API) patchWorkspaceAgentStartupLogs(rw http.ResponseWriter, r *http.R
302302
})
303303
return
304304
}
305+
if workspaceAgent.StartupLogsLength == 0 {
306+
// If these are the first logs being appended, we publish a UI update
307+
// to notify the UI that logs are now available.
308+
resource, err := api.Database.GetWorkspaceResourceByID(ctx, workspaceAgent.ResourceID)
309+
if err != nil {
310+
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
311+
Message: "Failed to get workspace resource.",
312+
Detail: err.Error(),
313+
})
314+
return
315+
}
316+
317+
build, err := api.Database.GetWorkspaceBuildByJobID(ctx, resource.JobID)
318+
if err != nil {
319+
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
320+
Message: "Internal error fetching workspace build job.",
321+
Detail: err.Error(),
322+
})
323+
return
324+
}
325+
326+
api.publishWorkspaceUpdate(ctx, build.WorkspaceID)
327+
}
328+
305329
lowestID := logs[0].ID
306330
// Publish by the lowest log ID inserted so the
307331
// log stream will fetch everything from that point.
@@ -1140,6 +1164,7 @@ func convertWorkspaceAgent(derpMap *tailcfg.DERPMap, coordinator tailnet.Coordin
11401164
Architecture: dbAgent.Architecture,
11411165
OperatingSystem: dbAgent.OperatingSystem,
11421166
StartupScript: dbAgent.StartupScript.String,
1167+
StartupLogsLength: dbAgent.StartupLogsLength,
11431168
StartupLogsOverflowed: dbAgent.StartupLogsOverflowed,
11441169
Version: dbAgent.Version,
11451170
EnvironmentVariables: envs,

codersdk/workspaceagents.go

+1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ type WorkspaceAgent struct {
9090
EnvironmentVariables map[string]string `json:"environment_variables"`
9191
OperatingSystem string `json:"operating_system"`
9292
StartupScript string `json:"startup_script,omitempty"`
93+
StartupLogsLength int32 `json:"startup_logs_length"`
9394
StartupLogsOverflowed bool `json:"startup_logs_overflowed"`
9495
Directory string `json:"directory,omitempty"`
9596
ExpandedDirectory string `json:"expanded_directory,omitempty"`

docs/api/agents.md

+1
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,7 @@ curl -X GET http://coder-server:8080/api/v2/workspaceagents/{workspaceagent} \
519519
"resource_id": "4d5215ed-38bb-48ed-879a-fdb9ca58522f",
520520
"shutdown_script": "string",
521521
"shutdown_script_timeout_seconds": 0,
522+
"startup_logs_length": 0,
522523
"startup_logs_overflowed": true,
523524
"startup_script": "string",
524525
"startup_script_timeout_seconds": 0,

docs/api/builds.md

+8
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ curl -X GET http://coder-server:8080/api/v2/users/{user}/workspace/{workspacenam
106106
"resource_id": "4d5215ed-38bb-48ed-879a-fdb9ca58522f",
107107
"shutdown_script": "string",
108108
"shutdown_script_timeout_seconds": 0,
109+
"startup_logs_length": 0,
109110
"startup_logs_overflowed": true,
110111
"startup_script": "string",
111112
"startup_script_timeout_seconds": 0,
@@ -257,6 +258,7 @@ curl -X GET http://coder-server:8080/api/v2/workspacebuilds/{workspacebuild} \
257258
"resource_id": "4d5215ed-38bb-48ed-879a-fdb9ca58522f",
258259
"shutdown_script": "string",
259260
"shutdown_script_timeout_seconds": 0,
261+
"startup_logs_length": 0,
260262
"startup_logs_overflowed": true,
261263
"startup_script": "string",
262264
"startup_script_timeout_seconds": 0,
@@ -549,6 +551,7 @@ curl -X GET http://coder-server:8080/api/v2/workspacebuilds/{workspacebuild}/res
549551
"resource_id": "4d5215ed-38bb-48ed-879a-fdb9ca58522f",
550552
"shutdown_script": "string",
551553
"shutdown_script_timeout_seconds": 0,
554+
"startup_logs_length": 0,
552555
"startup_logs_overflowed": true,
553556
"startup_script": "string",
554557
"startup_script_timeout_seconds": 0,
@@ -630,6 +633,7 @@ Status Code **200**
630633
| `»» resource_id` | string(uuid) | false | | |
631634
| `»» shutdown_script` | string | false | | |
632635
| `»» shutdown_script_timeout_seconds` | integer | false | | |
636+
| `»» startup_logs_length` | integer | false | | |
633637
| `»» startup_logs_overflowed` | boolean | false | | |
634638
| `»» startup_script` | string | false | | |
635639
| `»» startup_script_timeout_seconds` | integer | false | | »startup script timeout seconds is the number of seconds to wait for the startup script to complete. If the script does not complete within this time, the agent lifecycle will be marked as start_timeout. |
@@ -785,6 +789,7 @@ curl -X GET http://coder-server:8080/api/v2/workspacebuilds/{workspacebuild}/sta
785789
"resource_id": "4d5215ed-38bb-48ed-879a-fdb9ca58522f",
786790
"shutdown_script": "string",
787791
"shutdown_script_timeout_seconds": 0,
792+
"startup_logs_length": 0,
788793
"startup_logs_overflowed": true,
789794
"startup_script": "string",
790795
"startup_script_timeout_seconds": 0,
@@ -941,6 +946,7 @@ curl -X GET http://coder-server:8080/api/v2/workspaces/{workspace}/builds \
941946
"resource_id": "4d5215ed-38bb-48ed-879a-fdb9ca58522f",
942947
"shutdown_script": "string",
943948
"shutdown_script_timeout_seconds": 0,
949+
"startup_logs_length": 0,
944950
"startup_logs_overflowed": true,
945951
"startup_script": "string",
946952
"startup_script_timeout_seconds": 0,
@@ -1056,6 +1062,7 @@ Status Code **200**
10561062
| `»»» resource_id` | string(uuid) | false | | |
10571063
| `»»» shutdown_script` | string | false | | |
10581064
| `»»» shutdown_script_timeout_seconds` | integer | false | | |
1065+
| `»»» startup_logs_length` | integer | false | | |
10591066
| `»»» startup_logs_overflowed` | boolean | false | | |
10601067
| `»»» startup_script` | string | false | | |
10611068
| `»»» startup_script_timeout_seconds` | integer | false | | »»startup script timeout seconds is the number of seconds to wait for the startup script to complete. If the script does not complete within this time, the agent lifecycle will be marked as start_timeout. |
@@ -1273,6 +1280,7 @@ curl -X POST http://coder-server:8080/api/v2/workspaces/{workspace}/builds \
12731280
"resource_id": "4d5215ed-38bb-48ed-879a-fdb9ca58522f",
12741281
"shutdown_script": "string",
12751282
"shutdown_script_timeout_seconds": 0,
1283+
"startup_logs_length": 0,
12761284
"startup_logs_overflowed": true,
12771285
"startup_script": "string",
12781286
"startup_script_timeout_seconds": 0,

docs/api/schemas.md

+6
Original file line numberDiff line numberDiff line change
@@ -4342,6 +4342,7 @@ Parameter represents a set value for the scope.
43424342
"resource_id": "4d5215ed-38bb-48ed-879a-fdb9ca58522f",
43434343
"shutdown_script": "string",
43444344
"shutdown_script_timeout_seconds": 0,
4345+
"startup_logs_length": 0,
43454346
"startup_logs_overflowed": true,
43464347
"startup_script": "string",
43474348
"startup_script_timeout_seconds": 0,
@@ -4470,6 +4471,7 @@ Parameter represents a set value for the scope.
44704471
"resource_id": "4d5215ed-38bb-48ed-879a-fdb9ca58522f",
44714472
"shutdown_script": "string",
44724473
"shutdown_script_timeout_seconds": 0,
4474+
"startup_logs_length": 0,
44734475
"startup_logs_overflowed": true,
44744476
"startup_script": "string",
44754477
"startup_script_timeout_seconds": 0,
@@ -4506,6 +4508,7 @@ Parameter represents a set value for the scope.
45064508
| `resource_id` | string | false | | |
45074509
| `shutdown_script` | string | false | | |
45084510
| `shutdown_script_timeout_seconds` | integer | false | | |
4511+
| `startup_logs_length` | integer | false | | |
45094512
| `startup_logs_overflowed` | boolean | false | | |
45104513
| `startup_script` | string | false | | |
45114514
| `startup_script_timeout_seconds` | integer | false | | Startup script timeout seconds is the number of seconds to wait for the startup script to complete. If the script does not complete within this time, the agent lifecycle will be marked as start_timeout. |
@@ -4835,6 +4838,7 @@ Parameter represents a set value for the scope.
48354838
"resource_id": "4d5215ed-38bb-48ed-879a-fdb9ca58522f",
48364839
"shutdown_script": "string",
48374840
"shutdown_script_timeout_seconds": 0,
4841+
"startup_logs_length": 0,
48384842
"startup_logs_overflowed": true,
48394843
"startup_script": "string",
48404844
"startup_script_timeout_seconds": 0,
@@ -5055,6 +5059,7 @@ Parameter represents a set value for the scope.
50555059
"resource_id": "4d5215ed-38bb-48ed-879a-fdb9ca58522f",
50565060
"shutdown_script": "string",
50575061
"shutdown_script_timeout_seconds": 0,
5062+
"startup_logs_length": 0,
50585063
"startup_logs_overflowed": true,
50595064
"startup_script": "string",
50605065
"startup_script_timeout_seconds": 0,
@@ -5251,6 +5256,7 @@ Parameter represents a set value for the scope.
52515256
"resource_id": "4d5215ed-38bb-48ed-879a-fdb9ca58522f",
52525257
"shutdown_script": "string",
52535258
"shutdown_script_timeout_seconds": 0,
5259+
"startup_logs_length": 0,
52545260
"startup_logs_overflowed": true,
52555261
"startup_script": "string",
52565262
"startup_script_timeout_seconds": 0,

0 commit comments

Comments
 (0)