Skip to content
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

cli: improve output of eval commands #13581

Merged
merged 4 commits into from
Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changelog/13581.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:improvement
cli: display namespace and node ID in the `eval list` command and when `eval status` matches multiple evals
```

```release-note:improvement
cli: always display job ID and namespace in the `eval status` command
```
22 changes: 0 additions & 22 deletions command/eval.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package command

import (
"fmt"
"strings"

"github.com/hashicorp/nomad/api"
"github.com/mitchellh/cli"
)

Expand Down Expand Up @@ -46,23 +44,3 @@ func (f *EvalCommand) Synopsis() string {
func (f *EvalCommand) Name() string { return "eval" }

func (f *EvalCommand) Run(_ []string) int { return cli.RunResultHelp }

// outputEvalList is a helper which outputs an array of evaluations as a list
// to the UI with key information such as ID and status.
func outputEvalList(ui cli.Ui, evals []*api.Evaluation, length int) {

out := make([]string, len(evals)+1)
out[0] = "ID|Priority|Triggered By|Job ID|Status|Placement Failures"
for i, eval := range evals {
failures, _ := evalFailureStatus(eval)
out[i+1] = fmt.Sprintf("%s|%d|%s|%s|%s|%s",
limit(eval.ID, length),
eval.Priority,
eval.TriggeredBy,
eval.JobID,
eval.Status,
failures,
)
}
ui.Output(formatList(out))
}
2 changes: 1 addition & 1 deletion command/eval_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ func (e *EvalDeleteCommand) batchDelete(evals []*api.Evaluation) (int, bool, err
// avoided when deleting large quantities of evals.
if listEvals {
e.Ui.Output("")
outputEvalList(e.Ui, evals, shortId)
e.Ui.Output(formatEvalList(evals, false))
e.Ui.Output("")
}
}
Expand Down
34 changes: 27 additions & 7 deletions command/eval_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,7 @@ func (c *EvalListCommand) Run(args []string) int {
return 0
}

// Truncate the id unless full length is requested
length := shortId
if verbose {
length = fullId
}

outputEvalList(c.Ui, evals, length)
c.Ui.Output(formatEvalList(evals, verbose))

if qm.NextToken != "" {
c.Ui.Output(fmt.Sprintf(`
Expand Down Expand Up @@ -204,3 +198,29 @@ func argsWithoutPageToken(osArgs []string) string {
}
return strings.Join(args, " ")
}

func formatEvalList(evals []*api.Evaluation, verbose bool) string {
// Truncate IDs unless full length is requested
length := shortId
if verbose {
length = fullId
}

out := make([]string, len(evals)+1)
out[0] = "ID|Priority|Triggered By|Job ID|Namespace|Node ID|Status|Placement Failures"
for i, eval := range evals {
failures, _ := evalFailureStatus(eval)
out[i+1] = fmt.Sprintf("%s|%d|%s|%s|%s|%s|%s|%s",
limit(eval.ID, length),
eval.Priority,
eval.TriggeredBy,
eval.JobID,
eval.Namespace,
limit(eval.NodeID, length),
eval.Status,
failures,
)
}

return formatList(out)
}
19 changes: 3 additions & 16 deletions command/eval_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,20 +155,7 @@ func (c *EvalStatusCommand) Run(args []string) int {
}

if len(evals) > 1 {
// Format the evals
out := make([]string, len(evals)+1)
out[0] = "ID|Priority|Triggered By|Status|Placement Failures"
for i, eval := range evals {
failures, _ := evalFailureStatus(eval)
out[i+1] = fmt.Sprintf("%s|%d|%s|%s|%s",
limit(eval.ID, length),
eval.Priority,
eval.TriggeredBy,
eval.Status,
failures,
)
}
c.Ui.Error(fmt.Sprintf("Prefix matched multiple evaluations\n\n%s", formatList(out)))
c.Ui.Error(fmt.Sprintf("Prefix matched multiple evaluations\n\n%s", formatEvalList(evals, verbose)))
return 1
}

Expand Down Expand Up @@ -223,6 +210,8 @@ func (c *EvalStatusCommand) Run(args []string) int {
fmt.Sprintf("Status Description|%s", statusDesc),
fmt.Sprintf("Type|%s", eval.Type),
fmt.Sprintf("TriggeredBy|%s", eval.TriggeredBy),
fmt.Sprintf("Job ID|%s", eval.JobID),
fmt.Sprintf("Namespace|%s", eval.Namespace),
}

if triggerNoun != "" && triggerSubj != "" {
Expand Down Expand Up @@ -282,8 +271,6 @@ func sortedTaskGroupFromMetrics(groups map[string]*api.AllocationMetric) []strin

func getTriggerDetails(eval *api.Evaluation) (noun, subject string) {
switch eval.TriggeredBy {
case "job-register", "job-deregister", "periodic-job", "rolling-update", "deployment-watcher":
return "Job ID", eval.JobID
case "node-update":
return "Node ID", eval.NodeID
case "max-plan-attempts":
Expand Down
8 changes: 4 additions & 4 deletions website/content/docs/commands/eval/delete.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ Delete all evaluations with status `pending` for the `example` job:
$ nomad eval delete -filter='Stauts == "pending" and JobID == "example"'
Do you want to list evals (3) before deletion? [y/N] y
ID Priority Triggered By Job ID Status Placement Failures
cef92121 50 job-register example pending false
1c905ca0 50 job-register example pending false
b9e77692 50 job-register example pending false
ID Priority Triggered By Job ID Namespace Node ID Status Placement Failures
cef92121 50 job-register example default <none> pending false
1c905ca0 50 job-register example default <none> pending false
b9e77692 50 job-register example default <none> pending false
Are you sure you want to delete 3 evals? [y/N] y
Expand Down
8 changes: 4 additions & 4 deletions website/content/docs/commands/eval/list.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ List all tracked evaluations:

```shell-session
$ nomad eval list -per-page 3 -status complete
ID Priority Triggered By Job ID Status Placement Failures
456e37aa 50 deployment-watcher example complete false
1a1eafe6 50 alloc-stop example complete false
3411e37b 50 job-register example complete false
ID Priority Triggered By Job ID Namespace Node ID Status Placement Failures
456e37aa 50 deployment-watcher example default <none> complete false
1a1eafe6 50 alloc-stop example default <node> complete false
3411e37b 50 job-register example default <node> complete false
Results have been paginated. To get the next page run:
Expand Down
1 change: 1 addition & 0 deletions website/content/docs/commands/eval/status.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Status Description = complete
Type = service
TriggeredBy = job-register
Job ID = example
Namespace = default
Priority = 50
Placement Failures = true
Expand Down