Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add timestamps to evals #5881

Merged
merged 10 commits into from
Aug 7, 2019
2 changes: 2 additions & 0 deletions api/evaluations.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ type Evaluation struct {
SnapshotIndex uint64
CreateIndex uint64
ModifyIndex uint64
CreateTime int64
ModifyTime int64
}

// EvalIndexSort is a wrapper to sort evaluations by CreateIndex.
Expand Down
6 changes: 6 additions & 0 deletions nomad/job_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ func (j *Job) Register(args *structs.JobRegisterRequest, reply *structs.JobRegis
JobID: args.Job.ID,
JobModifyIndex: reply.JobModifyIndex,
Status: structs.EvalStatusPending,
CreateTime: time.Now().UTC().UnixNano(),
ModifyTime: time.Now().UTC().UnixNano(),
}
update := &structs.EvalUpdateRequest{
Evals: []*structs.Evaluation{eval},
Expand Down Expand Up @@ -659,6 +661,8 @@ func (j *Job) Deregister(args *structs.JobDeregisterRequest, reply *structs.JobD
JobID: args.JobID,
JobModifyIndex: index,
Status: structs.EvalStatusPending,
CreateTime: time.Now().UTC().UnixNano(),
ModifyTime: time.Now().UTC().UnixNano(),
}
update := &structs.EvalUpdateRequest{
Evals: []*structs.Evaluation{eval},
Expand Down Expand Up @@ -1424,6 +1428,8 @@ func (j *Job) Dispatch(args *structs.JobDispatchRequest, reply *structs.JobDispa
JobID: dispatchJob.ID,
JobModifyIndex: jobCreateIndex,
Status: structs.EvalStatusPending,
CreateTime: time.Now().UTC().UnixNano(),
ModifyTime: time.Now().UTC().UnixNano(),
}
update := &structs.EvalUpdateRequest{
Evals: []*structs.Evaluation{eval},
Expand Down
6 changes: 6 additions & 0 deletions nomad/leader.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,8 +532,12 @@ func (s *Server) reapFailedEvaluations(stopCh chan struct{}) {
// due to the fairly large backoff.
followupEvalWait := s.config.EvalFailedFollowupBaselineDelay +
time.Duration(rand.Int63n(int64(s.config.EvalFailedFollowupDelayRange)))

// TODO: what is this followup eval and where to create timestamp?
jazzyfresh marked this conversation as resolved.
Show resolved Hide resolved
followupEval := eval.CreateFailedFollowUpEval(followupEvalWait)
updateEval.NextEval = followupEval.ID
updateEval.CreateTime = time.Now().UTC().UnixNano()
jazzyfresh marked this conversation as resolved.
Show resolved Hide resolved
updateEval.ModifyTime = time.Now().UTC().UnixNano()
jazzyfresh marked this conversation as resolved.
Show resolved Hide resolved
jazzyfresh marked this conversation as resolved.
Show resolved Hide resolved
jazzyfresh marked this conversation as resolved.
Show resolved Hide resolved

// Update via Raft
req := structs.EvalUpdateRequest{
Expand Down Expand Up @@ -570,6 +574,8 @@ func (s *Server) reapDupBlockedEvaluations(stopCh chan struct{}) {
newEval := dup.Copy()
newEval.Status = structs.EvalStatusCancelled
newEval.StatusDescription = fmt.Sprintf("existing blocked evaluation exists for job %q", newEval.JobID)
newEval.CreateTime = time.Now().UTC().UnixNano()
jazzyfresh marked this conversation as resolved.
Show resolved Hide resolved
newEval.ModifyTime = time.Now().UTC().UnixNano()
cancel[i] = newEval
}

Expand Down
2 changes: 2 additions & 0 deletions nomad/mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,8 @@ func Eval() *structs.Evaluation {
Type: structs.JobTypeService,
JobID: uuid.Generate(),
Status: structs.EvalStatusPending,
CreateTime: time.Now().UTC().UnixNano(),
ModifyTime: time.Now().UTC().UnixNano(),
}
return eval
}
Expand Down
6 changes: 6 additions & 0 deletions nomad/node_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -1095,6 +1095,8 @@ func (n *Node) batchUpdate(future *structs.BatchFuture, updates []*structs.Alloc
}
_, exists := evalsByJobId[namespacedID]
if !exists {
eval.CreateTime = time.Now().UTC().UnixNano()
eval.ModifyTime = time.Now().UTC().UnixNano()
trimmedEvals = append(trimmedEvals, eval)
evalsByJobId[namespacedID] = struct{}{}
}
Expand Down Expand Up @@ -1261,6 +1263,8 @@ func (n *Node) createNodeEvals(nodeID string, nodeIndex uint64) ([]string, uint6
NodeID: nodeID,
NodeModifyIndex: nodeIndex,
Status: structs.EvalStatusPending,
CreateTime: time.Now().UTC().UnixNano(),
ModifyTime: time.Now().UTC().UnixNano(),
}
evals = append(evals, eval)
evalIDs = append(evalIDs, eval.ID)
Expand All @@ -1285,6 +1289,8 @@ func (n *Node) createNodeEvals(nodeID string, nodeIndex uint64) ([]string, uint6
NodeID: nodeID,
NodeModifyIndex: nodeIndex,
Status: structs.EvalStatusPending,
CreateTime: time.Now().UTC().UnixNano(),
ModifyTime: time.Now().UTC().UnixNano(),
}
evals = append(evals, eval)
evalIDs = append(evalIDs, eval.ID)
Expand Down
3 changes: 3 additions & 0 deletions nomad/periodic.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ func (s *Server) DispatchJob(job *structs.Job) (*structs.Evaluation, error) {
JobID: job.ID,
JobModifyIndex: index,
Status: structs.EvalStatusPending,
CreateTime: time.Now().UTC().UnixNano(),
ModifyTime: time.Now().UTC().UnixNano(),
}
update := &structs.EvalUpdateRequest{
Evals: []*structs.Evaluation{eval},
Expand All @@ -85,6 +87,7 @@ func (s *Server) DispatchJob(job *structs.Job) (*structs.Evaluation, error) {
return nil, err
}

// TODO: do the timestamps need to be at the same time that the raft index is updated?
jazzyfresh marked this conversation as resolved.
Show resolved Hide resolved
// Update its indexes.
eval.CreateIndex = evalIndex
eval.ModifyIndex = evalIndex
Expand Down
12 changes: 12 additions & 0 deletions nomad/state/state_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,8 @@ func (s *StateStore) UpsertPlanResults(index uint64, results *structs.ApplyPlanR

// Upsert followup evals for allocs that were preempted
for _, eval := range results.PreemptionEvals {
jazzyfresh marked this conversation as resolved.
Show resolved Hide resolved
eval.CreateTime = time.Now().UTC().UnixNano()
eval.ModifyTime = time.Now().UTC().UnixNano()
if err := s.nestedUpsertEval(txn, index, eval); err != nil {
return err
}
Expand Down Expand Up @@ -1724,6 +1726,8 @@ func (s *StateStore) UpsertEvalsTxn(index uint64, evals []*structs.Evaluation, t
// Do a nested upsert
jobs := make(map[structs.NamespacedID]string, len(evals))
for _, eval := range evals {
eval.CreateTime = time.Now().UTC().UnixNano()
eval.ModifyTime = time.Now().UTC().UnixNano()
if err := s.nestedUpsertEval(txn, index, eval); err != nil {
return err
}
Expand Down Expand Up @@ -2313,6 +2317,8 @@ func (s *StateStore) UpdateAllocsDesiredTransitions(index uint64, allocs map[str
}

for _, eval := range evals {
eval.CreateTime = time.Now().UTC().UnixNano()
eval.ModifyTime = time.Now().UTC().UnixNano()
if err := s.nestedUpsertEval(txn, index, eval); err != nil {
return err
}
Expand Down Expand Up @@ -2724,6 +2730,8 @@ func (s *StateStore) UpdateDeploymentStatus(index uint64, req *structs.Deploymen

// Upsert the optional eval
if req.Eval != nil {
req.Eval.CreateTime = time.Now().UTC().UnixNano()
req.Eval.ModifyTime = time.Now().UTC().UnixNano()
if err := s.nestedUpsertEval(txn, index, req.Eval); err != nil {
return err
}
Expand Down Expand Up @@ -2940,6 +2948,8 @@ func (s *StateStore) UpdateDeploymentPromotion(index uint64, req *structs.ApplyD

// Upsert the optional eval
if req.Eval != nil {
req.Eval.CreateTime = time.Now().UTC().UnixNano()
req.Eval.ModifyTime = time.Now().UTC().UnixNano()
if err := s.nestedUpsertEval(txn, index, req.Eval); err != nil {
return err
}
Expand Down Expand Up @@ -3054,6 +3064,8 @@ func (s *StateStore) UpdateDeploymentAllocHealth(index uint64, req *structs.Appl

// Upsert the optional eval
if req.Eval != nil {
req.Eval.CreateTime = time.Now().UTC().UnixNano()
req.Eval.ModifyTime = time.Now().UTC().UnixNano()
if err := s.nestedUpsertEval(txn, index, req.Eval); err != nil {
return err
}
Expand Down
3 changes: 3 additions & 0 deletions nomad/structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -8394,6 +8394,9 @@ type Evaluation struct {
// Raft Indexes
CreateIndex uint64
ModifyIndex uint64

CreateTime int64
ModifyTime int64
jazzyfresh marked this conversation as resolved.
Show resolved Hide resolved
}

// TerminalStatus returns if the current status is terminal and
Expand Down
6 changes: 6 additions & 0 deletions nomad/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,8 @@ func (w *Worker) UpdateEval(eval *structs.Evaluation) error {

// Store the snapshot index in the eval
eval.SnapshotIndex = w.snapshotIndex
eval.CreateTime = time.Now().UTC().UnixNano()
jazzyfresh marked this conversation as resolved.
Show resolved Hide resolved
eval.ModifyTime = time.Now().UTC().UnixNano()

// Setup the request
req := structs.EvalUpdateRequest{
Expand Down Expand Up @@ -386,6 +388,8 @@ func (w *Worker) CreateEval(eval *structs.Evaluation) error {

// Store the snapshot index in the eval
eval.SnapshotIndex = w.snapshotIndex
eval.CreateTime = time.Now().UTC().UnixNano()
eval.ModifyTime = time.Now().UTC().UnixNano()

// Setup the request
req := structs.EvalUpdateRequest{
Expand Down Expand Up @@ -447,6 +451,8 @@ func (w *Worker) ReblockEval(eval *structs.Evaluation) error {

// Store the snapshot index in the eval
eval.SnapshotIndex = w.snapshotIndex
eval.CreateTime = time.Now().UTC().UnixNano()
jazzyfresh marked this conversation as resolved.
Show resolved Hide resolved
eval.ModifyTime = time.Now().UTC().UnixNano()

// Setup the request
req := structs.EvalUpdateRequest{
Expand Down