This repository has been archived by the owner on Jan 9, 2020. It is now read-only.
forked from apache/spark
-
Notifications
You must be signed in to change notification settings - Fork 118
Introduce blocking submit to kubernetes by default #53
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
e999b21
Introduce blocking submit to kubernetes by default
ash211 3371b49
Minor touchups
ash211 3f278f3
More succinct logging for pod state
ash211 4c55ea8
Fix import order
ash211 67ed06a
Switch to watch-based logging
ash211 2cbe11f
Spaces in comma-joined volumes, labels, and containers
ash211 a69b865
Use CountDownLatch instead of SettableFuture
ash211 f44ca49
Match parallel ConfigBuilder style
ash211 c63e5e5
Disable logging in fire-and-forget mode
ash211 db39eac
Merge remote-tracking branch 'k8s-group/k8s-support-alternate-increme…
ash211 61fbed3
Additional log line for when application is launched
ash211 6ef7df8
Minor wording changes
ash211 1d92854
More logging
ash211 d019cc9
Drop log to DEBUG
ash211 f35dc34
Merge remote-tracking branch 'k8s-group/k8s-support-alternate-increme…
ash211 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
114 changes: 114 additions & 0 deletions
114
...etes/core/src/main/scala/org/apache/spark/deploy/kubernetes/LoggingPodStatusWatcher.scala
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 |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.spark.deploy.kubernetes | ||
|
||
import java.util.concurrent.{CountDownLatch, Executors, TimeUnit} | ||
|
||
import scala.collection.JavaConverters._ | ||
|
||
import io.fabric8.kubernetes.api.model.Pod | ||
import io.fabric8.kubernetes.client.{KubernetesClientException, Watcher} | ||
import io.fabric8.kubernetes.client.Watcher.Action | ||
|
||
import org.apache.spark.internal.Logging | ||
|
||
/** | ||
* A monitor for the running Kubernetes pod of a Spark application. Status logging occurs on | ||
* every state change and also at an interval for liveness. | ||
* | ||
* @param podCompletedFuture a CountDownLatch that is set to true when the watched pod finishes | ||
* @param appId | ||
* @param interval ms between each state request. If set to 0 or a negative number, the periodic | ||
* logging will be disabled. | ||
*/ | ||
private[kubernetes] class LoggingPodStatusWatcher(podCompletedFuture: CountDownLatch, | ||
appId: String, | ||
interval: Long) | ||
extends Watcher[Pod] with Logging { | ||
|
||
// start timer for periodic logging | ||
private val scheduler = Executors.newScheduledThreadPool(1) | ||
private val logRunnable: Runnable = new Runnable { | ||
override def run() = logShortStatus() | ||
} | ||
if (interval > 0) { | ||
scheduler.scheduleWithFixedDelay(logRunnable, 0, interval, TimeUnit.MILLISECONDS) | ||
} | ||
|
||
private var pod: Option[Pod] = Option.empty | ||
private var prevPhase: String = null | ||
private def phase: String = pod.map(_.getStatus().getPhase()).getOrElse("unknown") | ||
|
||
override def eventReceived(action: Action, pod: Pod): Unit = { | ||
this.pod = Option(pod) | ||
|
||
logShortStatus() | ||
if (prevPhase != phase) { | ||
logLongStatus() | ||
} | ||
prevPhase = phase | ||
|
||
if (phase == "Succeeded" || phase == "Failed") { | ||
podCompletedFuture.countDown() | ||
} | ||
} | ||
|
||
override def onClose(e: KubernetesClientException): Unit = { | ||
scheduler.shutdown() | ||
logDebug(s"Stopped watching application $appId with last-observed phase $phase") | ||
} | ||
|
||
private def logShortStatus() = { | ||
logInfo(s"Application status for $appId (phase: $phase)") | ||
} | ||
|
||
private def logLongStatus() = { | ||
logInfo("Phase changed, new state: " + pod.map(formatPodState(_)).getOrElse("unknown")) | ||
} | ||
|
||
private def formatPodState(pod: Pod): String = { | ||
|
||
val details = Seq[(String, String)]( | ||
// pod metadata | ||
("pod name", pod.getMetadata.getName()), | ||
("namespace", pod.getMetadata.getNamespace()), | ||
("labels", pod.getMetadata.getLabels().asScala.mkString(", ")), | ||
("pod uid", pod.getMetadata.getUid), | ||
("creation time", pod.getMetadata.getCreationTimestamp()), | ||
|
||
// spec details | ||
("service account name", pod.getSpec.getServiceAccountName()), | ||
("volumes", pod.getSpec.getVolumes().asScala.map(_.getName).mkString(", ")), | ||
("node name", pod.getSpec.getNodeName()), | ||
|
||
// status | ||
("start time", pod.getStatus.getStartTime), | ||
("container images", | ||
pod.getStatus.getContainerStatuses() | ||
.asScala | ||
.map(_.getImage) | ||
.mkString(", ")), | ||
("phase", pod.getStatus.getPhase()) | ||
) | ||
|
||
// Use more loggable format if value is null or empty | ||
details.map { case (k, v) => | ||
val newValue = Option(v).filter(_.nonEmpty).getOrElse("N/A") | ||
s"\n\t $k: $newValue" | ||
}.mkString("") | ||
} | ||
} |
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.
nit: four-space indentation from the leftmost margin here