Skip to content

feat: allow bumping workspace deadline #1828

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 14 commits into from
May 27, 2022
Merged

Conversation

johnstcn
Copy link
Member

@johnstcn johnstcn commented May 27, 2022

  • Adds a bump command to extend workspace build deadline
  • Reduces WARN-level logging spam from autobuild executor
  • Modifies cli/ssh notifications to read from workspace build deadline and to notify relative time instead (sidestepping the problem of figuring out a user's timezone across multiple OSes)
  • Shows workspace extension time in coder list output e.g.
    WORKSPACE        TEMPLATE  STATUS   LAST BUILT  OUTDATED  AUTOSTART        TTL        
    developer/test1  docker    Running  4m          false     0 9 * * MON-FRI  15m (+5m)  
    

@johnstcn johnstcn requested review from greyscaled and a team May 27, 2022 10:46
@johnstcn johnstcn self-assigned this May 27, 2022
@johnstcn johnstcn closed this May 27, 2022
@johnstcn johnstcn force-pushed the cj/cli-autostop-deadline-bump branch from 4b868d2 to 7a5c873 Compare May 27, 2022 14:46
@johnstcn johnstcn deleted the cj/cli-autostop-deadline-bump branch May 27, 2022 14:48
@johnstcn johnstcn restored the cj/cli-autostop-deadline-bump branch May 27, 2022 14:48
@johnstcn johnstcn reopened this May 27, 2022
@johnstcn johnstcn force-pushed the cj/cli-autostop-deadline-bump branch from 34ed95f to 4b868d2 Compare May 27, 2022 15:17
Comment on lines -89 to -110
if duration > time.Hour {
duration = duration.Truncate(time.Hour)
}
if duration > time.Minute {
duration = duration.Truncate(time.Minute)
}
days := 0
for duration.Hours() > 24 {
days++
duration -= 24 * time.Hour
}
durationDisplay := duration.String()
if days > 0 {
durationDisplay = fmt.Sprintf("%dd%s", days, durationDisplay)
}
if strings.HasSuffix(durationDisplay, "m0s") {
durationDisplay = durationDisplay[:len(durationDisplay)-2]
}
if strings.HasSuffix(durationDisplay, "h0m") {
durationDisplay = durationDisplay[:len(durationDisplay)-2]
}

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: moved to its own func

`Your Coder workspace %s is scheduled to stop at %s.`,
ws.Name,
deadline.Format(time.Kitchen),
)
`Your Coder workspace %s is scheduled to stop in %.0f mins`, ws.Name, ttl.Minutes())
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: using a relative time here makes more sense, plus it also means we don't need to worry about timezones!

Comment on lines +110 to +112
// For stopping, do not truncate. This is inconsistent with autostart, but
// it ensures we will not stop too early.
nextTransition = priorHistory.Deadline
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 decided to stop truncating this as the consistency didn't seem worth losing the fidelity in other places. In the worst case, we'll stop a little bit later (but not too early).

Comment on lines 612 to 613
// Disallow updates within than one minute
if withinDuration(newDeadline, build.Deadline, time.Minute) {
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: it's an edge case, but it doesn't make sense to allow this.

Comment on lines +845 to +847
if dt < -d || dt > d {
return false
}
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 just lifted this from require.WithinDuration.

Long: bumpDescriptionLong,
Example: "coder bump my-workspace 90m",
RunE: func(cmd *cobra.Command, args []string) error {
bumpDuration := defaultBumpDuration
Copy link
Member

Choose a reason for hiding this comment

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

If we have a default, should it just be a flag? --duration=90m or something?
Cobra supports duration strings

Copy link
Member Author

@johnstcn johnstcn May 27, 2022

Choose a reason for hiding this comment

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

I don't like the way that looks, without the flag is less typing!

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.

This looks good to me, loved the nice and simple tests. I mostly looked at the code and logic, not so much UX/design.

return d, nil
}

func isDigit(s string) bool {
Copy link
Member

Choose a reason for hiding this comment

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

This would also return true for the empty string, "", although that shouldn't matter in the current implementation (parse error).

@@ -597,7 +597,7 @@ func (api *API) putExtendWorkspace(rw http.ResponseWriter, r *http.Request) {
return xerrors.Errorf("workspace must be started, current status: %s", build.Transition)
}

newDeadline := req.Deadline.Truncate(time.Minute).UTC()
newDeadline := req.Deadline.UTC()
Copy link
Member

Choose a reason for hiding this comment

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

Very nice getting rid of the truncates! 💪🏻

johnstcn and others added 2 commits May 27, 2022 17:48
Co-authored-by: Steven Masley <Emyrk@users.noreply.github.com>
Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>
@kylecarbs
Copy link
Member

nit: Update title to be feat instead!

@johnstcn johnstcn changed the title feature: allow bumping workspace deadline feat: allow bumping workspace deadline May 27, 2022
Copy link
Contributor

@greyscaled greyscaled left a comment

Choose a reason for hiding this comment

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

Awesome stuff @johnstcn

@johnstcn johnstcn merged commit ff542af into main May 27, 2022
@johnstcn johnstcn deleted the cj/cli-autostop-deadline-bump branch May 27, 2022 19:04
kylecarbs pushed a commit that referenced this pull request Jun 10, 2022
 * Adds a `bump` command to extend workspace build deadline
 * Reduces WARN-level logging spam from autobuild executor
 * Modifies `cli/ssh` notifications to read from workspace build deadline and to notify relative time instead (sidestepping the problem of figuring out a user's timezone across multiple OSes)
 * Shows workspace extension time in `coder list` output e.g.
    ```
    WORKSPACE        TEMPLATE  STATUS   LAST BUILT  OUTDATED  AUTOSTART        TTL        
    developer/test1  docker    Running  4m          false     0 9 * * MON-FRI  15m (+5m)  
    ```
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