Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1309827

Browse files
committed
feat: add level support for startup logs
This allows external services like our devcontainer support to displayerrors and warnings with custom styles to indicate failures to users.
1 parente5c6ebd commit1309827

File tree

16 files changed

+85
-24
lines changed

16 files changed

+85
-24
lines changed

‎coderd/apidoc/docs.go‎

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

‎coderd/apidoc/swagger.json‎

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

‎coderd/database/dbfake/databasefake.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3706,6 +3706,7 @@ func (q *fakeQuerier) InsertWorkspaceAgentStartupLogs(_ context.Context, arg dat
37063706
ID:id,
37073707
AgentID:arg.AgentID,
37083708
CreatedAt:arg.CreatedAt[index],
3709+
Level:arg.Level[index],
37093710
Output:output,
37103711
})
37113712
outputLength+=int32(len(output))

‎coderd/database/dump.sql‎

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTERTABLE workspace_agent_startup_logs
2+
DROP COLUMN level;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTERTABLE workspace_agent_startup_logs
2+
ADD COLUMN level log_levelNOT NULL DEFAULT'info'::log_level;

‎coderd/database/models.go‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/queries.sql.go‎

Lines changed: 9 additions & 4 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/queries/workspaceagents.sql‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ INSERT INTO
155155
SELECT
156156
@agent_id :: uuidAS agent_id,
157157
unnest(@created_at ::timestamptz [ ])AS created_at,
158-
unnest(@output ::VARCHAR(1024) [ ])AS output
158+
unnest(@output ::VARCHAR(1024) [ ])AS output,
159+
unnest(@level :: log_level [ ])AS level
159160
RETURNING workspace_agent_startup_logs.*;
160161

161162
-- If an agent hasn't connected in the last 7 days, we purge it's logs.

‎coderd/workspaceagents.go‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,16 +256,31 @@ func (api *API) patchWorkspaceAgentStartupLogs(rw http.ResponseWriter, r *http.R
256256
}
257257
createdAt:=make([]time.Time,0)
258258
output:=make([]string,0)
259+
level:=make([]database.LogLevel,0)
259260
outputLength:=0
260261
for_,log:=rangereq.Logs {
261262
createdAt=append(createdAt,log.CreatedAt)
262263
output=append(output,log.Output)
263264
outputLength+=len(log.Output)
265+
iflog.Level=="" {
266+
// Default to "info" to support older agents that didn't have the level field.
267+
log.Level=codersdk.LogLevelInfo
268+
}
269+
parsedLevel:=database.LogLevel(log.Level)
270+
if!parsedLevel.Valid() {
271+
httpapi.Write(ctx,rw,http.StatusBadRequest, codersdk.Response{
272+
Message:"Invalid log level provided.",
273+
Detail:fmt.Sprintf("invalid log level: %q",log.Level),
274+
})
275+
return
276+
}
277+
level=append(level,parsedLevel)
264278
}
265279
logs,err:=api.Database.InsertWorkspaceAgentStartupLogs(ctx, database.InsertWorkspaceAgentStartupLogsParams{
266280
AgentID:workspaceAgent.ID,
267281
CreatedAt:createdAt,
268282
Output:output,
283+
Level:level,
269284
OutputLength:int32(outputLength),
270285
})
271286
iferr!=nil {
@@ -1971,5 +1986,6 @@ func convertWorkspaceAgentStartupLog(log database.WorkspaceAgentStartupLog) code
19711986
ID:log.ID,
19721987
CreatedAt:log.CreatedAt,
19731988
Output:log.Output,
1989+
Level:codersdk.LogLevel(log.Level),
19741990
}
19751991
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp