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

Skip to content

Streamline coder autostart UX #1647

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
7 tasks done
Tracked by #1317
ammario opened this issue May 21, 2022 · 8 comments Β· Fixed by #2251
Closed
7 tasks done
Tracked by #1317

Streamline coder autostart UX #1647

ammario opened this issue May 21, 2022 · 8 comments Β· Fixed by #2251
Assignees
Labels
api Area: HTTP API
Milestone

Comments

@ammario
Copy link
Member

ammario commented May 21, 2022

cc @johnstcn (thank you! πŸ™‡πŸ½β€β™‚οΈ)


subcommand naming

coder autostart enable implies it just turns on autostart, not that it would update it too. For example, you wouldn't enable autostart multiple times. Perhaps coder autostart set makes more sense?

restructured set syntax

Screen Shot 2022-05-21 at 1 37 34 PM

I believe that we should use defaults only when they satisfy a majority of the use cases.

In the case of autostart, maybe 1 in 20 will use UTC, and maybe 1 in 3 want their workspace to start at 9am. I believe we should remove these defaults and force users to set their workspace schedule as follows:

coder autostart set <workspace> Mon-Fri 9:00AM America/Chicago 
  • If they omit timezone, we should infer it from the system
  • If they omits days of week, we should set it to Mon-Sun
  • Time of day is always required as I can't think of a reasonable default. Standard start times range from 7AM to 10AM

display schedule more clearly

Screen Shot 2022-05-21 at 1 46 53 PM

In the current schedule print, the displayed time zone is extracted from the local system when the configured time zone may be different. There's also no acknowledgement of which days autostart is enabled for.

What we display here should closely map to how autostart is configured. I suggest this format:

$ coder autostart set ab Mon-Fri 9:00AM America/Chicago 
ab will automatically start on Mon, Tue, Wed, Thu, and Fri at 9:00AM America/Chicago

Acceptance Criteria

  • autostart enable|disable -> autostart set|unset
  • --autostart-hour --autostart-minute --autostart-dow -> HH:MM{AM|PM} [DOW] [TIMEZONE]
    • DOW defaults MON-SUN SUN-SAT Edit: our existing schedules assume Sunday is the first day of the week.
    • Require time-of-day
  • CLI can infer timezone from system
  • Updated autostart show output showing DOW and in configured autostart timezone
@ammario
Copy link
Member Author

ammario commented May 21, 2022

Oops, I think this may be redundant with #1641

@johnstcn
Copy link
Member

johnstcn commented May 23, 2022

Oops, I think this may be redundant with #1641

This ticket is written way better though!

@johnstcn
Copy link
Member

Blocking this ticket on the autostart UI work. As @vapurrmaid mentions, it will likely be easier to refactor after those pieces are in place, in 1 PR like we did for ttl together

@ammario
Copy link
Member Author

ammario commented Jun 7, 2022

Something else to consider is a time-based instead of duration-based approach to auto-off, following the logic in #2141.

@ammario ammario changed the title Smoothen coder autostart UX Streamline coder autostart UX Jun 8, 2022
@Emyrk
Copy link
Member

Emyrk commented Jun 9, 2022

We need to document that we only support IANA Time Locations, and not time zones for the TZ input.

If you look at this list, https://en.wikipedia.org/wiki/List_of_tz_database_time_zones, the value must be in the TZ database name. The schedule library uses time.LoadLocation.

This is a bit unfortunate as timezones like CST and CDT are not supported (although daylight savings is a headache on it's own). From a brief look a the time api, we cannot convert CDT -> America/Chicago either. (Which makes sense because CDT is a large zone, America.Chicago is a singular location).

I think the 2 timezones people will use is UTC and Local. Anything else seems pretty niche.


Currently we don't support Local.

schedules scoped to time.Local are not supported

I wrote a brief PR (https://github.com/coder/coder/pull/2207/files) on how we can use time.Local to infer local timezone using w/e golang does by default. Then we just convert the Local -> UTC time and submit that to the API.

coder/cli/autostart.go

Lines 101 to 109 in da00128

now := time.Now()
// Create the local date for the hour + minute.
local := time.Date(now.Year(), now.Month(), now.Day(), now.Hour(), now.Minute(), 0, 0, time.Local)
// Convert to UTC time
inUTC := local.In(time.UTC)
// Convert the user's input to UTC values.
autostartMinute = strconv.Itoa(inUTC.Minute())
autostartHour = strconv.Itoa(inUTC.Hour())
autostartTimezone = "UTC"

@johnstcn
Copy link
Member

johnstcn commented Jun 9, 2022

We need to document that we only support IANA Time Locations, and not time zones for the TZ input.

100%

This is a bit unfortunate as timezones like CST and CDT are not supported (although daylight savings is a headache on it's own).

This is probably for the best. Having daylight-savings-time-specific timezones in a schedule is probably going to lead to confusion.

I wrote a brief PR (https://github.com/coder/coder/pull/2207/files) on how we can use time.Local to infer local timezone using w/e golang does by default. Then we just convert the Local -> UTC time and submit that to the API.

If whoever uses this lives in a location where daylight savings time is active, storing their autostart time in UTC will cause bugs.

@Emyrk
Copy link
Member

Emyrk commented Jun 9, 2022

If whoever uses this lives in a location where daylight savings time is active, storing their autostart time in UTC will cause bugs.

I didn't think about this. I wonder if we have this issue in v1. If we handle TZ parsing manually, we could maybe support zone syntax?

This part of the code makes it look like we can set the location manually?

schedule, ok := specSched.(*cron.SpecSchedule)
if !ok {
return nil, xerrors.Errorf("expected *cron.SpecSchedule but got %T", specSched)
}
if schedule.Location == time.Local {
return nil, xerrors.Errorf("schedules scoped to time.Local are not supported")
}

I wonder if this works? Then we can support more common zones?

tz, _ := time.Parse("MST", "CDT")
schedule.Location = tz.Location()

Or alternatively, just tell them to use IANA locations. Maybe add this code to catch the common mistake of using a zone name. It is confusing the output text uses a zone

The steven workspace will automatically start at 2022-06-10 10:39:00 -0500 CDT.

if strings.Contains(err.Error(), "provided bad location") {
  _, err := time.Parse("MST", autostartTimezone)
  if err == nil {
    // We should find a nice easy list to use.
    return xerrors.Errorf("It appears you have entered a timezone, try using a location from the IANA location list https://gist.github.com/aviflax/a4093965be1cd008f172")
  }
}

@ketang
Copy link
Contributor

ketang commented Jun 9, 2022

I just want to be completely clear here: not supporting time zones like CDT or EST is a feature. We never want to support those because they they don't adapt to human needs and expectations.

johnstcn added a commit that referenced this issue Jun 13, 2022
This commit adds the following changes:

- autostart enable|disable => autostart set|unset
- autostart enable now accepts a more natual schedule format: <time> <days-of-week> <location>
- autostart show now shows configured timezone
- πŸŽ‰ automatic timezone detection across mac, windows, linux πŸŽ‰

Fixes #1647
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.

6 participants