-
Notifications
You must be signed in to change notification settings - Fork 881
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
Conversation
07e97b2
to
87c7ffa
Compare
87c7ffa
to
987f785
Compare
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) |
There was a problem hiding this comment.
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.
// 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. |
There was a problem hiding this comment.
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!
coderd/workspaces.go
Outdated
// 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))} |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Constant sounds good!
scheduleHeader: (workspace: Workspace): string => { | ||
const tz = workspace.autostart_schedule ? extractTimezone(workspace.autostart_schedule) : dayjs.tz.guess() | ||
return `Schedule (${tz})` | ||
}, |
There was a problem hiding this comment.
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 | ||
}.` |
There was a problem hiding this comment.
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.
There was a problem hiding this 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!
coderd/workspaces.go
Outdated
// 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))} |
There was a problem hiding this comment.
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.
Not looking to bike-shed this, but writing down my thoughts.
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 |
I like the idea; there are some other changes in the pipeline (#2224) that should make this less of an issue though! |
I like the PR deletes more than it adds 👍 |
…eadline-from-ttl-again
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
This PR makes the following changes:
Some additional drive-by changes: