diff --git a/command/alloc_status.go b/command/alloc_status.go index dbcc7728d..ed124d877 100644 --- a/command/alloc_status.go +++ b/command/alloc_status.go @@ -274,6 +274,11 @@ func formatAllocBasicInfo(alloc *api.Allocation, client *api.Client, uuidLength } } + if alloc.NextAllocation != "" { + basic = append(basic, + fmt.Sprintf("Rescheduled Alloc ID|%s", limit(alloc.NextAllocation, uuidLength))) + } + if verbose { basic = append(basic, fmt.Sprintf("Evaluated Nodes|%d", alloc.Metrics.NodesEvaluated), @@ -281,6 +286,10 @@ func formatAllocBasicInfo(alloc *api.Allocation, client *api.Client, uuidLength fmt.Sprintf("Exhausted Nodes|%d", alloc.Metrics.NodesExhausted), fmt.Sprintf("Allocation Time|%s", alloc.Metrics.AllocationTime), fmt.Sprintf("Failures|%d", alloc.Metrics.CoalescedFailures)) + if alloc.RescheduleTracker != nil && len(alloc.RescheduleTracker.Events) > 0 { + basic = append(basic, + fmt.Sprintf("Previous Reschedule Attempts|%d", len(alloc.RescheduleTracker.Events))) + } } return formatKV(basic), nil diff --git a/command/alloc_status_test.go b/command/alloc_status_test.go index 9be04f3dc..6f4c789ef 100644 --- a/command/alloc_status_test.go +++ b/command/alloc_status_test.go @@ -5,12 +5,16 @@ import ( "strings" "testing" + "time" + + "github.com/hashicorp/nomad/helper/uuid" "github.com/hashicorp/nomad/nomad/mock" "github.com/hashicorp/nomad/nomad/structs" "github.com/hashicorp/nomad/testutil" "github.com/mitchellh/cli" "github.com/posener/complete" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestAllocStatusCommand_Implements(t *testing.T) { @@ -168,6 +172,42 @@ func TestAllocStatusCommand_Run(t *testing.T) { t.Fatal("expected to find alloc id in output") } ui.OutputWriter.Reset() + + // Test reschedule attempt info + require := require.New(t) + state := srv.Agent.Server().State() + a := mock.Alloc() + a.Metrics = &structs.AllocMetric{} + nextAllocId := uuid.Generate() + a.NextAllocation = nextAllocId + a.RescheduleTracker = &structs.RescheduleTracker{ + Events: []*structs.RescheduleEvent{ + { + RescheduleTime: time.Now().Add(-5 * time.Minute).UTC().UnixNano(), + PrevAllocID: uuid.Generate(), + PrevNodeID: uuid.Generate(), + }, + { + RescheduleTime: time.Now().Add(-5 * time.Minute).UTC().UnixNano(), + PrevAllocID: uuid.Generate(), + PrevNodeID: uuid.Generate(), + }, + }, + } + require.Nil(state.UpsertAllocs(1000, []*structs.Allocation{a})) + + if code := cmd.Run([]string{"-address=" + url, a.ID}); code != 0 { + t.Fatalf("expected exit 0, got: %d", code) + } + out = ui.OutputWriter.String() + require.Contains(out, "Rescheduled Alloc ID") + + if code := cmd.Run([]string{"-address=" + url, "-verbose", a.ID}); code != 0 { + t.Fatalf("expected exit 0, got: %d", code) + } + out = ui.OutputWriter.String() + require.Contains(out, "Previous Reschedule Attempts") + } func TestAllocStatusCommand_AutocompleteArgs(t *testing.T) {