-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-53335][K8S] Support spark.kubernetes.driver.annotateExitException
#52068
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
Closed
ForVic
wants to merge
8
commits into
apache:master
from
ForVic:vsunderl/better_kubernetes_diagnostics
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
782d37d
Capture the stack trace from failed K8s jobs, and set it in the annot…
b2b0c8b
address review comments
victors-oai 0b7abd8
fix compile errors
victors-oai 1dcc991
initial round of review comments
victors-oai df2f6ce
Use a string conf, and some style
victors-oai e1509eb
Rename the config to exit exception
victors-oai 1a394f0
Another round of review comments
victors-oai 8060376
fix CI
victors-oai 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 hidden or 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
18 changes: 18 additions & 0 deletions
18
.../core/src/main/resources/META-INF/services/org.apache.spark.deploy.SparkDiagnosticsSetter
This file contains hidden or 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,18 @@ | ||
| # | ||
| # 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. | ||
| # | ||
|
|
||
| org.apache.spark.deploy.k8s.SparkKubernetesDiagnosticsSetter |
This file contains hidden or 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 hidden or 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
80 changes: 80 additions & 0 deletions
80
...es/core/src/main/scala/org/apache/spark/deploy/k8s/SparkKubernetesDiagnosticsSetter.scala
This file contains hidden or 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,80 @@ | ||
| /* | ||
| * 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.k8s | ||
|
|
||
| import io.fabric8.kubernetes.api.model.{Pod, PodBuilder} | ||
| import io.fabric8.kubernetes.client.KubernetesClient | ||
| import org.apache.hadoop.util.StringUtils | ||
|
|
||
| import org.apache.spark.SparkConf | ||
| import org.apache.spark.deploy.SparkDiagnosticsSetter | ||
| import org.apache.spark.deploy.k8s.Config._ | ||
| import org.apache.spark.deploy.k8s.Constants.EXIT_EXCEPTION_ANNOTATION | ||
| import org.apache.spark.deploy.k8s.SparkKubernetesClientFactory.ClientType | ||
| import org.apache.spark.internal.Logging | ||
| import org.apache.spark.util.{SparkStringUtils, Utils} | ||
|
|
||
| /** | ||
| * We use this trait and its implementation to allow for mocking the static | ||
| * client creation in tests. | ||
| */ | ||
| private[spark] trait KubernetesClientProvider { | ||
| def create(conf: SparkConf): KubernetesClient | ||
| } | ||
|
|
||
| private[spark] class DefaultKubernetesClientProvider extends KubernetesClientProvider { | ||
| override def create(conf: SparkConf): KubernetesClient = { | ||
| SparkKubernetesClientFactory.createKubernetesClient( | ||
| conf.get(KUBERNETES_DRIVER_MASTER_URL), | ||
| Option(conf.get(KUBERNETES_NAMESPACE)), | ||
| KUBERNETES_AUTH_DRIVER_MOUNTED_CONF_PREFIX, | ||
| ClientType.Driver, | ||
| conf, | ||
| None) | ||
| } | ||
| } | ||
|
|
||
| private[spark] class SparkKubernetesDiagnosticsSetter(clientProvider: KubernetesClientProvider) | ||
| extends SparkDiagnosticsSetter with Logging { | ||
|
|
||
| private val KUBERNETES_EXIT_EXCEPTION_MESSAGE_LIMIT_BYTES = 64 * 1024 // 64 KiB | ||
|
|
||
| def this() = { | ||
| this(new DefaultKubernetesClientProvider) | ||
| } | ||
|
|
||
| override def setDiagnostics(throwable: Throwable, conf: SparkConf): Unit = { | ||
| val diagnostics = SparkStringUtils.abbreviate(StringUtils.stringifyException(throwable), | ||
| KUBERNETES_EXIT_EXCEPTION_MESSAGE_LIMIT_BYTES) | ||
| Utils.tryWithResource(clientProvider.create(conf)) { client => | ||
| conf.get(KUBERNETES_DRIVER_POD_NAME).foreach { podName => | ||
| client.pods() | ||
| .inNamespace(conf.get(KUBERNETES_NAMESPACE)) | ||
| .withName(podName) | ||
| .edit((p: Pod) => new PodBuilder(p) | ||
| .editOrNewMetadata() | ||
| .addToAnnotations(EXIT_EXCEPTION_ANNOTATION, diagnostics) | ||
| .endMetadata() | ||
| .build()); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| override def supports(clusterManagerUrl: String): Boolean = { | ||
| clusterManagerUrl.startsWith("k8s://") | ||
| } | ||
| } |
89 changes: 89 additions & 0 deletions
89
...re/src/test/scala/org/apache/spark/deploy/k8s/SparkKubernetesDiagnosticsSetterSuite.scala
This file contains hidden or 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,89 @@ | ||
| /* | ||
| * 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.k8s | ||
|
|
||
| import java.util.function.UnaryOperator | ||
|
|
||
| import io.fabric8.kubernetes.api.model.Pod | ||
| import io.fabric8.kubernetes.client.KubernetesClient | ||
| import io.fabric8.kubernetes.client.dsl.PodResource | ||
| import org.apache.hadoop.util.StringUtils | ||
| import org.mockito.{ArgumentCaptor, Mock, MockitoAnnotations} | ||
| import org.mockito.ArgumentMatchers.any | ||
| import org.mockito.Mockito._ | ||
| import org.scalatest.BeforeAndAfterEach | ||
| import org.scalatestplus.mockito.MockitoSugar | ||
|
|
||
| import org.apache.spark.{SparkConf, SparkFunSuite} | ||
| import org.apache.spark.deploy.k8s.Config._ | ||
| import org.apache.spark.deploy.k8s.Constants.EXIT_EXCEPTION_ANNOTATION | ||
| import org.apache.spark.deploy.k8s.Fabric8Aliases.PODS | ||
|
|
||
| class SparkKubernetesDiagnosticsSetterSuite extends SparkFunSuite | ||
| with MockitoSugar with BeforeAndAfterEach { | ||
|
|
||
| @Mock | ||
| private var client: KubernetesClient = _ | ||
| @Mock | ||
| private var clientProvider: KubernetesClientProvider = _ | ||
| @Mock | ||
| private var podOperations: PODS = _ | ||
| @Mock | ||
| private var driverPodOperations: PodResource = _ | ||
|
|
||
| private val driverPodName: String = "driver-pod" | ||
| private val k8sClusterManagerUrl: String = "k8s://dummy" | ||
| private val namespace: String = "default" | ||
|
|
||
| private var setter: SparkKubernetesDiagnosticsSetter = _ | ||
|
|
||
| override def beforeEach(): Unit = { | ||
| MockitoAnnotations.openMocks(this) | ||
| when(client.pods()).thenReturn(podOperations) | ||
| when(podOperations.inNamespace(namespace)).thenReturn(podOperations) | ||
| when(podOperations.withName(driverPodName)).thenReturn(driverPodOperations) | ||
| when(clientProvider.create(any(classOf[SparkConf]))).thenReturn(client) | ||
| setter = new SparkKubernetesDiagnosticsSetter(clientProvider) | ||
| } | ||
|
|
||
| test("supports() should return true only for k8s:// URLs") { | ||
| assert(setter.supports(k8sClusterManagerUrl)) | ||
| assert(!setter.supports("yarn")) | ||
| assert(!setter.supports("spark://localhost")) | ||
| } | ||
|
|
||
| test("setDiagnostics should patch pod with diagnostics annotation") { | ||
| val diagnostics = new Throwable("Fake diagnostics stack trace") | ||
| val conf = new SparkConf() | ||
| .set(KUBERNETES_DRIVER_MASTER_URL, k8sClusterManagerUrl) | ||
| .set(KUBERNETES_NAMESPACE, namespace) | ||
| .set(KUBERNETES_DRIVER_POD_NAME, driverPodName) | ||
|
|
||
| setter.setDiagnostics(diagnostics, conf) | ||
|
|
||
| val captor: ArgumentCaptor[UnaryOperator[Pod]] = | ||
| ArgumentCaptor.forClass(classOf[UnaryOperator[Pod]]) | ||
| verify(driverPodOperations).edit(captor.capture()) | ||
|
|
||
| val fn = captor.getValue | ||
| val initialPod = SparkPod.initialPod().pod | ||
| val editedPod = fn.apply(initialPod) | ||
|
|
||
| assert(editedPod.getMetadata.getAnnotations.get(EXIT_EXCEPTION_ANNOTATION) | ||
| == StringUtils.stringifyException(diagnostics)) | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.