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

Commit

Permalink
Add deployment failure reason to event. (#6011)
Browse files Browse the repository at this point in the history
Summary:
Currently we do not send the reason for a deployment failure along with
the event. This makes debugging hard. This change introduces an optional
reason message.
  • Loading branch information
jeschkies authored Feb 14, 2018
1 parent fe69c84 commit 0177db1
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
5 changes: 5 additions & 0 deletions docs/docs/rest-api/public/api/v2/events.raml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ get:
description:
Specify subscribed event types.
You can specify this parameter multiple times with different values.
plan-format:
required: false
description:
Indicate whether to receive "light" events or full events including
deployment plans. Defaults to full events.

responses:
200:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ class MarathonSchedulerActor private (
logger.error(s"Deployment ${plan.id}:${plan.version} of ${plan.targetIdsString} failed", reason)
Future.sequence(plan.affectedRunSpecIds.map(launchQueue.asyncPurge))
.recover { case NonFatal(error) => logger.warn(s"Error during async purge: planId=${plan.id} for ${plan.targetIdsString}", error); Done }
.foreach { _ => eventBus.publish(core.event.DeploymentFailed(plan.id, plan)) }
.foreach { _ => eventBus.publish(core.event.DeploymentFailed(plan.id, plan, reason = Some(reason.getMessage()))) }
}
}

Expand Down
9 changes: 8 additions & 1 deletion src/main/scala/mesosphere/marathon/api/v2/json/Formats.scala
Original file line number Diff line number Diff line change
Expand Up @@ -293,12 +293,19 @@ trait EventFormats {
)
}
implicit lazy val LightDeploymentFailedWrites: Writes[DeploymentFailed] = Writes { event =>
Json.obj(
val serializedEvent = Json.obj(
"id" -> event.id,
"plan" -> LightDeploymentPlanWrites.writes(event.plan),
"eventType" -> "deployment_failed",
"timestamp" -> Timestamp.now().toString
)

event.reason match {
case Some(reason) =>
serializedEvent ++ Json.obj("reason" -> reason)
case None =>
serializedEvent
}
}
implicit lazy val LightDeploymentStatusWrites: Writes[DeploymentStatus] = Writes { event =>
Json.obj(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class DeploymentManagerActor(
sender() ! cancelDeployment(plan.id)

case DeploymentFinished(plan, result) =>
runningDeployments.remove(plan.id).map { deploymentInfo =>
runningDeployments.remove(plan.id).foreach { deploymentInfo =>
logger.info(s"Removing ${plan.id} for ${plan.targetIdsString} from list of running deployments")
deploymentStatus -= plan.id
deploymentRepository.delete(plan.id)
Expand Down Expand Up @@ -189,7 +189,7 @@ class DeploymentManagerActor(
waitForCanceledConflicts(plan, conflicts)

case FailedRepositoryOperation(plan, reason) if isScheduledDeployment(plan.id) =>
runningDeployments.remove(plan.id).map(info => info.promise.failure(reason))
runningDeployments.remove(plan.id).foreach(info => info.promise.failure(reason))
}

private def giveUpConflictingDeployment(plan: DeploymentPlan, origSender: ActorRef): Future[Done] = {
Expand Down
3 changes: 2 additions & 1 deletion src/main/scala/mesosphere/marathon/core/event/Events.scala
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ case class DeploymentFailed(
id: String,
plan: DeploymentPlan,
eventType: String = "deployment_failed",
timestamp: String = Timestamp.now().toString) extends UpgradeEvent
timestamp: String = Timestamp.now().toString,
reason: Option[String] = None) extends UpgradeEvent

case class DeploymentStatus(
plan: DeploymentPlan,
Expand Down

0 comments on commit 0177db1

Please sign in to comment.