-
Notifications
You must be signed in to change notification settings - Fork 846
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
Fix grace period after kill for health check failure #7221
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -17,6 +17,7 @@ import mesosphere.marathon.core.health.impl.AppHealthCheckActor.{ | |||||
} | ||||||
import mesosphere.marathon.core.health.impl.HealthCheckActor._ | ||||||
import mesosphere.marathon.core.instance.Instance | ||||||
import mesosphere.marathon.core.task.Task | ||||||
import mesosphere.marathon.core.task.termination.{KillReason, KillService} | ||||||
import mesosphere.marathon.core.task.tracker.InstanceTracker | ||||||
import mesosphere.marathon.state.{AppDefinition, Timestamp} | ||||||
|
@@ -40,7 +41,7 @@ private[health] class HealthCheckActor( | |||||
implicit val mat = ActorMaterializer() | ||||||
import context.dispatcher | ||||||
|
||||||
val healthByInstanceId = TrieMap.empty[Instance.Id, Health] | ||||||
val healthByInstanceId = TrieMap.empty[Task.Id, Health] | ||||||
|
||||||
private case class HealthCheckStreamStopped(thisInstance: this.type) | ||||||
|
||||||
|
@@ -83,10 +84,8 @@ private[health] class HealthCheckActor( | |||||
def purgeStatusOfDoneInstances(instances: Seq[Instance]): Unit = { | ||||||
logger.debug(s"Purging health status of inactive instances for app ${app.id} version ${app.version} and healthCheck ${healthCheck}") | ||||||
|
||||||
val inactiveInstanceIds: Set[Instance.Id] = instances.filterNot(_.isActive).iterator.map(_.instanceId).toSet | ||||||
inactiveInstanceIds.foreach { inactiveId => | ||||||
healthByInstanceId.remove(inactiveId) | ||||||
} | ||||||
val activeTaskIds: Set[Task.Id] = instances.map(_.appTask).filter(_.isActive).map(_.taskId).to(Set) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
healthByInstanceId.retain((taskId, health) => activeTaskIds(taskId)) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👏 |
||||||
|
||||||
val checksToPurge = instances | ||||||
.withFilter(!_.isActive) | ||||||
|
@@ -144,12 +143,12 @@ private[health] class HealthCheckActor( | |||||
|
||||||
def handleHealthResult(result: HealthResult): Unit = { | ||||||
val instanceId = result.instanceId | ||||||
val health = healthByInstanceId.getOrElse(instanceId, Health(instanceId)) | ||||||
val health = healthByInstanceId.getOrElse(result.taskId, Health(instanceId)) | ||||||
|
||||||
val updatedHealth = result match { | ||||||
case Healthy(_, _, _, _) => | ||||||
case Healthy(_, _, _, _, _) => | ||||||
Future.successful(health.update(result)) | ||||||
case Unhealthy(_, _, _, _, _) => | ||||||
case Unhealthy(_, _, _, _, _, _) => | ||||||
instanceTracker.instance(instanceId).map { | ||||||
case Some(instance) => | ||||||
if (ignoreFailures(instance, health)) { | ||||||
|
@@ -183,7 +182,7 @@ private[health] class HealthCheckActor( | |||||
val newHealth = instanceHealth.newHealth | ||||||
|
||||||
logger.info(s"Received health result for app [${app.id}] version [${app.version}]: [$result]") | ||||||
healthByInstanceId += (instanceId -> instanceHealth.newHealth) | ||||||
healthByInstanceId += (result.taskId -> instanceHealth.newHealth) | ||||||
appHealthCheckActor ! HealthCheckStatusChanged(ApplicationKey(app.id, app.version), healthCheck, newHealth) | ||||||
|
||||||
if (health.alive != newHealth.alive && result.publishEvent) { | ||||||
|
@@ -192,7 +191,9 @@ private[health] class HealthCheckActor( | |||||
} | ||||||
|
||||||
def receive: Receive = { | ||||||
case GetInstanceHealth(instanceId) => sender() ! healthByInstanceId.getOrElse(instanceId, Health(instanceId)) | ||||||
case GetInstanceHealth(instanceId) => | ||||||
sender() ! healthByInstanceId.find(_._1.instanceId == instanceId) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm... so we're going to scan a map? This seems like this could potentially perform poorly with lots of health checks. Maybe we should keep it indexed by instance id and evict the health status if the task id changes? |
||||||
.map(_._2).getOrElse(Health(instanceId)) | ||||||
|
||||||
case GetAppHealth => | ||||||
sender() ! AppHealth(healthByInstanceId.values.to(Seq)) | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems like we oughta rename this map?