feat(coderd): return agent script timings#14923
Conversation
Add the agent script timings into the `/workspaces/:workspaceId/timings` response.
dannykopping
left a comment
There was a problem hiding this comment.
Good start, but I think this needs some hardening.
| 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.
Nit: reduce nesting by keeping the happy path unindented.
i.e. continue if the slice does not contain what you're looking for.
|
@dannykopping I'm not sure if I addressed all your comments, but since I made a bunch of changes, I feel it is time for a second review round. |
dannykopping
left a comment
There was a problem hiding this comment.
Great work @BrunoQuaresma!
| r.Post("/", api.postWorkspaceAgentPortShare) | ||
| r.Delete("/", api.deleteWorkspaceAgentPortShare) | ||
| }) | ||
| r.Get("/timings", api.workspaceTimings) |
There was a problem hiding this comment.
We should check if this endpoint got included in a release. If it has, we'll have to keep it.
There was a problem hiding this comment.
@BrunoQuaresma In theory this is a breaking change... is there any frontend component using it?
There was a problem hiding this comment.
Even if there isn't a frontend using it, customers might have already started integrating with it.
|
|
||
| build, err := q.GetWorkspaceBuildByID(ctx, id) | ||
| if err != nil { | ||
| return nil, err |
There was a problem hiding this comment.
Please wrap these errors.
There was a problem hiding this comment.
What do you mean by " wrap these errors"?
There was a problem hiding this comment.
| return nil, err | |
| return nil, xerrors.Errorf("failed to retrieve workspace build: %w", err) |
This adds context for what might be a fairly generic error.
|
|
||
| // When: fetching an inexistent build | ||
| buildID := uuid.New() | ||
| _, err := client.WorkspaceBuildTimings(context.Background(), buildID) |
There was a problem hiding this comment.
Instead of using context.Background, use a context which has a timeout.
mtojek
left a comment
There was a problem hiding this comment.
I marked some Danny's comments as important. I think the rest can be pushed in the follow-up or next iteration 👍
|
|
||
| // When: fetching an inexistent build | ||
| buildID := uuid.New() | ||
| _, err := client.WorkspaceBuildTimings(context.Background(), buildID) |
|
|
||
| build, err := q.GetWorkspaceBuildByID(ctx, id) | ||
| if err != nil { | ||
| return nil, err |
| r.Post("/", api.postWorkspaceAgentPortShare) | ||
| r.Delete("/", api.deleteWorkspaceAgentPortShare) | ||
| }) | ||
| r.Get("/timings", api.workspaceTimings) |
There was a problem hiding this comment.
@BrunoQuaresma In theory this is a breaking change... is there any frontend component using it?
@mtojek there is not |
then I think we can remove it |
We have to keep in mind that users can also use the API, so let's check if it made it into a release yet - and if so we have to keep it. |
dannykopping
left a comment
There was a problem hiding this comment.
Great work @BrunoQuaresma!
I think we can land this
| ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong) | ||
| t.Cleanup(cancel) |
There was a problem hiding this comment.
You can use testutil.Context to handle this in future, btw.
|
|
||
| provisionerTimings, err := api.Database.GetProvisionerJobTimingsByJobID(ctx, build.JobID) | ||
| if err != nil && !errors.Is(err, sql.ErrNoRows) { | ||
| timings, err := api.buildTimings(ctx, build) |
Add the agent script timings into the
/workspacebuilds/:workspacebuild/timingsresponse.Close #14876