-
Notifications
You must be signed in to change notification settings - Fork 943
feat(coderd): return agent script timings #14923
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
1b62a39
3daab59
1c6671e
15ca638
ddde7a3
5abc511
bcd8b04
f4c3331
2852164
b70628a
9e09c64
7786166
ed4cbd0
920e41d
65aeeea
c7ae412
aaedd1c
a846eb7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Add the agent script timings into the `/workspaces/:workspaceId/timings` response.
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5793,6 +5793,67 @@ | |
return database.WorkspaceAgentPortShare{}, sql.ErrNoRows | ||
} | ||
|
||
func (q *FakeQuerier) GetWorkspaceAgentScriptTimingsByWorkspaceID(ctx context.Context, workspaceID uuid.UUID) ([]database.GetWorkspaceAgentScriptTimingsByWorkspaceIDRow, error) { | ||
q.mutex.RLock() | ||
defer q.mutex.RUnlock() | ||
|
||
build, err := q.getLatestWorkspaceBuildByWorkspaceIDNoLock(ctx, workspaceID) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
resources, err := q.GetWorkspaceResourcesByJobID(ctx, build.JobID) | ||
if err != nil { | ||
return nil, err | ||
} | ||
resourceIDs := make([]uuid.UUID, 0, len(resources)) | ||
for _, res := range resources { | ||
resourceIDs = append(resourceIDs, res.ID) | ||
} | ||
|
||
agents, err := q.GetWorkspaceAgentsByResourceIDs(ctx, resourceIDs) | ||
if err != nil { | ||
return nil, err | ||
} | ||
agentIDs := make([]uuid.UUID, 0, len(agents)) | ||
for _, agent := range agents { | ||
agentIDs = append(agentIDs, agent.ID) | ||
} | ||
|
||
scripts, err := q.GetWorkspaceAgentScriptsByAgentIDs(ctx, agentIDs) | ||
if err != nil { | ||
return nil, err | ||
} | ||
scriptIDs := make([]uuid.UUID, 0, len(scripts)) | ||
for _, script := range scripts { | ||
scriptIDs = append(scriptIDs, script.ID) | ||
} | ||
|
||
rows := []database.GetWorkspaceAgentScriptTimingsByWorkspaceIDRow{} | ||
for _, t := range q.workspaceAgentScriptTimings { | ||
if slices.Contains(scriptIDs, t.ScriptID) { | ||
var script database.WorkspaceAgentScript | ||
for _, s := range scripts { | ||
if s.ID == t.ScriptID { | ||
script = s | ||
break | ||
} | ||
} | ||
|
||
rows = append(rows, database.GetWorkspaceAgentScriptTimingsByWorkspaceIDRow{ | ||
ScriptID: t.ScriptID, | ||
StartedAt: t.StartedAt, | ||
EndedAt: t.EndedAt, | ||
ExitCode: t.ExitCode, | ||
Stage: t.Stage, | ||
Status: t.Status, | ||
DisplayName: script.DisplayName, | ||
}) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: reduce nesting by keeping the happy path unindented. i.e. |
||
} | ||
return rows, nil | ||
} | ||
|
||
func (q *FakeQuerier) GetWorkspaceAgentScriptsByAgentIDs(_ context.Context, ids []uuid.UUID) ([]database.WorkspaceAgentScript, error) { | ||
q.mutex.RLock() | ||
defer q.mutex.RUnlock() | ||
|
@@ -7844,28 +7905,26 @@ | |
return nil | ||
} | ||
|
||
func (q *FakeQuerier) InsertWorkspaceAgentScriptTimings(_ context.Context, arg database.InsertWorkspaceAgentScriptTimingsParams) error { | ||
func (q *FakeQuerier) InsertWorkspaceAgentScriptTimings(_ context.Context, arg database.InsertWorkspaceAgentScriptTimingsParams) (database.WorkspaceAgentScriptTiming, error) { | ||
err := validateDatabaseType(arg) | ||
if err != nil { | ||
return err | ||
return database.WorkspaceAgentScriptTiming{}, err | ||
} | ||
|
||
q.mutex.Lock() | ||
defer q.mutex.Unlock() | ||
|
||
q.workspaceAgentScriptTimings = append(q.workspaceAgentScriptTimings, | ||
//nolint:gosimple // Stop the linter complaining about changing the type of `arg`. | ||
database.WorkspaceAgentScriptTiming{ | ||
ScriptID: arg.ScriptID, | ||
StartedAt: arg.StartedAt, | ||
EndedAt: arg.EndedAt, | ||
ExitCode: arg.ExitCode, | ||
Stage: arg.Stage, | ||
Status: arg.Status, | ||
}, | ||
) | ||
timing := database.WorkspaceAgentScriptTiming{ | ||
Check failure on line 7917 in coderd/database/dbmem/dbmem.go
|
||
ScriptID: arg.ScriptID, | ||
StartedAt: arg.StartedAt, | ||
EndedAt: arg.EndedAt, | ||
ExitCode: arg.ExitCode, | ||
Stage: arg.Stage, | ||
Status: arg.Status, | ||
} | ||
q.workspaceAgentScriptTimings = append(q.workspaceAgentScriptTimings, timing) | ||
|
||
return nil | ||
return timing, nil | ||
} | ||
|
||
func (q *FakeQuerier) InsertWorkspaceAgentScripts(_ context.Context, arg database.InsertWorkspaceAgentScriptsParams) ([]database.WorkspaceAgentScript, error) { | ||
|
CF59 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please wrap these errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean by " wrap these errors"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This adds context for what might be a fairly generic error.