This is an automated email from the ASF dual-hosted git repository.

feiwang pushed a commit to branch branch-1.10
in repository https://gitbox.apache.org/repos/asf/kyuubi.git


The following commit(s) were added to refs/heads/branch-1.10 by this push:
     new a326ba78c4 [KYUUBI #7034] [KUBERNETES] Prefer to use pod 
`spark-app-name` label as application name than pod name
a326ba78c4 is described below

commit a326ba78c42825ffe347e8d5ebe48908a830384f
Author: Wang, Fei <fwan...@ebay.com>
AuthorDate: Wed Apr 16 19:28:04 2025 -0700

    [KYUUBI #7034] [KUBERNETES] Prefer to use pod `spark-app-name` label as 
application name than pod name
    
    ### Why are the changes needed?
    
    After https://github.com/apache/spark/pull/34460 (Since Spark 3.3.0), the 
`spark-app-name` is available.
    
    We shall use it as the application name if it exists.
    
    ### How was this patch tested?
    
    Minor change.
    ### Was this patch authored or co-authored using generative AI tooling?
    
    No.
    
    Closes #7034 from turboFei/k8s_app_name.
    
    Closes #7034
    
    bfa88a436 [Wang, Fei] Get pod app name
    
    Authored-by: Wang, Fei <fwan...@ebay.com>
    Signed-off-by: Wang, Fei <fwan...@ebay.com>
    (cherry picked from commit cc68cb4c852dccd920ba53a4d853aa407ff83faa)
    Signed-off-by: Wang, Fei <fwan...@ebay.com>
---
 .../engine/KubernetesApplicationAuditLogger.scala     |  5 +++--
 .../engine/KubernetesApplicationOperation.scala       | 19 ++++++++++++++-----
 2 files changed, 17 insertions(+), 7 deletions(-)

diff --git 
a/kyuubi-server/src/main/scala/org/apache/kyuubi/engine/KubernetesApplicationAuditLogger.scala
 
b/kyuubi-server/src/main/scala/org/apache/kyuubi/engine/KubernetesApplicationAuditLogger.scala
index ff3d51245d..cc34e4a89d 100644
--- 
a/kyuubi-server/src/main/scala/org/apache/kyuubi/engine/KubernetesApplicationAuditLogger.scala
+++ 
b/kyuubi-server/src/main/scala/org/apache/kyuubi/engine/KubernetesApplicationAuditLogger.scala
@@ -23,7 +23,7 @@ import io.fabric8.kubernetes.api.model.Pod
 
 import org.apache.kyuubi.Logging
 import 
org.apache.kyuubi.config.KyuubiConf.KubernetesApplicationStateSource.KubernetesApplicationStateSource
-import 
org.apache.kyuubi.engine.KubernetesApplicationOperation.{toApplicationStateAndError,
 LABEL_KYUUBI_UNIQUE_KEY, SPARK_APP_ID_LABEL}
+import org.apache.kyuubi.engine.KubernetesApplicationOperation.{getPodAppId, 
getPodAppName, toApplicationStateAndError, LABEL_KYUUBI_UNIQUE_KEY}
 import 
org.apache.kyuubi.engine.KubernetesResourceEventTypes.KubernetesResourceEventType
 
 object KubernetesApplicationAuditLogger extends Logging {
@@ -49,7 +49,8 @@ object KubernetesApplicationAuditLogger extends Logging {
       s"${containerState.getName}->${containerState.getState}"
     }.mkString("[", ",", "]")
     sb.append(s"containers=$containerStatuses").append("\t")
-    
sb.append(s"appId=${pod.getMetadata.getLabels.get(SPARK_APP_ID_LABEL)}").append("\t")
+    sb.append(s"appId=${getPodAppId(pod)}").append("\t")
+    sb.append(s"appName=${getPodAppName(pod)}").append("\t")
     val (appState, appError) =
       toApplicationStateAndError(pod, appStateSource, appStateContainer, 
eventType)
     sb.append(s"appState=$appState").append("\t")
diff --git 
a/kyuubi-server/src/main/scala/org/apache/kyuubi/engine/KubernetesApplicationOperation.scala
 
b/kyuubi-server/src/main/scala/org/apache/kyuubi/engine/KubernetesApplicationOperation.scala
index 2e57c722f4..8981c1f687 100644
--- 
a/kyuubi-server/src/main/scala/org/apache/kyuubi/engine/KubernetesApplicationOperation.scala
+++ 
b/kyuubi-server/src/main/scala/org/apache/kyuubi/engine/KubernetesApplicationOperation.scala
@@ -408,16 +408,16 @@ class KubernetesApplicationOperation extends 
ApplicationOperation with Logging {
         appInfoStore.put(
           kyuubiUniqueKey,
           kubernetesInfo -> appInfo.copy(
-            id = pod.getMetadata.getLabels.get(SPARK_APP_ID_LABEL),
-            name = pod.getMetadata.getName,
+            id = getPodAppId(pod),
+            name = getPodAppName(pod),
             state = appState,
             error = appError))
       }.getOrElse {
         appInfoStore.put(
           kyuubiUniqueKey,
           kubernetesInfo -> ApplicationInfo(
-            id = pod.getMetadata.getLabels.get(SPARK_APP_ID_LABEL),
-            name = pod.getMetadata.getName,
+            id = getPodAppId(pod),
+            name = getPodAppName(pod),
             state = appState,
             error = appError))
       }
@@ -506,7 +506,8 @@ class KubernetesApplicationOperation extends 
ApplicationOperation with Logging {
 
 object KubernetesApplicationOperation extends Logging {
   val LABEL_KYUUBI_UNIQUE_KEY = "kyuubi-unique-tag"
-  val SPARK_APP_ID_LABEL = "spark-app-selector"
+  private val SPARK_APP_ID_LABEL = "spark-app-selector"
+  private val SPARK_APP_NAME_LABEL = "spark-app-name"
   val KUBERNETES_SERVICE_HOST = "KUBERNETES_SERVICE_HOST"
   val KUBERNETES_SERVICE_PORT = "KUBERNETES_SERVICE_PORT"
   val SPARK_UI_PORT_NAME = "spark-ui"
@@ -634,4 +635,12 @@ object KubernetesApplicationOperation extends Logging {
       .replace("{{KUBERNETES_NAMESPACE}}", kubernetesNamespace)
       .replace("{{SPARK_UI_PORT}}", sparkUiPort.toString)
   }
+
+  def getPodAppId(pod: Pod): String = {
+    pod.getMetadata.getLabels.get(SPARK_APP_ID_LABEL)
+  }
+
+  def getPodAppName(pod: Pod): String = {
+    
Option(pod.getMetadata.getLabels.get(SPARK_APP_NAME_LABEL)).getOrElse(pod.getMetadata.getName)
+  }
 }

Reply via email to