From 97df5d2bdfcaf5dfe2d194986174a956791d3883 Mon Sep 17 00:00:00 2001 From: Diptanu Choudhury Date: Tue, 12 Jul 2016 14:27:45 -0600 Subject: [PATCH] Accounting lost state of allocations --- nomad/state/state_store.go | 19 ++++--------------- nomad/state/state_store_test.go | 2 ++ nomad/structs/structs.go | 1 + 3 files changed, 7 insertions(+), 15 deletions(-) diff --git a/nomad/state/state_store.go b/nomad/state/state_store.go index 2d60d7410..d37024c4d 100644 --- a/nomad/state/state_store.go +++ b/nomad/state/state_store.go @@ -1299,6 +1299,8 @@ func (s *StateStore) updateSummaryWithAlloc(newAlloc *structs.Allocation, tgSummary.Starting += 1 case structs.AllocClientStatusComplete: tgSummary.Complete += 1 + case structs.AllocClientStatusLost: + tgSummary.Lost += 1 } // Decrementing the count of the bin of the last state @@ -1311,21 +1313,8 @@ func (s *StateStore) updateSummaryWithAlloc(newAlloc *structs.Allocation, tgSummary.Starting -= 1 case structs.AllocClientStatusComplete: tgSummary.Complete -= 1 - } - } else if existingAlloc.DesiredStatus != newAlloc.DesiredStatus { - shouldDecrementStarting := false - switch newAlloc.DesiredStatus { - case structs.AllocDesiredStatusFailed: - tgSummary.Failed += 1 - shouldDecrementStarting = true - case structs.AllocDesiredStatusStop: - tgSummary.Complete += 1 - shouldDecrementStarting = true - } - if shouldDecrementStarting { - if newAlloc.ClientStatus == structs.AllocClientStatusPending { - tgSummary.Starting -= 1 - } + case structs.AllocClientStatusLost: + tgSummary.Lost -= 1 } } diff --git a/nomad/state/state_store_test.go b/nomad/state/state_store_test.go index 9ce1c58e4..a6a4f5ece 100644 --- a/nomad/state/state_store_test.go +++ b/nomad/state/state_store_test.go @@ -2369,12 +2369,14 @@ func TestStateJobSummary_UpdateJobCount(t *testing.T) { alloc4.Job = alloc2.Job alloc4.JobID = alloc2.JobID alloc4.DesiredStatus = structs.AllocDesiredStatusStop + alloc4.ClientStatus = structs.AllocClientStatusComplete alloc5 := mock.Alloc() alloc5.ID = alloc3.ID alloc5.Job = alloc3.Job alloc5.JobID = alloc3.JobID alloc5.DesiredStatus = structs.AllocDesiredStatusStop + alloc5.ClientStatus = structs.AllocClientStatusComplete if err := state.UpsertAllocs(1004, []*structs.Allocation{alloc4, alloc5}); err != nil { t.Fatalf("err: %v", err) diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index bd2baea6b..7bebe65c2 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -955,6 +955,7 @@ type TaskGroupSummary struct { Failed int Running int Starting int + Lost int } // Total returns the total number of allocations for the task group.