diff --git a/command/alloc_status.go b/command/alloc_status.go index 2f206f40b..2c16bcd6f 100644 --- a/command/alloc_status.go +++ b/command/alloc_status.go @@ -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()) + formattedModifyTime := formatTimePretty(time.Unix(0, alloc.ModifyTime), time.Now()) + basic := []string{ fmt.Sprintf("ID|%s", limit(alloc.ID, uuidLength)), fmt.Sprintf("Eval ID|%s", limit(alloc.EvalID, uuidLength)), @@ -225,7 +228,8 @@ func formatAllocBasicInfo(alloc *api.Allocation, client *api.Client, uuidLength fmt.Sprintf("Client Description|%s", alloc.ClientDescription), fmt.Sprintf("Desired Status|%s", alloc.DesiredStatus), fmt.Sprintf("Desired Description|%s", alloc.DesiredDescription), - fmt.Sprintf("Created At|%s", formatUnixNanoTime(alloc.CreateTime)), + fmt.Sprintf("Created|%s", formattedCreateTime), + fmt.Sprintf("Modified|%s", formattedModifyTime), } if alloc.DeploymentID != "" { diff --git a/command/helpers.go b/command/helpers.go index 13f74ba9d..dd58875e9 100644 --- a/command/helpers.go +++ b/command/helpers.go @@ -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 { + return formatTimeDifference(first.Round(time.Second), second.Round(time.Second), time.Second) + " ago" +} + // getLocalNodeID returns the node ID of the local Nomad Client and an error if // it couldn't be determined or the Agent is not running in Client mode. func getLocalNodeID(client *api.Client) (string, error) { diff --git a/command/job_status.go b/command/job_status.go index 0adc69ef3..fabe5913b 100644 --- a/command/job_status.go +++ b/command/job_status.go @@ -406,9 +406,9 @@ 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" for i, alloc := range stubs { - allocs[i+1] = fmt.Sprintf("%s|%s|%s|%s|%d|%s|%s|%s", + allocs[i+1] = fmt.Sprintf("%s|%s|%s|%s|%d|%s|%s|%s|%s", limit(alloc.ID, uuidLength), limit(alloc.EvalID, uuidLength), limit(alloc.NodeID, uuidLength), @@ -416,19 +416,23 @@ func formatAllocListStubs(stubs []*api.AllocationListStub, verbose bool, uuidLen alloc.JobVersion, alloc.DesiredStatus, alloc.ClientStatus, - formatUnixNanoTime(alloc.CreateTime)) + formatUnixNanoTime(alloc.CreateTime), + formatUnixNanoTime(alloc.ModifyTime)) } } else { - allocs[0] = "ID|Node ID|Task Group|Version|Desired|Status|Created At" + allocs[0] = "ID|Node ID|Task Group|Version|Desired|Status|Created|Modified" for i, alloc := range stubs { - allocs[i+1] = fmt.Sprintf("%s|%s|%s|%d|%s|%s|%s", + createTimePretty := formatTimePretty(time.Unix(0, alloc.CreateTime), time.Now()) + modTimePretty := formatTimePretty(time.Unix(0, alloc.ModifyTime), time.Now()) + allocs[i+1] = fmt.Sprintf("%s|%s|%s|%d|%s|%s|%s|%s", limit(alloc.ID, uuidLength), limit(alloc.NodeID, uuidLength), alloc.TaskGroup, alloc.JobVersion, alloc.DesiredStatus, alloc.ClientStatus, - formatUnixNanoTime(alloc.CreateTime)) + createTimePretty, + modTimePretty) } }