Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat(cli): extend duration to longer units#15040

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
defelmnq merged 10 commits intomainfromfeat/improve-duration-flags
Oct 16, 2024

Conversation

defelmnq
Copy link
Contributor

@defelmnqdefelmnq commentedOct 10, 2024
edited
Loading

This PR is a proposal to improve the situation described in#14750

For some precise commands - we would like to be able to use durations bigger than hours, minutes..

This PR extends the Duration proposed by Go with :

  • d - a day or 24hours.
  • y - a year or 365 days.

I also removed the default value for lifetime and instead fetch the maxLifetime value from codersdk - so by default if no value set we use the value defined in the config.

matifali reacted with hooray emoji
@defelmnqdefelmnq self-assigned thisOct 10, 2024
@defelmnqdefelmnq requested a review frommtojekOctober 10, 2024 23:47
{"10s", 10 * time.Second, true},
{"1m", 1 * time.Minute, true},
{"20h", 20 * time.Hour, true},
{"10y10d10s", 0, false},
Copy link
Member

Choose a reason for hiding this comment

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

I think users will expect durations like 1y1d to work here. It shouldn't be a huge lift to enable this!

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Hey@johnstcn I tried to play with time.ParseDuration golang function to mimic the behavior as much as possible - and changed to indeed modify what you've raised.

johnstcn reacted with heart emoji
@matifali
Copy link
Member

matifali commentedOct 14, 2024
edited
Loading

This is excellent@defelmnq. I suggest we stay uniform and check and update all durations of input throughput the product to support the string format across CLI/API/frontend.

It doesn't have to be in this PR and can be tracked as a separate issue.

cli/util.go Outdated
Comment on lines 188 to 189
// - d (days)
// - y (years)
Copy link
Member

Choose a reason for hiding this comment

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

It may make sense to explicitly note that this will not take into account things like DST or leap years or all that other assorted wibbly wobbley timey wimey stuff.

Suggested change
// - d (days)
// - y (years)
// - d (days, interpreted as 24 hours)
// - y (years, interpreted as 8_760 hours)

Copy link
Member

Choose a reason for hiding this comment

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

My first though was about leap years too :)

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Yep - indeed we can document it. About the behavior are we good to keep it this way ? I felt like it can quickly become complicated with time saving, leap years etc.. otherwise - maybe we can do it in the follow-up PR in serpent if we want to use it everywhere.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, definitely not a must-have

Copy link
Member

@johnstcnjohnstcnOct 14, 2024
edited
Loading

Choose a reason for hiding this comment

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

I'm happy with a naive definition of days and years here. Adding DST / leap year awareness adds a lot of complications, as you need both a timezone and a relative time. We can add a follow-up issue if we think it's necessary though.

defelmnq reacted with heart emoji
Comment on lines +51 to +59
{"1d", 24 * time.Hour, true},
{"1y", 365 * 24 * time.Hour, true},
{"10s", 10 * time.Second, true},
{"1m", 1 * time.Minute, true},
{"20h", 20 * time.Hour, true},
{"10y10d10s", 10*365*24*time.Hour + 10*24*time.Hour + 10*time.Second, true},
{"10ms", 10 * time.Millisecond, true},
{"5y10d10s5y2ms8ms", 10*365*24*time.Hour + 10*24*time.Hour + 10*time.Second + 10*time.Millisecond, true},
{"10yz10d10s", 0, false},
Copy link
Member

Choose a reason for hiding this comment

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

question: What happens if we try to parse a duration greater than2540400h10m10.000000000s (e.g.1000y)?
(see:https://github.com/golang/go/blob/master/src/time/time.go#L954C21-L954C45)

mtojek reacted with thumbs up emoji
Comment on lines +78 to +81
parsedLifetime, err = extendedParseDuration(tokenLifetime)
if err != nil {
return xerrors.Errorf("parse lifetime: %w", err)
}
Copy link
Member

Choose a reason for hiding this comment

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

suggestion: given that we have the token config available, we can check if the requested lifetime is greater thanMaxTokenLifetime client-side. This may not be completely necessary though, as the API will disallow creating tokens with lifetime greater thanMaximumTokenDuration. Dealer's choice!

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Yeah you're completely right - makes sense I just changed it a bit to handle the config fetched ! 👌

@@ -46,7 +46,7 @@ func (r *RootCmd) tokens() *serpent.Command {

func (r *RootCmd) createToken() *serpent.Command {
var (
tokenLifetimetime.Duration
tokenLifetimestring
Copy link
Member

Choose a reason for hiding this comment

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

@defelmnq@johnstcn WDYT about defining a new type incoder/serpent,time.LongDuration?

Copy link
Member

Choose a reason for hiding this comment

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

Could be done as a follow-up!

mtojek reacted with thumbs up emoji
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I created afollow-up issue here - would definitely be a cool one to do indeed.

johnstcn reacted with heart emoji
cli/util.go Outdated
Comment on lines 188 to 189
// - d (days)
// - y (years)
Copy link
Member

Choose a reason for hiding this comment

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

My first though was about leap years too :)

Copy link
Member

@EmyrkEmyrk left a comment
edited
Loading

Choose a reason for hiding this comment

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

I see this being valuable outside this 1 case.

serpent.Duration is used in a few places inDeploymentValues. Can we make this a new time, called likeserpent.ExtendedDuration?

Or maybe more controversial, just include this intoserpent.Duration itself?

Screenshot from 2024-10-14 10-26-09

@defelmnq
Copy link
ContributorAuthor

Hey@mtojek@johnstcn thanks a lot for the input here - really appreciate.

Since the last review, here are globally the points I tried to change and improve :

  • Handling & tests for negative values and overflow.
  • Stick to go time package to add 'segments' (2h2h10m is valid and equals 4h10m)
  • Verifying client-side if the defined token lifetime is valid compared to the one fetched in the config.

What I would love to do as a follow-up :

  • Handle cases like1.2h
  • Potentially move the library to Serpent cc@Emyrk &this issue for broader adoption
Emyrk and mtojek reacted with thumbs up emoji

Copy link
Member

@mtojekmtojek left a comment

Choose a reason for hiding this comment

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

Strong tests 👍

Copy link
Member

@johnstcnjohnstcn left a comment

Choose a reason for hiding this comment

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

Nice work! 👍

@defelmnqdefelmnq requested a review fromEmyrkOctober 16, 2024 13:09
@defelmnqdefelmnq merged commitccbb687 intomainOct 16, 2024
27 checks passed
@defelmnqdefelmnq deleted the feat/improve-duration-flags branchOctober 16, 2024 15:02
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsOct 16, 2024
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@johnstcnjohnstcnjohnstcn approved these changes

@mtojekmtojekmtojek approved these changes

@dannykoppingdannykoppingAwaiting requested review from dannykopping

@EmyrkEmyrkAwaiting requested review from Emyrk

Assignees

@defelmnqdefelmnq

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

5 participants
@defelmnq@matifali@johnstcn@Emyrk@mtojek

[8]ページ先頭

©2009-2025 Movatter.jp