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

chengpan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kyuubi.git


The following commit(s) were added to refs/heads/master by this push:
     new b95d2e243 [KYUUBI #5218] Improve logs of KubernetesApplicationOperation
b95d2e243 is described below

commit b95d2e24386ec0c2042fc35825ab18156784ab6d
Author: Cheng Pan <[email protected]>
AuthorDate: Wed Aug 30 19:35:23 2023 +0800

    [KYUUBI #5218] Improve logs of KubernetesApplicationOperation
    
    ### _Why are the changes needed?_
    
    This PR improves the log message of `KubernetesApplicationOperation`, by 
adding `kyuubi-unique-tag=${tag_value}` to each message, which is important for 
analyzing while the thing goes wrong.
    
    ### _How was this patch tested?_
    - [ ] Add some test cases that check the changes thoroughly including 
negative and positive cases if possible
    
    - [ ] Add screenshots for manual tests if appropriate
    
    - [x] [Run 
test](https://kyuubi.readthedocs.io/en/master/contributing/code/testing.html#running-tests)
 locally before make a pull request
    
    ### _Was this patch authored or co-authored using generative AI tooling?_
    
    No
    
    Closes #5218 from pan3793/log-tag.
    
    Closes #5218
    
    263fab9ff [Cheng Pan] revert irrelevant changes
    610738b20 [Cheng Pan] nit
    ad3bf97a5 [Cheng Pan] improve logs
    
    Authored-by: Cheng Pan <[email protected]>
    Signed-off-by: Cheng Pan <[email protected]>
---
 .../engine/KubernetesApplicationOperation.scala    | 33 +++++++++++-----------
 1 file changed, 17 insertions(+), 16 deletions(-)

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 7ddd0366b..c9d509efe 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
@@ -30,7 +30,7 @@ import 
io.fabric8.kubernetes.client.informers.{ResourceEventHandler, SharedIndex
 import org.apache.kyuubi.{KyuubiException, Logging, Utils}
 import org.apache.kyuubi.config.KyuubiConf
 import org.apache.kyuubi.engine.ApplicationState.{isTerminated, 
ApplicationState, FAILED, FINISHED, NOT_FOUND, PENDING, RUNNING, UNKNOWN}
-import 
org.apache.kyuubi.engine.KubernetesApplicationOperation.{toApplicationState, 
LABEL_KYUUBI_UNIQUE_KEY, SPARK_APP_ID_LABEL}
+import 
org.apache.kyuubi.engine.KubernetesApplicationOperation.{toApplicationState, 
toLabel, LABEL_KYUUBI_UNIQUE_KEY, SPARK_APP_ID_LABEL}
 import org.apache.kyuubi.util.KubernetesUtils
 
 class KubernetesApplicationOperation extends ApplicationOperation with Logging 
{
@@ -103,7 +103,7 @@ class KubernetesApplicationOperation extends 
ApplicationOperation with Logging {
       .removalListener((notification: RemovalNotification[String, 
ApplicationState]) => {
         Option(appInfoStore.remove(notification.getKey)).foreach { removed =>
           info(s"Remove terminated application ${removed.id} with " +
-            s"tag ${notification.getKey} and state ${removed.state}")
+            s"[${toLabel(notification.getKey)}, state: ${removed.state}]")
         }
       })
       .build()
@@ -123,35 +123,34 @@ class KubernetesApplicationOperation extends 
ApplicationOperation with Logging {
     }
     val kubernetesInfo = appMgrInfo.kubernetesInfo
     val kubernetesClient = getOrCreateKubernetesClient(kubernetesInfo)
-    debug(s"[$kubernetesInfo] Deleting application info from Kubernetes 
cluster by $tag tag")
+    debug(s"[$kubernetesInfo] Deleting application[${toLabel(tag)}]'s info 
from Kubernetes cluster")
     try {
       Option(appInfoStore.get(tag)) match {
         case Some(info) =>
-          debug(s"Application info[tag: $tag] is in ${info.state}")
+          debug(s"Application[${toLabel(tag)}] is in ${info.state} state")
           info.state match {
             case NOT_FOUND | FAILED | UNKNOWN =>
               (
                 false,
-                s"[$kubernetesInfo] Target application[tag: $tag] is in 
${info.state} status")
+                s"[$kubernetesInfo] Target application[${toLabel(tag)}] is in 
${info.state} state")
             case _ =>
               (
                 !kubernetesClient.pods.withName(info.name).delete().isEmpty,
                 s"[$kubernetesInfo] Operation of deleted" +
-                  s" application[appId: ${info.id} ,tag: $tag] is completed")
+                  s" application[appId: ${info.id}, ${toLabel(tag)}] is 
completed")
           }
         case None =>
-          warn(s"No application info found for tag[$tag]," +
-            s" trying to delete pod with label [$LABEL_KYUUBI_UNIQUE_KEY -> 
$tag]")
+          warn(s"No application info found, trying to delete pod with 
${toLabel(tag)}")
           (
             !kubernetesClient.pods.withLabel(LABEL_KYUUBI_UNIQUE_KEY, 
tag).delete().isEmpty,
-            s"[$kubernetesInfo] Operation of deleted" +
-              s" pod with label [$LABEL_KYUUBI_UNIQUE_KEY -> $tag] is 
completed")
+            s"[$kubernetesInfo] Operation of deleted pod with ${toLabel(tag)} 
is completed")
       }
     } catch {
       case e: Exception =>
         (
           false,
-          s"[$kubernetesInfo] Failed to terminate application with $tag, due 
to ${e.getMessage}")
+          s"[$kubernetesInfo] Failed to terminate 
application[${toLabel(tag)}], " +
+            s"due to ${e.getMessage}")
     }
   }
 
@@ -162,7 +161,7 @@ class KubernetesApplicationOperation extends 
ApplicationOperation with Logging {
     if (kyuubiConf == null) {
       throw new IllegalStateException("Methods initialize and isSupported must 
be called ahead")
     }
-    debug(s"Getting application info from Kubernetes cluster by $tag tag")
+    debug(s"Getting application[${toLabel(tag)}]'s info from Kubernetes 
cluster")
     try {
       // need to initialize the kubernetes client if not exists
       getOrCreateKubernetesClient(appMgrInfo.kubernetesInfo)
@@ -172,23 +171,23 @@ class KubernetesApplicationOperation extends 
ApplicationOperation with Logging {
         case (NOT_FOUND, Some(_submitTime)) =>
           val elapsedTime = System.currentTimeMillis - _submitTime
           if (elapsedTime > submitTimeout) {
-            error(s"Can't find target driver pod by tag: $tag, " +
+            error(s"Can't find target driver pod by ${toLabel(tag)}, " +
               s"elapsed time: ${elapsedTime}ms exceeds ${submitTimeout}ms.")
             ApplicationInfo.NOT_FOUND
           } else {
-            warn("Wait for driver pod to be created, " +
+            warn(s"Waiting for driver pod with ${toLabel(tag)} to be created, 
" +
               s"elapsed time: ${elapsedTime}ms, return UNKNOWN status")
             ApplicationInfo.UNKNOWN
           }
         case (NOT_FOUND, None) =>
           ApplicationInfo.NOT_FOUND
         case _ =>
-          debug(s"Successfully got application info by $tag: $appInfo")
+          debug(s"Successfully got application[${toLabel(tag)}]'s info: 
$appInfo")
           appInfo
       }
     } catch {
       case e: Exception =>
-        error(s"Failed to get application with $tag, due to ${e.getMessage}")
+        error(s"Failed to get application by ${toLabel(tag)}, due to 
${e.getMessage}")
         ApplicationInfo.NOT_FOUND
     }
   }
@@ -271,6 +270,8 @@ object KubernetesApplicationOperation extends Logging {
   val KUBERNETES_SERVICE_HOST = "KUBERNETES_SERVICE_HOST"
   val KUBERNETES_SERVICE_PORT = "KUBERNETES_SERVICE_PORT"
 
+  def toLabel(tag: String): String = s"label: $LABEL_KYUUBI_UNIQUE_KEY=$tag"
+
   def toApplicationState(state: String): ApplicationState = state match {
     // 
https://github.com/kubernetes/kubernetes/blob/master/pkg/apis/core/types.go#L2396
     // https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/

Reply via email to