This repository has been archived by the owner on Oct 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 840
Fix grace period after kill for health check failure #7221
Open
komuta
wants to merge
1
commit into
d2iq-archive:master
Choose a base branch
from
criteo-forks:fix-grace-period-upstream
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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?