Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

Commit

Permalink
fixes #1106 - Return empty HealthCheck result instead on None, when n…
Browse files Browse the repository at this point in the history
…o results are present
  • Loading branch information
drexin committed Jan 27, 2015
1 parent 5e148fb commit 3f1eabe
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ import mesosphere.marathon.state.PathId
case class EnrichedTask(
appId: PathId,
task: MarathonTask,
healthCheckResults: Seq[Option[Health]],
healthCheckResults: Seq[Health],
servicePorts: Seq[Int] = Nil)
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class HealthCheckActor(
}

def receive: Receive = {
case GetTaskHealth(taskId) => sender() ! taskHealth.get(taskId)
case GetTaskHealth(taskId) => sender() ! taskHealth.getOrElse(taskId, Health(taskId))

case Tick =>
purgeStatusOfDoneTasks()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ trait HealthCheckManager {
/**
* Returns the health status of the supplied task.
*/
def status(appId: PathId, taskId: String): Future[Seq[Option[Health]]]
def status(appId: PathId, taskId: String): Future[Seq[Health]]

}
Original file line number Diff line number Diff line change
Expand Up @@ -175,17 +175,17 @@ class MarathonHealthCheckManager @Inject() (

override def status(
appId: PathId,
taskId: String): Future[Seq[Option[Health]]] =
taskId: String): Future[Seq[Health]] =
withReadLock {
import mesosphere.marathon.health.HealthCheckActor.GetTaskHealth
implicit val timeout: Timeout = Timeout(2, SECONDS)

val maybeAppVersion: Option[Timestamp] = taskTracker.getVersion(appId, taskId)

val taskHealth: Seq[Future[Option[Health]]] = maybeAppVersion.map { appVersion =>
val taskHealth: Seq[Future[Health]] = maybeAppVersion.map { appVersion =>
listActive(appId, appVersion).toSeq.collect {
case ActiveHealthCheck(_, actor) =>
(actor ? GetTaskHealth(taskId)).mapTo[Option[Health]]
(actor ? GetTaskHealth(taskId)).mapTo[Health]
}
}.getOrElse(Nil)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,14 @@ class MarathonHealthCheckManagerTest extends MarathonSpec with Logging {
hcManager.add(appId, version, healthCheck)

val status1 = Await.result(hcManager.status(appId, taskId.getValue), 5.seconds)
assert(status1 == Seq(None))
assert(status1 == Seq(Health(taskId.getValue)))

// send unhealthy task status
EventFilter.info(start = "Received health result: [", occurrences = 1).intercept {
hcManager.update(taskStatus.toBuilder.setHealthy(false).build, version)
}

val Seq(Some(health2)) = Await.result(hcManager.status(appId, taskId.getValue), 5.seconds)
val Seq(health2) = Await.result(hcManager.status(appId, taskId.getValue), 5.seconds)
assert(health2.lastFailure.isDefined)
assert(health2.lastSuccess.isEmpty)

Expand All @@ -107,7 +107,7 @@ class MarathonHealthCheckManagerTest extends MarathonSpec with Logging {
hcManager.update(taskStatus.toBuilder.setHealthy(true).build, version)
}

val Seq(Some(health3)) = Await.result(hcManager.status(appId, taskId.getValue), 5.seconds)
val Seq(health3) = Await.result(hcManager.status(appId, taskId.getValue), 5.seconds)
assert(health3.lastFailure.isDefined)
assert(health3.lastSuccess.isDefined)
assert(health3.lastSuccess > health3.lastFailure)
Expand Down

0 comments on commit 3f1eabe

Please sign in to comment.