mirror of
https://github.com/kemko/nomad.git
synced 2026-01-04 17:35:43 +03:00
Add ModifyTime to Allocation and update it both on plan applies and client initiated updates
This commit is contained in:
@@ -95,6 +95,7 @@ type Allocation struct {
|
||||
ModifyIndex uint64
|
||||
AllocModifyIndex uint64
|
||||
CreateTime int64
|
||||
ModifyTime int64
|
||||
}
|
||||
|
||||
// AllocationMetric is used to deserialize allocation metrics.
|
||||
@@ -132,11 +133,12 @@ type AllocationListStub struct {
|
||||
CreateIndex uint64
|
||||
ModifyIndex uint64
|
||||
CreateTime int64
|
||||
ModifyTime int64
|
||||
}
|
||||
|
||||
// AllocDeploymentStatus captures the status of the allocation as part of the
|
||||
// deployment. This can include things like if the allocation has been marked as
|
||||
// heatlhy.
|
||||
// healthy.
|
||||
type AllocDeploymentStatus struct {
|
||||
Healthy *bool
|
||||
ModifyIndex uint64
|
||||
|
||||
@@ -822,6 +822,10 @@ func (n *Node) UpdateAlloc(args *structs.AllocUpdateRequest, reply *structs.Gene
|
||||
|
||||
// Add this to the batch
|
||||
n.updatesLock.Lock()
|
||||
now := time.Now().UTC().UnixNano()
|
||||
for _, alloc := range args.Alloc {
|
||||
alloc.ModifyTime = now
|
||||
}
|
||||
n.updates = append(n.updates, args.Alloc...)
|
||||
|
||||
// Start a new batch if none
|
||||
|
||||
@@ -1323,8 +1323,10 @@ func TestClientEndpoint_GetClientAllocs_Blocking(t *testing.T) {
|
||||
node.ModifyIndex = resp.Index
|
||||
|
||||
// Inject fake evaluations async
|
||||
now := time.Now().UTC().UnixNano()
|
||||
alloc := mock.Alloc()
|
||||
alloc.NodeID = node.ID
|
||||
alloc.ModifyTime = now
|
||||
state := s1.fsm.State()
|
||||
state.UpsertJobSummary(99, mock.JobSummary(alloc.JobID))
|
||||
start := time.Now()
|
||||
@@ -1363,6 +1365,10 @@ func TestClientEndpoint_GetClientAllocs_Blocking(t *testing.T) {
|
||||
t.Fatalf("bad: %#v", resp2.Allocs)
|
||||
}
|
||||
|
||||
if resp2.Allocs[0].ModifyTime != now {
|
||||
t.Fatalf("Invalid modify time %v", resp2.Allocs[0].ModifyTime)
|
||||
}
|
||||
|
||||
// Alloc updates fire watches
|
||||
time.AfterFunc(100*time.Millisecond, func() {
|
||||
allocUpdate := mock.Alloc()
|
||||
@@ -1675,6 +1681,10 @@ func TestClientEndpoint_UpdateAlloc(t *testing.T) {
|
||||
if out.ClientStatus != structs.AllocClientStatusFailed {
|
||||
t.Fatalf("Bad: %#v", out)
|
||||
}
|
||||
|
||||
if out.ModifyTime <= 0 {
|
||||
t.Fatalf("must have valid modify time but was %v", out.ModifyTime)
|
||||
}
|
||||
}
|
||||
|
||||
func TestClientEndpoint_BatchUpdate(t *testing.T) {
|
||||
|
||||
@@ -149,6 +149,8 @@ func (s *Server) applyPlan(plan *structs.Plan, result *structs.PlanResult, snap
|
||||
for _, alloc := range req.Alloc {
|
||||
if alloc.CreateTime == 0 {
|
||||
alloc.CreateTime = now
|
||||
} else {
|
||||
alloc.ModifyTime = now
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -226,6 +226,10 @@ func TestPlanApply_applyPlan(t *testing.T) {
|
||||
t.Fatalf("missing job")
|
||||
}
|
||||
|
||||
if out.ModifyTime <= 0 {
|
||||
t.Fatalf("must have valid modify time but was %v", out.ModifyTime)
|
||||
}
|
||||
|
||||
// Lookup the allocation
|
||||
out, err = s1.fsm.State().AllocByID(ws, alloc2.ID)
|
||||
if err != nil {
|
||||
|
||||
@@ -1718,6 +1718,9 @@ func (s *StateStore) nestedUpdateAllocFromClient(txn *memdb.Txn, index uint64, a
|
||||
// Update the modify index
|
||||
copyAlloc.ModifyIndex = index
|
||||
|
||||
// Update the modify time
|
||||
copyAlloc.ModifyTime = alloc.ModifyTime
|
||||
|
||||
if err := s.updateDeploymentWithAlloc(index, copyAlloc, exist, txn); err != nil {
|
||||
return fmt.Errorf("error updating deployment: %v", err)
|
||||
}
|
||||
|
||||
@@ -4605,6 +4605,9 @@ type Allocation struct {
|
||||
// CreateTime is the time the allocation has finished scheduling and been
|
||||
// verified by the plan applier.
|
||||
CreateTime int64
|
||||
|
||||
// ModifyTime is the time the allocation was last updated.
|
||||
ModifyTime int64
|
||||
}
|
||||
|
||||
// Index returns the index of the allocation. If the allocation is from a task
|
||||
@@ -4746,6 +4749,7 @@ func (a *Allocation) Stub() *AllocListStub {
|
||||
CreateIndex: a.CreateIndex,
|
||||
ModifyIndex: a.ModifyIndex,
|
||||
CreateTime: a.CreateTime,
|
||||
ModifyTime: a.ModifyTime,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4767,6 +4771,7 @@ type AllocListStub struct {
|
||||
CreateIndex uint64
|
||||
ModifyIndex uint64
|
||||
CreateTime int64
|
||||
ModifyTime int64
|
||||
}
|
||||
|
||||
// AllocMetric is used to track various metrics while attempting
|
||||
|
||||
Reference in New Issue
Block a user