diff --git a/client/alloc_runner.go b/client/alloc_runner.go index 61410e576..aeb284a3b 100644 --- a/client/alloc_runner.go +++ b/client/alloc_runner.go @@ -50,7 +50,8 @@ type AllocRunner struct { alloc *structs.Allocation allocClientStatus string // Explicit status of allocation. Set when there are failures allocClientDescription string - allocHealth *bool // Whether the allocation is healthy + allocHealth *bool // Whether the allocation is healthy + allocHealthTime time.Time // Time at which allocation health has been set allocBroadcast *cstructs.AllocBroadcaster allocLock sync.Mutex @@ -577,11 +578,10 @@ func (r *AllocRunner) Alloc() *structs.Allocation { // The health has been set if r.allocHealth != nil { if alloc.DeploymentStatus == nil { - alloc.DeploymentStatus = &structs.AllocDeploymentStatus{ - Timestamp: time.Now(), - } + alloc.DeploymentStatus = &structs.AllocDeploymentStatus{} } alloc.DeploymentStatus.Healthy = helper.BoolToPtr(*r.allocHealth) + alloc.DeploymentStatus.Timestamp = r.allocHealthTime } r.allocLock.Unlock() @@ -945,6 +945,7 @@ OUTER: // If the deployment ids have changed clear the health if r.alloc.DeploymentID != update.DeploymentID { r.allocHealth = nil + r.allocHealthTime = time.Time{} } r.alloc = update diff --git a/client/alloc_runner_health_watcher.go b/client/alloc_runner_health_watcher.go index f193b41e2..ede4eaeaa 100644 --- a/client/alloc_runner_health_watcher.go +++ b/client/alloc_runner_health_watcher.go @@ -112,6 +112,7 @@ func (r *AllocRunner) watchHealth(ctx context.Context) { r.allocLock.Lock() r.allocHealth = helper.BoolToPtr(allocHealthy) + r.allocHealthTime = time.Now() r.allocLock.Unlock() // If deployment is unhealthy emit task events explaining why