-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Adds modify time to cli output #3449
Conversation
command/helpers.go
Outdated
@@ -75,6 +75,11 @@ func formatTimeDifference(first, second time.Time, d time.Duration) string { | |||
return second.Truncate(d).Sub(first.Truncate(d)).String() | |||
} | |||
|
|||
// formatTimePretty rounds off time difference to the nearest second for nicer display | |||
func formatTimePretty(first, second time.Time) string { |
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.
Can we use something like: https://godoc.org/github.com/dustin/go-humanize#Time
The output of this still could become huge if the allocation is many days old.
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 may want to specialize the 0 case since older allocations won't have the modify time and when it gets displayed it would show something like 40 years ago!
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.
LOL, good way to remind people that for engineers, time doesn't exist prior to Jan 1 1970. Will fix
command/alloc_status.go
Outdated
@@ -214,6 +214,9 @@ func (c *AllocStatusCommand) Run(args []string) int { | |||
} | |||
|
|||
func formatAllocBasicInfo(alloc *api.Allocation, client *api.Client, uuidLength int, verbose bool) (string, error) { | |||
formattedCreateTime := formatTimePretty(time.Unix(0, alloc.CreateTime), time.Now()) |
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.
If verbose can we use, formatUnixNanoTime
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.
Same with below
command/job_status.go
Outdated
@@ -406,29 +406,33 @@ func formatAllocListStubs(stubs []*api.AllocationListStub, verbose bool, uuidLen | |||
|
|||
allocs := make([]string, len(stubs)+1) | |||
if verbose { | |||
allocs[0] = "ID|Eval ID|Node ID|Task Group|Version|Desired|Status|Created At" | |||
allocs[0] = "ID|Eval ID|Node ID|Task Group|Version|Desired|Status|Created At|Modified At" |
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.
We should standardize on Created
vs Created At
and same with modify.
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 left it this way because it is grammatically correct to say "Created at yyyy:mm:dd" and "Created 2 minutes ago". The other phrasing Created At x seconds ago
sounds wrong. I'd be fine with changing both to Created
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 vote drop the At
command/helpers.go
Outdated
@@ -75,6 +75,11 @@ func formatTimeDifference(first, second time.Time, d time.Duration) string { | |||
return second.Truncate(d).Sub(first.Truncate(d)).String() | |||
} | |||
|
|||
// formatTimePretty rounds off time difference to the nearest second for nicer display | |||
func formatTimePretty(first, second time.Time) string { |
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 may want to specialize the 0 case since older allocations won't have the modify time and when it gets displayed it would show something like 40 years ago!
7d32802
to
3f0d46c
Compare
…ring() with approximated values for days and beyond. Used in cli output for allocation create/modify times
d := second.Sub(first) | ||
u := uint64(d.Seconds()) | ||
|
||
var buf [32]byte |
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 used a buffer for this similar to Duration.String() to prevent unnecessary allocations as we build up the output string.
command/job_status.go
Outdated
@@ -422,8 +422,8 @@ func formatAllocListStubs(stubs []*api.AllocationListStub, verbose bool, uuidLen | |||
} else { | |||
allocs[0] = "ID|Node ID|Task Group|Version|Desired|Status|Created|Modified" | |||
for i, alloc := range stubs { | |||
createTimePretty := formatTimePretty(time.Unix(0, alloc.CreateTime), time.Now()) | |||
modTimePretty := formatTimePretty(time.Unix(0, alloc.ModifyTime), time.Now()) | |||
createTimePretty := prettyTimeDiff(time.Unix(0, alloc.CreateTime), time.Now()) |
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.
Verbose switch
I'm going to lock this pull request because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active contributions. |
Needs a rebase after #3446 is merged