Skip to content

Commit 584b6db

Browse files
committed
[SPARK-49190][K8S] Add SPARK_EXECUTOR_ATTRIBUTE_(APP|EXECUTOR)_ID if CUSTOM_EXECUTOR_LOG_URL is defined
### What changes were proposed in this pull request? This PR aims to add `SPARK_EXECUTOR_ATTRIBUTE_(APP|EXECUTOR)_ID` if `CUSTOM_EXECUTOR_LOG_URL` is defined. ### Why are the changes needed? Apache Spark has been supported `spark.ui.custom.executor.log.url` in K8s environment well. - #47681 This PR aims to help users use it more easily by providing the required `SPARK_EXECUTOR_ATTRIBUTE_APP_ID` and `SPARK_EXECUTOR_ATTRIBUTE_EXECUTOR_ID` automatically if `spark.ui.custom.executor.log.url` is defined. ### Does this PR introduce _any_ user-facing change? - No by default because `spark.ui.custom.executor.log.url` is not used. - When `spark.ui.custom.executor.log.url` is used, - For YARN users, there is no change for YARN users because this is K8s only change. - For K8s users, this will reduce the existing steps by providing the same environment variables. In addition, the user variables always overwrite this built-in environment variables by design. ### How was this patch tested? No. ### Was this patch authored or co-authored using generative AI tooling? No. Closes #47692 from dongjoon-hyun/SPARK-49190. Authored-by: Dongjoon Hyun <dhyun@apple.com> Signed-off-by: Dongjoon Hyun <dhyun@apple.com>
1 parent eb859de commit 584b6db

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

docs/running-on-kubernetes.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,6 @@ the cluster.
433433
When there exists a log collection system, you can expose it at Spark Driver `Executors` tab UI. For example,
434434

435435
```
436-
spark.executorEnv.SPARK_EXECUTOR_ATTRIBUTE_APP_ID='$(SPARK_APPLICATION_ID)'
437-
spark.executorEnv.SPARK_EXECUTOR_ATTRIBUTE_EXECUTOR_ID='$(SPARK_EXECUTOR_ID)'
438436
spark.ui.custom.executor.log.url='https://log-server/log?appId={{APP_ID}}&execId={{EXECUTOR_ID}}'
439437
```
440438

resource-managers/kubernetes/core/src/main/scala/org/apache/spark/deploy/k8s/Constants.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ object Constants {
7272
val ENV_EXECUTOR_ID = "SPARK_EXECUTOR_ID"
7373
val ENV_EXECUTOR_POD_IP = "SPARK_EXECUTOR_POD_IP"
7474
val ENV_EXECUTOR_POD_NAME = "SPARK_EXECUTOR_POD_NAME"
75+
val ENV_EXECUTOR_ATTRIBUTE_APP_ID = "SPARK_EXECUTOR_ATTRIBUTE_APP_ID"
76+
val ENV_EXECUTOR_ATTRIBUTE_EXECUTOR_ID = "SPARK_EXECUTOR_ATTRIBUTE_EXECUTOR_ID"
7577
val ENV_JAVA_OPT_PREFIX = "SPARK_JAVA_OPT_"
7678
val ENV_CLASSPATH = "SPARK_CLASSPATH"
7779
val ENV_DRIVER_BIND_ADDRESS = "SPARK_DRIVER_BIND_ADDRESS"

resource-managers/kubernetes/core/src/main/scala/org/apache/spark/deploy/k8s/features/BasicExecutorFeatureStep.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,14 @@ private[spark] class BasicExecutorFeatureStep(
143143
(s"$ENV_JAVA_OPT_PREFIX$index", opt)
144144
}.toMap
145145

146+
val attributes = if (kubernetesConf.get(UI.CUSTOM_EXECUTOR_LOG_URL).isDefined) {
147+
Map(
148+
ENV_EXECUTOR_ATTRIBUTE_APP_ID -> kubernetesConf.appId,
149+
ENV_EXECUTOR_ATTRIBUTE_EXECUTOR_ID -> kubernetesConf.executorId)
150+
} else {
151+
Map.empty[String, String]
152+
}
153+
146154
KubernetesUtils.buildEnvVars(
147155
Seq(
148156
ENV_DRIVER_URL -> driverUrl,
@@ -153,6 +161,7 @@ private[spark] class BasicExecutorFeatureStep(
153161
ENV_SPARK_CONF_DIR -> SPARK_CONF_DIR_INTERNAL,
154162
ENV_EXECUTOR_ID -> kubernetesConf.executorId,
155163
ENV_RESOURCE_PROFILE_ID -> resourceProfile.id.toString)
164+
++ attributes
156165
++ kubernetesConf.environment
157166
++ sparkAuthSecret
158167
++ Seq(ENV_CLASSPATH -> kubernetesConf.get(EXECUTOR_CLASS_PATH).orNull)

resource-managers/kubernetes/core/src/test/scala/org/apache/spark/deploy/k8s/features/BasicExecutorFeatureStepSuite.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,18 @@ class BasicExecutorFeatureStepSuite extends SparkFunSuite with BeforeAndAfter {
252252
s"/p1/${KubernetesTestConf.APP_ID}/1,/p2/${KubernetesTestConf.APP_ID}/1"))
253253
}
254254

255+
test("SPARK-49190: Add SPARK_EXECUTOR_ATTRIBUTE_(APP|EXECUTOR)_ID if CUSTOM_EXECUTOR_LOG_URL" +
256+
" is defined") {
257+
val conf = baseConf.clone()
258+
.set(UI.CUSTOM_EXECUTOR_LOG_URL, "https://custom-executor-log-server/")
259+
val kconf = KubernetesTestConf.createExecutorConf(sparkConf = conf)
260+
val step = new BasicExecutorFeatureStep(kconf, new SecurityManager(conf), defaultProfile)
261+
val executor = step.configurePod(SparkPod.initialPod())
262+
checkEnv(executor, conf, Map(
263+
ENV_EXECUTOR_ATTRIBUTE_APP_ID -> KubernetesTestConf.APP_ID,
264+
ENV_EXECUTOR_ATTRIBUTE_EXECUTOR_ID -> KubernetesTestConf.EXECUTOR_ID))
265+
}
266+
255267
test("test executor pyspark memory") {
256268
baseConf.set("spark.kubernetes.resource.type", "python")
257269
baseConf.set(PYSPARK_EXECUTOR_MEMORY, 42L)

0 commit comments

Comments
 (0)