Skip to content

Commit

Permalink
Clean failed placement output
Browse files Browse the repository at this point in the history
  • Loading branch information
dadgar committed May 31, 2016
1 parent ad00346 commit f5398d2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 36 deletions.
4 changes: 2 additions & 2 deletions command/eval_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (c *EvalStatusCommand) Run(args []string) int {
statusDesc = eval.Status
}

// Format the allocation data
// Format the evaluation data
basic := []string{
fmt.Sprintf("ID|%s", limit(eval.ID, length)),
fmt.Sprintf("Status|%s", eval.Status),
Expand Down Expand Up @@ -167,7 +167,7 @@ func (c *EvalStatusCommand) Run(args []string) int {
}

if eval.BlockedEval != "" {
c.Ui.Output(fmt.Sprintf("\nEvaluation %q waiting for additional capacity to place remainder",
c.Ui.Output(fmt.Sprintf("Evaluation %q waiting for additional capacity to place remainder",
limit(eval.BlockedEval, length)))
}
}
Expand Down
56 changes: 22 additions & 34 deletions command/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,31 +244,9 @@ func (c *StatusCommand) outputJobInfo(client *api.Client, job *api.Job) error {
}

// Determine latest evaluation with failures whose follow up hasn't
// completed.
evalsByID := make(map[string]*api.Evaluation, len(jobEvals))
for _, eval := range jobEvals {
evalsByID[eval.ID] = eval
}

// completed, this is done while formatting
var latestFailedPlacement *api.Evaluation
for _, eval := range evalsByID {
if len(eval.FailedTGAllocs) == 0 {
// Skip evals without failures
continue
}

// Check if created blocked eval is finished
if blocked, ok := evalsByID[eval.BlockedEval]; ok {
if blocked.Status != "blocked" {
continue
}
}

if latestFailedPlacement == nil || latestFailedPlacement.CreateIndex < eval.CreateIndex {
latestFailedPlacement = eval
}

}
blockedEval := false

// Format the evals
evals = make([]string, len(jobEvals)+1)
Expand All @@ -281,14 +259,27 @@ func (c *StatusCommand) outputJobInfo(client *api.Client, job *api.Job) error {
eval.Status,
len(eval.FailedTGAllocs) != 0,
)

if eval.Status == "blocked" {
blockedEval = true
}

if len(eval.FailedTGAllocs) == 0 {
// Skip evals without failures
continue
}

if latestFailedPlacement == nil || latestFailedPlacement.CreateIndex < eval.CreateIndex {
latestFailedPlacement = eval
}
}

if c.verbose || c.showEvals {
c.Ui.Output("\n==> Evaluations")
c.Ui.Output(formatList(evals))
}

if latestFailedPlacement != nil {
if blockedEval && latestFailedPlacement != nil {
c.outputFailedPlacements(latestFailedPlacement)
}

Expand Down Expand Up @@ -319,27 +310,24 @@ func (c *StatusCommand) outputFailedPlacements(failedEval *api.Evaluation) {
return
}

c.Ui.Output("\n==> Last Placement Failure")
c.Ui.Output("\n==> Placement Failure")

sorted := sortedTaskGroupFromMetrics(failedEval.FailedTGAllocs)
for i, tg := range sorted {
if i >= maxFailedTGs {
break
}

c.Ui.Output(fmt.Sprintf("Task Group %q:", tg))
metrics := failedEval.FailedTGAllocs[tg]

noun := "allocation"
if metrics.CoalescedFailures > 0 {
noun += "s"
}
c.Ui.Output(fmt.Sprintf("Task Group %q (failed to place %d %s):", tg, metrics.CoalescedFailures+1, noun))
dumpAllocMetrics(c.Ui, metrics, false)
c.Ui.Output("")
if i != len(sorted)-1 {
c.Ui.Output("")
}
}

if len(sorted) > maxFailedTGs {
trunc := fmt.Sprintf("Placement failures truncated. To see remainder run:\nnomad eval-status %s", failedEval.ID)
trunc := fmt.Sprintf("\nPlacement failures truncated. To see remainder run:\nnomad eval-status %s", failedEval.ID)
c.Ui.Output(trunc)
}
}
Expand Down

0 comments on commit f5398d2

Please sign in to comment.