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

Skip to content

fix: coderd: decouple ttl and deadline #2282

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 11 commits into from
Jun 14, 2022

Conversation

johnstcn
Copy link
Member

@johnstcn johnstcn commented Jun 13, 2022

This PR makes the following changes:

  • Partially reverts the changes of feat: update workspace deadline when workspace ttl updated #2165, making the deadline of a running workspace build independant of TTL, once started.
  • CLI: updating a workspace TTL no longer updates the deadline of the workspace.
  • UI: updating a workspace TTL no longer updates the deadline of the workspace.

Some additional drive-by changes:

  • API: When creating a workspace, default TTL to min(12 hours, template max_ttl) if not instructed otherwise.
  • CLI: list: measure workspace extension correctly (+X in last column) from the time the provisioner job was completed
  • WorkspaceSchedule: show timezone of schedule if it is set, defaulting to dayjs guess otherwise.
    • 👀 This caused a lot of storybook changes -- if preferred I can move this to another change instead or chromatic-ignore that element.
  • WorkspaceScheduleForm: fixed an issue where deleting the "TTL" value in the form would show the text "Your workspace will shut down a few seconds after start".

@johnstcn johnstcn self-assigned this Jun 13, 2022
@johnstcn johnstcn force-pushed the cj/2229/decouple-ws-deadline-from-ttl-again branch from 07e97b2 to 87c7ffa Compare June 13, 2022 21:11
@johnstcn johnstcn force-pushed the cj/2229/decouple-ws-deadline-from-ttl-again branch from 87c7ffa to 987f785 Compare June 14, 2022 08:10
@johnstcn johnstcn marked this pull request as ready for review June 14, 2022 10:03
@johnstcn johnstcn requested a review from a team as a code owner June 14, 2022 10:03
@johnstcn johnstcn requested a review from a team June 14, 2022 10:03
if ws.LatestBuild.Deadline.IsZero() {
return false, 0
}
if ws.TTLMillis == nil {
return false, 0
}
ttl := time.Duration(*ws.TTLMillis) * time.Millisecond
delta := ws.LatestBuild.Deadline.Add(-ttl).Sub(ws.LatestBuild.CreatedAt)
delta := ws.LatestBuild.Deadline.Add(-ttl).Sub(*ws.LatestBuild.Job.CompletedAt)
Copy link
Member Author

Choose a reason for hiding this comment

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

review: this was causing us to measure deadline extensions incorrectly, resulting in things like 8h (+3m) if your workspace took 3 minutes to buidl.

Comment on lines +88 to +90
// NOTE: If a workspace build is created with a given TTL and then the user either
// changes or unsets the TTL, the deadline for the workspace build will not
// have changed. This behavior is as expected per #2229.
Copy link
Member Author

Choose a reason for hiding this comment

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

review: this is now the expected behaviour until we're told otherwise!

Comment on lines 322 to 323
// Default to min(12 hours, template maximum). Just defaulting to template maximum can be surprising.
dbTTL = sql.NullInt64{Valid: true, Int64: min(template.MaxTtl, int64(12*time.Hour))}
Copy link
Member Author

Choose a reason for hiding this comment

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

review: as the default max_ttl for templates is 168 hours, setting the workspace default to something hopefully more reasonable on a day-to-day basis. Folks can still change this if they want!

Copy link
Member

Choose a reason for hiding this comment

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

Suggestion (non-blocking): Should we make this a constant somewhere, or perhaps define in the db? It could be hard to determine where this limit is coming from.

Copy link
Member Author

Choose a reason for hiding this comment

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

Constant sounds good!

Comment on lines +69 to +72
scheduleHeader: (workspace: Workspace): string => {
const tz = workspace.autostart_schedule ? extractTimezone(workspace.autostart_schedule) : dayjs.tz.guess()
return `Schedule (${tz})`
},
Copy link
Member Author

Choose a reason for hiding this comment

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

review: I found that if your workspace's schedule was set to a different timezone than your own, it would still show your own. I found that confusing, and figured others would likewise. Still defaulting to dayjs.tz.guess() as this should prime the user with what they hopefully want should they need to edit.

export const ttlShutdownAt = (now: dayjs.Dayjs, workspace: Workspace, tz: string, formTTL: number): string => {
// a manual shutdown has a deadline of '"0001-01-01T00:00:00Z"'
// SEE: #1834
const deadline = dayjs(workspace.latest_build.deadline).utc()
const hasDeadline = deadline.year() > 1
const ttl = workspace.ttl_ms ? workspace.ttl_ms / (1000 * 60 * 60) : 0
const delta = formTTL - ttl

if (delta === 0 || !isWorkspaceOn(workspace)) {
return Language.ttlHelperText
} else if (formTTL === 0) {
export const ttlShutdownAt = (formTTL: number): string => {
if (formTTL < 1) {
// Passing an empty value for TTL in the form results in a number that is not zero but less than 1.
return Language.ttlCausesNoShutdownHelperText
} else {
const newDeadline = dayjs(hasDeadline ? deadline : now).add(delta, "hours")
if (newDeadline.isSameOrBefore(now)) {
return `⚠️ ${Language.ttlCausesShutdownHelperText} ${Language.ttlCausesShutdownImmediately} ⚠️`
} else if (newDeadline.isSameOrBefore(now.add(30, "minutes"))) {
return `⚠️ ${Language.ttlCausesShutdownHelperText} ${Language.ttlCausesShutdownSoon} ⚠️`
} else {
return `${Language.ttlCausesShutdownHelperText} ${Language.ttlCausesShutdownAt} ${newDeadline
.tz(tz)
.format("MMM D, YYYY h:mm A")}.`
}
return `${Language.ttlCausesShutdownHelperText} ${dayjs.duration(formTTL, "hours").humanize()} ${
Language.ttlCausesShutdownAfterStart
}.`
Copy link
Member Author

Choose a reason for hiding this comment

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

review: As we no longer can depend on the workspace deadline, I'm just simplifying this a whole bunch and showing the humanized duration.

Copy link
Member

@mafredri mafredri left a comment

Choose a reason for hiding this comment

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

Some thoughts/suggestions but backend changes look good in general!

Comment on lines 322 to 323
// Default to min(12 hours, template maximum). Just defaulting to template maximum can be surprising.
dbTTL = sql.NullInt64{Valid: true, Int64: min(template.MaxTtl, int64(12*time.Hour))}
Copy link
Member

Choose a reason for hiding this comment

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

Suggestion (non-blocking): Should we make this a constant somewhere, or perhaps define in the db? It could be hard to determine where this limit is coming from.

@mafredri
Copy link
Member

Not looking to bike-shed this, but writing down my thoughts.

  • CLI: updating a workspace TTL no longer updates the deadline of the workspace.
  • UI: updating a workspace TTL no longer updates the deadline of the workspace.

Intuitively, I don't know if this is what I'd expect, but I think it's close enough. What I might like to see though is a prompt asking me if I want to update the current workspace TTL as well. For example, a yes/no to update to now + TTL, or perhaps a select box with: created + TTL, now + TTL, Cancel. Just a thought.

@johnstcn
Copy link
Member Author

What I might like to see though is a prompt asking me if I want to update the current workspace TTL as well.

I like the idea; there are some other changes in the pipeline (#2224) that should make this less of an issue though!

@Emyrk
Copy link
Member

Emyrk commented Jun 14, 2022

I like the PR deletes more than it adds 👍

Copy link
Member

@Kira-Pilot Kira-Pilot left a comment

Choose a reason for hiding this comment

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

LGTM!

@johnstcn johnstcn merged commit c28b7ec into main Jun 14, 2022
@johnstcn johnstcn deleted the cj/2229/decouple-ws-deadline-from-ttl-again branch June 14, 2022 16:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants