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

Skip to content

feat(coderd): return agent script timings#14923

Merged
BrunoQuaresma merged 18 commits into
mainfrom
bq/feat-agent-timings
Oct 14, 2024
Merged

feat(coderd): return agent script timings#14923
BrunoQuaresma merged 18 commits into
mainfrom
bq/feat-agent-timings

Conversation

@BrunoQuaresma

@BrunoQuaresma BrunoQuaresma commented Oct 1, 2024

Copy link
Copy Markdown
Contributor

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

Close #14876

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

@dannykopping dannykopping left a comment

Copy link
Copy Markdown
Contributor

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 thread coderd/database/dbmem/dbmem.go Outdated
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
Copy Markdown
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.

Comment thread coderd/workspaces.go Outdated
Comment thread coderd/workspaces.go Outdated
Comment thread coderd/workspaces_test.go Outdated
Comment thread coderd/workspaces_test.go Outdated
Comment thread coderd/database/queries/workspaceagents.sql Outdated
@BrunoQuaresma

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

@dannykopping dannykopping left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Great work @BrunoQuaresma!

Comment thread coderd/coderd.go
r.Post("/", api.postWorkspaceAgentPortShare)
r.Delete("/", api.deleteWorkspaceAgentPortShare)
})
r.Get("/timings", api.workspaceTimings)

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

Comment thread coderd/database/dbmem/dbmem.go Outdated

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

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

Choose a reason for hiding this comment

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

👍

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

Comment thread coderd/workspacebuilds_test.go Outdated

// When: fetching an inexistent build
buildID := uuid.New()
_, err := client.WorkspaceBuildTimings(context.Background(), buildID)

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

Choose a reason for hiding this comment

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

👍

Comment thread coderd/workspacebuilds_test.go

@mtojek mtojek left a comment

Copy link
Copy Markdown
Member

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 👍

Comment thread coderd/workspacebuilds_test.go Outdated

// When: fetching an inexistent build
buildID := uuid.New()
_, err := client.WorkspaceBuildTimings(context.Background(), buildID)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍

Comment thread coderd/database/dbmem/dbmem.go Outdated

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍

Comment thread coderd/coderd.go
r.Post("/", api.postWorkspaceAgentPortShare)
r.Delete("/", api.deleteWorkspaceAgentPortShare)
})
r.Get("/timings", api.workspaceTimings)

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

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

@mtojek there is not

@mtojek

mtojek commented Oct 4, 2024

Copy link
Copy Markdown
Member

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

then I think we can remove it

@dannykopping

Copy link
Copy Markdown
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.

@dannykopping dannykopping left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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.

Comment thread coderd/workspaces.go

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

Copy link
Copy Markdown
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
@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