Pass through timestamp
This commit is contained in:
parent
c49b5f9949
commit
99e00fb774
|
@ -194,9 +194,10 @@ func (w *deploymentWatcher) SetAllocHealth(
|
|||
// Create the request
|
||||
areq := &structs.ApplyDeploymentAllocHealthRequest{
|
||||
DeploymentAllocHealthRequest: *req,
|
||||
Eval: w.getEval(),
|
||||
DeploymentUpdate: u,
|
||||
Job: j,
|
||||
Timestamp: time.Now(),
|
||||
Eval: w.getEval(),
|
||||
DeploymentUpdate: u,
|
||||
Job: j,
|
||||
}
|
||||
|
||||
index, err := w.upsertDeploymentAllocHealth(areq)
|
||||
|
|
|
@ -196,6 +196,11 @@ func matchDeploymentAllocHealthRequest(c *matchDeploymentAllocHealthRequestConfi
|
|||
return false
|
||||
}
|
||||
|
||||
// Require a timestamp
|
||||
if args.Timestamp.IsZero() {
|
||||
return false
|
||||
}
|
||||
|
||||
if len(c.Healthy) != len(args.HealthyAllocationIDs) {
|
||||
return false
|
||||
}
|
||||
|
|
|
@ -2715,7 +2715,7 @@ func (s *StateStore) UpdateDeploymentAllocHealth(index uint64, req *structs.Appl
|
|||
|
||||
// Update the health status of each allocation
|
||||
if total := len(req.HealthyAllocationIDs) + len(req.UnhealthyAllocationIDs); total != 0 {
|
||||
setAllocHealth := func(id string, healthy bool) error {
|
||||
setAllocHealth := func(id string, healthy bool, ts time.Time) error {
|
||||
existing, err := txn.First("allocs", "id", id)
|
||||
if err != nil {
|
||||
return fmt.Errorf("alloc %q lookup failed: %v", id, err)
|
||||
|
@ -2735,6 +2735,7 @@ func (s *StateStore) UpdateDeploymentAllocHealth(index uint64, req *structs.Appl
|
|||
copy.DeploymentStatus = &structs.AllocDeploymentStatus{}
|
||||
}
|
||||
copy.DeploymentStatus.Healthy = helper.BoolToPtr(healthy)
|
||||
copy.DeploymentStatus.Timestamp = ts
|
||||
copy.DeploymentStatus.ModifyIndex = index
|
||||
|
||||
if err := s.updateDeploymentWithAlloc(index, copy, old, txn); err != nil {
|
||||
|
@ -2749,12 +2750,12 @@ func (s *StateStore) UpdateDeploymentAllocHealth(index uint64, req *structs.Appl
|
|||
}
|
||||
|
||||
for _, id := range req.HealthyAllocationIDs {
|
||||
if err := setAllocHealth(id, true); err != nil {
|
||||
if err := setAllocHealth(id, true, req.Timestamp); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
for _, id := range req.UnhealthyAllocationIDs {
|
||||
if err := setAllocHealth(id, false); err != nil {
|
||||
if err := setAllocHealth(id, false, req.Timestamp); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5935,6 +5935,9 @@ func TestStateStore_UpsertDeploymentAllocHealth(t *testing.T) {
|
|||
StatusDescription: desc,
|
||||
}
|
||||
|
||||
// Capture the time for the update
|
||||
ts := time.Now()
|
||||
|
||||
// Set health against the deployment
|
||||
req := &structs.ApplyDeploymentAllocHealthRequest{
|
||||
DeploymentAllocHealthRequest: structs.DeploymentAllocHealthRequest{
|
||||
|
@ -5945,6 +5948,7 @@ func TestStateStore_UpsertDeploymentAllocHealth(t *testing.T) {
|
|||
Job: j,
|
||||
Eval: e,
|
||||
DeploymentUpdate: u,
|
||||
Timestamp: ts,
|
||||
}
|
||||
err := state.UpdateDeploymentAllocHealth(3, req)
|
||||
if err != nil {
|
||||
|
@ -5995,6 +5999,13 @@ func TestStateStore_UpsertDeploymentAllocHealth(t *testing.T) {
|
|||
if !out2.DeploymentStatus.IsUnhealthy() {
|
||||
t.Fatalf("bad: alloc %q not unhealthy", out2.ID)
|
||||
}
|
||||
|
||||
if !out1.DeploymentStatus.Timestamp.Equal(ts) {
|
||||
t.Fatalf("bad: alloc %q had timestamp %v; want %v", out1.ID, out1.DeploymentStatus.Timestamp, ts)
|
||||
}
|
||||
if !out2.DeploymentStatus.Timestamp.Equal(ts) {
|
||||
t.Fatalf("bad: alloc %q had timestamp %v; want %v", out2.ID, out2.DeploymentStatus.Timestamp, ts)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStateStore_UpsertVaultAccessors(t *testing.T) {
|
||||
|
|
|
@ -788,6 +788,9 @@ type DeploymentAllocHealthRequest struct {
|
|||
type ApplyDeploymentAllocHealthRequest struct {
|
||||
DeploymentAllocHealthRequest
|
||||
|
||||
// Timestamp is the timestamp to use when setting the allocations health.
|
||||
Timestamp time.Time
|
||||
|
||||
// An optional field to update the status of a deployment
|
||||
DeploymentUpdate *DeploymentStatusUpdate
|
||||
|
||||
|
|
Loading…
Reference in a new issue