Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Merged
merged 18 commits into from
Oct 14, 2024
Merged

Conversation

BrunoQuaresma
Copy link
Collaborator

@BrunoQuaresma BrunoQuaresma commented Oct 1, 2024

Add the agent script timings into the /workspacebuilds/:workspacebuild/timings response.

Close #14876

Add the agent script timings into the `/workspaces/:workspaceId/timings`
response.
Copy link
Contributor

@dannykopping dannykopping left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good start, but I think this needs some hardening.

Comment on lines 5834 to 5852
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,
})
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: reduce nesting by keeping the happy path unindented.

i.e. continue if the slice does not contain what you're looking for.

@BrunoQuaresma
Copy link
Collaborator Author

@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.

Copy link
Contributor

@dannykopping dannykopping left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work @BrunoQuaresma!

coderd/coderd.go Outdated
@@ -1150,7 +1150,6 @@ func New(options *Options) *API {
r.Post("/", api.postWorkspaceAgentPortShare)
r.Delete("/", api.deleteWorkspaceAgentPortShare)
})
r.Get("/timings", api.workspaceTimings)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should check if this endpoint got included in a release. If it has, we'll have to keep it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BrunoQuaresma In theory this is a breaking change... is there any frontend component using it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please wrap these errors.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Collaborator Author

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"?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using context.Background, use a context which has a timeout.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Member

@mtojek mtojek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


build, err := q.GetWorkspaceBuildByID(ctx, id)
if err != nil {
return nil, err
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

coderd/coderd.go Outdated
@@ -1150,7 +1150,6 @@ func New(options *Options) *API {
r.Post("/", api.postWorkspaceAgentPortShare)
r.Delete("/", api.deleteWorkspaceAgentPortShare)
})
r.Get("/timings", api.workspaceTimings)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BrunoQuaresma In theory this is a breaking change... is there any frontend component using it?

@BrunoQuaresma
Copy link
Collaborator Author

In theory this is a breaking change... is there any frontend component using it?

@mtojek there is not

@mtojek
Copy link
Member

mtojek commented Oct 4, 2024

In theory this is a breaking change... is there any frontend component using it?

then I think we can remove it

@dannykopping
Copy link
Contributor

In theory this is a breaking change... is there any frontend component using it?

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.

Copy link
Contributor

@dannykopping dannykopping left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work @BrunoQuaresma!
I think we can land this

Comment on lines +1279 to +1280
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
t.Cleanup(cancel)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use testutil.Context to handle this in future, btw.

@@ -1763,30 +1763,16 @@ func (api *API) workspaceTimings(rw http.ResponseWriter, r *http.Request) {
return
}

provisionerTimings, err := api.Database.GetProvisionerJobTimingsByJobID(ctx, build.JobID)
if err != nil && !errors.Is(err, sql.ErrNoRows) {
timings, err := api.buildTimings(ctx, build)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@BrunoQuaresma BrunoQuaresma merged commit 9c8ecb8 into main Oct 14, 2024
30 checks passed
@BrunoQuaresma BrunoQuaresma deleted the bq/feat-agent-timings branch October 14, 2024 12:31
@github-actions github-actions bot locked and limited conversation to collaborators Oct 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Expose the agent timings in the /workspace/:workspaceId/timings endpoint
3 participants