-
Notifications
You must be signed in to change notification settings - Fork 904
refactor: workspace autostop_schedule -> ttl #1578
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
coderd/database/migrations/999999_rename_this_autostop_ttl.down.sql
Outdated
Show resolved
Hide resolved
coderd/database/migrations/999999_rename_this_autostop_ttl.up.sql
Outdated
Show resolved
Hide resolved
0593de8
to
22cd000
Compare
if ws.TTL == nil || *ws.TTL == 0 { | ||
return time.Time{}, nil | ||
} |
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.
Instead of using a pointer why not just have 0
mean disabled?
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.
I considered that initially, but I think using the zero value could lead to bugs and/or unintended behaviour. Grey also preferred the semantics of nil | time.Duration
from a FE consumption perspective.
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.
You do have a point, though -- 0 is already an invalid TTL.
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.
Comment: I think the FE or other clients having to know 0
means "manual" is unfortunate, but I'm willing to accept it if it's cleaner for our backend/APIs.
As stated earlier, from v2 forwards I believe it's best that we look at the Coder system as a frontend for a backend, not the other way around.
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.
Should we then consider that in the API response? We could return something like {"ttl": 0, "ttl_mode": "manual"}
?
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.
It's certainly golang convention to make use of "zero-values" in this way, but I don't think we should extend that to the HTTP API, CLI, or frontend, which should behave in ways that are independent of golang's idioms.
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.
@spikecurtis are you referring to @deansheather 's comment here: #1578 (comment)
why not just have 0 mean disabled?
Or the fact that we're using a pointer such that the value can be nil
or a number.
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.
Yeah, I feel like among go practitioners, 0 means disabled would be preferred to making it a pointer and nil
means disabled.
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.
Might need to generate the types, since I see codersdk
changed types.
This will have FE breakages.
If you don't mind, I can push those fixes to this PR so that it's all taken care of in one. Are you cool with that?
if ws.TTL == nil || *ws.TTL == 0 { | ||
return time.Time{}, nil | ||
} |
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.
Comment: I think the FE or other clients having to know 0
means "manual" is unfortunate, but I'm willing to accept it if it's cleaner for our backend/APIs.
As stated earlier, from v2 forwards I believe it's best that we look at the Coder system as a frontend for a backend, not the other way around.
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 👍🏻. Attached some (optional) suggestions.
type UpdateWorkspaceAutostopRequest struct { | ||
Schedule string `json:"schedule"` | ||
type UpdateWorkspaceTTLRequest struct { | ||
TTL *time.Duration `json:"ttl"` |
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: Should we implement a custom Duration type like type NullDuration { Duration time.Duration; Valid bool }
(optionally in a types
or null
package) with a custom json.Marshaler
? I'm mostly thinking about (Go) consumers here. It's not possible to e.g. do:
req := UpdateWorkspaceTTLRequest {
TTL: &time.Duration(time.Second),
}
without first assigning to a variable. Similarly the pointer usage could lead to null pointer dereferences (which arguably would be the "correct" behavior, unless it's known that the zero value is OK).
badcfec
to
b3168c1
Compare
Co-authored-by: G r e y <[email protected]>
This PR makes the following changes:
autostop_schedule
column ofworkspaces
with attl
.pq
(still) does not supporttime.Duration
.autostop_schedule
tottl
in database code etc.autostop
tottl
, updates API routes accordingly