Skip to content
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

update mesos-actor; cleanup orphaned failed task launches #4109

Merged
merged 2 commits into from
Nov 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion common/scala/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ dependencies {
compile 'io.kamon:kamon-core_2.12:0.6.7'
compile 'io.kamon:kamon-statsd_2.12:0.6.7'
//for mesos
compile 'com.adobe.api.platform.runtime:mesos-actor:0.0.13'
compile 'com.adobe.api.platform.runtime:mesos-actor:0.0.14'

//tracing support
compile 'io.opentracing:opentracing-api:0.31.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ import com.adobe.api.platform.runtime.mesos.SubmitTask
import com.adobe.api.platform.runtime.mesos.TaskDef
import com.adobe.api.platform.runtime.mesos.User
import java.time.Instant
import org.apache.mesos.v1.Protos.TaskState
import org.apache.mesos.v1.Protos.TaskStatus
import scala.concurrent.ExecutionContext
import scala.concurrent.Future
import scala.util.Failure
Expand Down Expand Up @@ -142,9 +140,14 @@ object MesosTask {
transid.finished(this, start, s"launched task ${taskId} at ${taskDetails.hostname}:${taskDetails
.hostports(0)}", logLevel = InfoLevel)
case Failure(ate: AskTimeoutException) =>
transid.failed(this, start, ate.getMessage, ErrorLevel)
transid.failed(this, start, s"task launch timed out ${ate.getMessage}", ErrorLevel)
MetricEmitter.emitCounterMetric(LoggingMarkers.INVOKER_MESOS_CMD_TIMEOUT(LAUNCH_CMD))
case Failure(t) => transid.failed(this, start, t.getMessage, ErrorLevel)
//kill the task whose launch timed out
destroy(mesosClientActor, mesosConfig, taskId)
case Failure(t) =>
//kill the task whose launch timed out
destroy(mesosClientActor, mesosConfig, taskId)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the future returned by destroy for andThen call would be discarded so its more like ask and forget here. Is that the intention or it would be better to have destroy completed by the time creates resulting future completes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case destroy is just cleanup that is mesos-specific, so it should happen independent of the create future; i.e. create() timeout should return immediately, but trigger the cleanup of destroy()

transid.failed(this, start, s"task launch failed ${t.getMessage}", ErrorLevel)
}
.map(taskDetails => {
val taskHost = taskDetails.hostname
Expand All @@ -155,7 +158,29 @@ object MesosTask {
})

}
private def destroy(mesosClientActor: ActorRef, mesosConfig: MesosConfig, taskId: String)(
implicit transid: TransactionId,
logging: Logging,
ec: ExecutionContext): Future[Unit] = {
val taskDeleteTimeout = Timeout(mesosConfig.timeouts.taskDelete)

val start = transid.started(
this,
LoggingMarkers.INVOKER_MESOS_CMD(MesosTask.KILL_CMD),
s"killing mesos taskid $taskId (timeout: ${taskDeleteTimeout})",
logLevel = InfoLevel)

mesosClientActor
.ask(DeleteTask(taskId))(taskDeleteTimeout)
.andThen {
case Success(_) => transid.finished(this, start, logLevel = InfoLevel)
case Failure(ate: AskTimeoutException) =>
transid.failed(this, start, s"task destroy timed out ${ate.getMessage}", ErrorLevel)
MetricEmitter.emitCounterMetric(LoggingMarkers.INVOKER_MESOS_CMD_TIMEOUT(MesosTask.KILL_CMD))
case Failure(t) => transid.failed(this, start, s"task destroy failed ${t.getMessage}", ErrorLevel)
}
.map(_ => {})
}
}

object JsonFormatters extends DefaultJsonProtocol {
Expand All @@ -171,7 +196,6 @@ class MesosTask(override protected val id: ContainerId,
mesosClientActor: ActorRef,
mesosConfig: MesosConfig)
extends Container {
val taskDeleteTimeout = Timeout(mesosConfig.timeouts.taskLaunch)

/** Stops the container from consuming CPU cycles. */
override def suspend()(implicit transid: TransactionId): Future[Unit] = {
Expand All @@ -187,30 +211,7 @@ class MesosTask(override protected val id: ContainerId,

/** Completely destroys this instance of the container. */
override def destroy()(implicit transid: TransactionId): Future[Unit] = {
val start = transid.started(
this,
LoggingMarkers.INVOKER_MESOS_CMD(MesosTask.KILL_CMD),
s"killing mesos taskid $taskId (timeout: ${taskDeleteTimeout})",
logLevel = InfoLevel)

mesosClientActor
.ask(DeleteTask(taskId))(taskDeleteTimeout)
.mapTo[TaskStatus]
.andThen {
case Success(_) => transid.finished(this, start, logLevel = InfoLevel)
case Failure(ate: AskTimeoutException) =>
transid.failed(this, start, ate.getMessage, ErrorLevel)
MetricEmitter.emitCounterMetric(LoggingMarkers.INVOKER_MESOS_CMD_TIMEOUT(MesosTask.KILL_CMD))
case Failure(t) => transid.failed(this, start, t.getMessage, ErrorLevel)
}
.map(taskStatus => {
// verify that task ended in TASK_KILLED state (but don't fail if it didn't...)
if (taskStatus.getState != TaskState.TASK_KILLED) {
logging.error(this, s"task kill resulted in unexpected state ${taskStatus.getState}")
} else {
logging.info(this, s"task killed ended with state ${taskStatus.getState}")
}
})(ec)
MesosTask.destroy(mesosClientActor, mesosConfig, taskId)
}

/**
Expand Down