Skip to content

feat: increase autostop deadline if it passes autostart #10035

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

Closed
wants to merge 1 commit into from

Conversation

deansheather
Copy link
Member

@deansheather deansheather commented Oct 4, 2023

If the autostop deadline passes the next autostart deadline, increase the autostop deadline to be next_autostart + ttl instead of now + ttl.

This applies both on workspace build and periodically via the lifecycle executor system. It cannot happen immediately on activity bump as there's no way to execute cron statements in the database.

Also fixes a bug where activity bump would always use the workspace's configured TTL even if the template forbade it.

Closes #2028

If the autostop deadline passes the next autostart deadline, increase
the autostop deadline to be `next_autostart + ttl` instead of `now +
ttl`.

This applies both on workspace build and periodically via the lifecycle
executor system. It cannot happen immediately on activity bump as
there's no way to execute cron statements in the database.
Comment on lines +13 to +20
(
CASE
WHEN templates.allow_user_autostop
THEN workspaces.ttl
ELSE templates.default_ttl
END
) AS raw_ttl_interval,
(raw_ttl_interval / 1000 / 1000 / 1000 || ' seconds')::interval AS ttl_interval
Copy link
Member

Choose a reason for hiding this comment

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

🙏

-- - an autostop if it's past the deadline
-- - a deadline bump if it's currently running and has a deadline
-- The deadline is computed at build time upon success and is bumped
-- based on activity (up the max deadline if set). We don't need to
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
-- based on activity (up the max deadline if set). We don't need to
-- based on activity (up to the max deadline if set). We don't need to

Comment on lines +316 to +317
case !shouldBump(ws, latestBuild, latestJob, templateSchedule, currentTick).IsZero():
return "", database.BuildReasonBump, nil
Copy link
Member

Choose a reason for hiding this comment

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

Currently we only bump a workspace build if there are a non-zero number of connections. Will this end up bumping workspace deadlines regardless of connection count?

Copy link
Member

Choose a reason for hiding this comment

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

Also, add a test to make sure it doesn't double bump

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes this will bump regardless of connection count. We want to bump if the build lasts until the next autostart time.


// shouldBump returns a non-zero time if the workspace deadline should
// should be bumped.
func shouldBump(ws database.Workspace, build database.WorkspaceBuild, job database.ProvisionerJob, templateSchedule schedule.TemplateScheduleOptions, currentTick time.Time) time.Time {
Copy link
Member

Choose a reason for hiding this comment

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

nit: suggest renaming this to nextBumpDeadline or something for clarity

return ttl
}

// MaybeBumpDeadline may bump the deadline of the workspace if the deadline
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// MaybeBumpDeadline may bump the deadline of the workspace if the deadline
// MaybeBumpDeadline returns the next allowed deadline of the workspace if the deadline

// be used as the new deadline.
//
// The MaxDeadline is not taken into account.
func MaybeBumpDeadline(autostartSchedule *cron.Schedule, deadline time.Time, ttl time.Duration) time.Time {
Copy link
Member

Choose a reason for hiding this comment

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

nit: suggest renaming this to CalculateNextBumpDeadline

@johnstcn
Copy link
Member

johnstcn commented Oct 13, 2023

@deansheather I broke out the changes related to ActivityBump and default template TTL into #10253

You should be able to apply this commit to remove the changes from this PR.

I also rebased your existing changes on current main here: https://github.com/coder/coder/commits/cj/rebase/dean/bump-autostop-if-exceeds-autostart

@github-actions github-actions bot added the stale This issue is like stale bread. label Oct 21, 2023
@github-actions github-actions bot closed this Oct 24, 2023
@stirby stirby reopened this Jan 8, 2024
@github-actions github-actions bot removed the stale This issue is like stale bread. label Jan 10, 2024
@github-actions github-actions bot added the stale This issue is like stale bread. label Jan 17, 2024
@github-actions github-actions bot removed the stale This issue is like stale bread. label Jan 19, 2024
@github-actions github-actions bot added the stale This issue is like stale bread. label Jan 27, 2024
@github-actions github-actions bot closed this Jan 30, 2024
@github-actions github-actions bot deleted the dean/bump-autostop-if-exceeds-autostart branch April 5, 2024 00:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale This issue is like stale bread.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Autostop: bump deadline if workspace hits autostart time
3 participants