Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: allow users to pause prebuilt workspace reconciliation#18700

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
SasSwart merged 5 commits intomainfromjjs/internal-368
Jul 2, 2025

Conversation

SasSwart
Copy link
Contributor

@SasSwartSasSwart commentedJul 1, 2025
edited
Loading

This PR provides two commands:

  • coder prebuilds pause
  • coder prebuilds resume

These allow the suspension of all prebuilds activity, intended for use if prebuilds are misbehaving.

@SasSwartSasSwart changed the titlefeat: add cli commands to pause and resume prebuilt workspace reconci…feat: provide a mechanism to pause prebuilt workspace reconciliationJul 1, 2025
@SasSwartSasSwart changed the titlefeat: provide a mechanism to pause prebuilt workspace reconciliationfeat: allow users to pause prebuilt workspace reconciliationJul 1, 2025
Copy link
Member

@johnstcnjohnstcn left a comment

Choose a reason for hiding this comment

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

LGTM so far, just missing the final piece of plumbing

@SasSwartSasSwart requested a review fromjohnstcnJuly 2, 2025 08:26
@SasSwartSasSwart marked this pull request as ready for reviewJuly 2, 2025 08:29
@johnstcn
Copy link
Member

johnstcn commentedJul 2, 2025
edited
Loading

Might be good to also avoid the termprebuilds in the CLI command unless there is prior art

EDIT: prior art exists withcodersdk.PrebuildsConfig and in numerous other places in the codebase. I don't have any better naming suggestion, so leave it ascoder prebuilds

MetricEligibleGauge=namespace+"eligible"
MetricPresetHardLimitedGauge=namespace+"preset_hard_limited"
MetricLastUpdatedGauge=namespace+"metrics_last_updated"
MetricReconciliationPausedGauge=namespace+"reconciliation_paused"
Copy link
Contributor

Choose a reason for hiding this comment

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

Paused is difficult to reason about; I'd suggest inverting and make it_running so that a good value is 1 and a bad value is 0.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

paused in this case has a technical meaning relating to a specific setting. If we rename this torunning then I think we need to change the setting to be{"reconciliation_running": true}, which doesn't communicate the intent of the API clearly.

I'd like to keep it how it currently is, but as compensatory measures I will:

  • update the metric documentation to be clear about its meaning
  • add a second metric to represent a general "check engine light" for prebuilds

dannykopping reacted with thumbs up emoji
Copy link
Contributor

@dannykoppingdannykopping left a comment

Choose a reason for hiding this comment

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

This will be pretty handy, LGTM!

return
}

ifbytes.Equal(settingsJSON, []byte(currentSettingsJSON)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: not a problem now but when we add more settings, map ordering may cause this check to fail.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

good catch.

require.Len(t,workspaces,2,"should have created 2 prebuilds")

// Now pause prebuilds reconciliation
err=db.UpsertPrebuildsSettings(ctx,`{"reconciliation_paused": true}`)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd suggest going via the API here to avoid duplicating this business logic.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

good point

Copy link
Contributor

@ssncferreirassncferreira left a comment
edited
Loading

Choose a reason for hiding this comment

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

LGTM 🎉 Thanks for creating this.
There is just a question about rbac: with this change we require the permissionrbac.ResourceDeploymentConfig, so that means that only the owner of the resouce or a user with roleauditorRole can upsert this setting. Should we extend it to Admins?

}

func (q*querier)UpsertPrebuildsSettings(ctx context.Context,valuestring)error {
iferr:=q.authorizeContext(ctx,policy.ActionUpdate,rbac.ResourceDeploymentConfig);err!=nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to clarify here on the rbac side, this means that only a user with this permission can update the setting. Fromhttps://github.com/coder/coder/blob/main/coderd/rbac/roles.go currently, only theauditorRole has this permission. Is that intended?

Copy link
Member

Choose a reason for hiding this comment

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

Auditor only has read though?

ResourceDeploymentConfig.Type: {policy.ActionRead},

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, good catch! 👀 So it means that only the owner of theResourceDeploymentConfig can update the settings, right? Should we maybe extend it to the Admins? 🤔

Copy link
Member

@johnstcnjohnstcnJul 2, 2025
edited
Loading

Choose a reason for hiding this comment

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

I don't think there exists any other suitable role that should have permission to edit site-wide deployment config? Our choices are site-wide template admin or site-wide user admin, neither of which feel right to me. Site-wide auditor should only have read permissions, and all of the org-scoped admins are out of site-wide scope.

This might be something to explore in a separate PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, this could definitely be addressed in a separate PR. You might be right that adding the permission to admin roles isn’t the best approach. My main concern was that currently only users with theOwner role can update this setting. In our dogfood environment, this works fine since many users have theOwner role, but this is not the typical case.

On second thought, limiting this permission to theOwner role does make sense, since it’s an important command and users should be fully aware of the implications when using it.


typePrebuildsSettingsstruct {
ID uuid.UUID`db:"id" json:"id"`
ReconciliationPausedbool`db:"reconciliation_paused" json:"reconciliation_paused"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think it would also be useful to add a timestamp?


ifbytes.Equal(settingsJSON, []byte(currentSettingsJSON)) {
// See: https://www.rfc-editor.org/rfc/rfc7232#section-4.1
httpapi.Write(ctx,rw,http.StatusNotModified,nil)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: according to the RFC the 304 Not Modified is normally a response to a GET request.
Maybe a 204 No Content makes more sense in this case, wdyt?https://datatracker.ietf.org/doc/html/rfc7231#section-6.3.5

returnxerrors.Errorf("unable to pause prebuilds: %w",err)
}

_,_=fmt.Fprintln(inv.Stderr,"Prebuilds are now paused.")
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not?

Suggested change
_,_=fmt.Fprintln(inv.Stderr,"Prebuilds are now paused.")
_,_=fmt.Fprintln(inv.Stdout,"Prebuilds are now paused.")

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

My reasoning was that this command doesn't actually produce any output of its own.
It reports its own status, but that's more logging than output.

assert.Contains(t,buf.String(),"Prebuilds are now paused.")

// Verify the settings were actually updated
//nolint:gocritic // Only owners can change deployment settings
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the//nolint:gocritic? 🤔

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

There's a rule to check that we test with non-owner roles as they're usually more appropriate. In this case, owner is the appropriate role.

err=db.UpsertPrebuildsSettings(ctx,`{"reconciliation_paused": false}`)
require.NoError(t,err)

// Run reconciliation again - it should now recreate the prebuilds
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice test 🤩

@SasSwartSasSwartenabled auto-merge (squash)July 2, 2025 14:55
@SasSwartSasSwart merged commit01163ea intomainJul 2, 2025
34 checks passed
@SasSwartSasSwart deleted the jjs/internal-368 branchJuly 2, 2025 15:05
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsJul 2, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@johnstcnjohnstcnjohnstcn approved these changes

@ssncferreirassncferreirassncferreira left review comments

@dannykoppingdannykoppingdannykopping approved these changes

Assignees

@SasSwartSasSwart

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@SasSwart@johnstcn@dannykopping@ssncferreira

[8]ページ先頭

©2009-2025 Movatter.jp