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

Skip to content

API/SDK auto-stop extension #1462

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
Tracked by #1317
greyscaled opened this issue May 14, 2022 · 7 comments Β· Fixed by #1778
Closed
Tracked by #1317

API/SDK auto-stop extension #1462

greyscaled opened this issue May 14, 2022 · 7 comments Β· Fixed by #1778
Assignees
Labels
api Area: HTTP API
Milestone

Comments

@greyscaled
Copy link
Contributor

greyscaled commented May 14, 2022

User Story πŸ‘₯

As a user or agent, I'd like to use the API to extend a workspace lease.

Details

We may expose an extension path that looks something like:

/api/v2/workspaces/{workspace}/ttl/extend

with a body like

{
  time: *time.Duration
}

If time is not supplied, we default to 90 mins. We should set an upper bound on time. TBD what that upper bound is, but at least two approaches are:

  1. A hard-set upper bound (example 24 hours)
  2. The difference between NOW and the next scheduled start time

Acceptance Criteria

  • An API/SDK call that extends a lease
@greyscaled
Copy link
Contributor Author

Please add your planning poker estimate with ZenHub @johnstcn

@greyscaled
Copy link
Contributor Author

Left desc blank on purpose - want to double-check we still want pre-emptive extension for CE. Even if we don't, we still need reactive extension. The difference between the two can be further decomposed.

Currently at the SDK level we just have the ability to PUT the schedules:

coder/coderd/coderd.go

Lines 313 to 315 in 7bb7c6c

r.Route("/autostop", func(r chi.Router) {
r.Put("/", api.putWorkspaceAutostop)
})

@ammario
Copy link
Member

ammario commented May 21, 2022

I propose that instead of extend(ttl) it's a set(expire_time) so the API is idempotent (retry resistant). We can still keep the "extend" verbiage in user-facing features.

@greyscaled
Copy link
Contributor Author

greyscaled commented May 23, 2022

I propose that instead of extend(ttl) it's a set(expire_time) so the API is idempotent (retry resistant). We can still keep the "extend" verbiage in user-facing features.

Nice, we're all in agreement - that's well thought out. I like how we get the best presentation and resource representation from that mechanism.

@johnstcn and I are going to go with that approach!

@johnstcn
Copy link
Member

My current thought on the public-facing API of this is roughly:

curl 'http://$CODER/api/v2/workspaces/$WORKSPACE_ID/extend' \
  --request PUT \
  --header 'cookie: om nom nom' \
  --verbose \
  --data '{"deadline": "2022-05-24T17:59:59Z01:00"}'

Thoughts?

@ammario
Copy link
Member

ammario commented May 24, 2022

That API looks shiny clean to me.

@johnstcn
Copy link
Member

johnstcn commented May 25, 2022

Currently going with the following implementation (relevant Slack thread):

  • Add field deadline to table workspace_builds.
  • Upon inserting a row into workspace_builds, deadline will be set to now + workspace.ttl if workspace.ttl is set, and the zero time otherwise.
  • Autostop will now check the deadline field of the workspace_build for the purpose of autostop logic.
  • Adding a new route /api/v2/workspaces/:workspace/extend which will set the deadline of the currently active workspace build to the desired value.
    • The new deadline must be after the existing deadline, and not the zero time.
  • Provisionerd will update workspace_build.deadline upon successful workspace build completion (equal to now plus workspace TTL, if it exists)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Area: HTTP API
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants