diff --git a/.changelog/13581.txt b/.changelog/13581.txt new file mode 100644 index 000000000..2d9fef106 --- /dev/null +++ b/.changelog/13581.txt @@ -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 +``` diff --git a/command/eval.go b/command/eval.go index 82311fb84..0f7a22017 100644 --- a/command/eval.go +++ b/command/eval.go @@ -1,10 +1,8 @@ package command import ( - "fmt" "strings" - "github.com/hashicorp/nomad/api" "github.com/mitchellh/cli" ) @@ -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)) -} diff --git a/command/eval_delete.go b/command/eval_delete.go index 381c161ae..7609c2b10 100644 --- a/command/eval_delete.go +++ b/command/eval_delete.go @@ -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("") } } diff --git a/command/eval_list.go b/command/eval_list.go index f74d172e9..2baab393b 100644 --- a/command/eval_list.go +++ b/command/eval_list.go @@ -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(` @@ -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) +} diff --git a/command/eval_status.go b/command/eval_status.go index 967ff6efd..722da88ed 100644 --- a/command/eval_status.go +++ b/command/eval_status.go @@ -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 } @@ -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 != "" { @@ -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": diff --git a/website/content/docs/commands/eval/delete.mdx b/website/content/docs/commands/eval/delete.mdx index 42cf5125e..ae217f5d9 100644 --- a/website/content/docs/commands/eval/delete.mdx +++ b/website/content/docs/commands/eval/delete.mdx @@ -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 pending false +1c905ca0 50 job-register example default pending false +b9e77692 50 job-register example default pending false Are you sure you want to delete 3 evals? [y/N] y diff --git a/website/content/docs/commands/eval/list.mdx b/website/content/docs/commands/eval/list.mdx index e3dc5ac86..1081d2f52 100644 --- a/website/content/docs/commands/eval/list.mdx +++ b/website/content/docs/commands/eval/list.mdx @@ -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 complete false +1a1eafe6 50 alloc-stop example default complete false +3411e37b 50 job-register example default complete false Results have been paginated. To get the next page run: diff --git a/website/content/docs/commands/eval/status.mdx b/website/content/docs/commands/eval/status.mdx index f89bb603b..663c3a562 100644 --- a/website/content/docs/commands/eval/status.mdx +++ b/website/content/docs/commands/eval/status.mdx @@ -63,6 +63,7 @@ Status Description = complete Type = service TriggeredBy = job-register Job ID = example +Namespace = default Priority = 50 Placement Failures = true