mirror of
https://github.com/coder/coder.git
synced 2026-06-02 20:48:20 +00:00
fix: exclude provisioner_state from workspace_build_with_user view (#22159)
The provisioner state for a workspace build was being loaded for every long-lived agent rpc connection. Since this state can be anywhere from kilobytes to megabytes this can gradually cause the `coderd` memory footprint to grow over time. It's also a lot of unnecessary allocations for every query that fetches a workspace build since only a few callers ever actually reference the provisioner state. This PR removes it from the returned workspace build and adds a query to fetch the provisioner state explicitly.
This commit is contained in:
@@ -452,7 +452,7 @@ func (b *Builder) buildTx(authFunc func(action policy.Action, object rbac.Object
|
||||
// to read all provisioner daemons. We need to retrieve the eligible
|
||||
// provisioner daemons for this job to show in the UI if there is no
|
||||
// matching provisioner daemon.
|
||||
provisionerDaemons, err := b.store.GetEligibleProvisionerDaemonsByProvisionerJobIDs(dbauthz.AsSystemReadProvisionerDaemons(b.ctx), []uuid.UUID{provisionerJob.ID})
|
||||
provisionerDaemons, err := b.store.GetEligibleProvisionerDaemonsByProvisionerJobIDs(dbauthz.AsWorkspaceBuilder(b.ctx), []uuid.UUID{provisionerJob.ID})
|
||||
if err != nil {
|
||||
// NOTE: we do **not** want to fail a workspace build if we fail to
|
||||
// retrieve provisioner daemons. This is just to show in the UI if there
|
||||
@@ -570,8 +570,8 @@ func (b *Builder) buildTx(authFunc func(action policy.Action, object rbac.Object
|
||||
}
|
||||
}
|
||||
if b.state.orphan && !hasActiveEligibleProvisioner {
|
||||
// nolint: gocritic // At this moment, we are pretending to be provisionerd.
|
||||
if err := store.UpdateProvisionerJobWithCompleteWithStartedAtByID(dbauthz.AsProvisionerd(b.ctx), database.UpdateProvisionerJobWithCompleteWithStartedAtByIDParams{
|
||||
// nolint: gocritic // User won't necessarily have the permission to do this so we act as a system user.
|
||||
if err := store.UpdateProvisionerJobWithCompleteWithStartedAtByID(dbauthz.AsWorkspaceBuilder(b.ctx), database.UpdateProvisionerJobWithCompleteWithStartedAtByIDParams{
|
||||
CompletedAt: sql.NullTime{Valid: true, Time: now},
|
||||
Error: sql.NullString{Valid: false},
|
||||
ErrorCode: sql.NullString{Valid: false},
|
||||
@@ -815,7 +815,12 @@ func (b *Builder) getState() ([]byte, error) {
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("get last build to get state: %w", err)
|
||||
}
|
||||
return bld.ProvisionerState, nil
|
||||
// nolint: gocritic // Workspace builder needs to read provisioner state for the new build.
|
||||
state, err := b.store.GetWorkspaceBuildProvisionerStateByID(dbauthz.AsWorkspaceBuilder(b.ctx), bld.ID)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("get workspace build provisioner state: %w", err)
|
||||
}
|
||||
return state.ProvisionerState, nil
|
||||
}
|
||||
|
||||
func (b *Builder) getParameters() (names, values []string, err error) {
|
||||
|
||||
Reference in New Issue
Block a user