From 2a990beb714f4196dffb62983694b271865333df Mon Sep 17 00:00:00 2001 From: "Wang, Fei" Date: Fri, 2 Aug 2024 00:32:54 -0700 Subject: [PATCH] [KYUUBI #6579] Show kyuubi batch app details on app state change MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # :mag: Description ## Issue References ๐Ÿ”— This pr enhance the kyuubi batch logs for spark on k8s with kyuubi-ctl. ## Describe Your Solution ๐Ÿ”ง For spark on k8s, before, it does not show the app detail info until the log batch command finished. In this PR, it will show the batch app details in app state change. Especially show the app URL info. ## Types of changes :bookmark: - [ ] Bugfix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) ## Test Plan ๐Ÿงช #### Behavior Without This Pull Request :coffin: #### Behavior With This Pull Request :tada: #### Related Unit Tests image --- # Checklist ๐Ÿ“ - [x] This patch was not authored or co-authored using [Generative Tooling](https://www.apache.org/legal/generative-tooling.html) **Be nice. Be informative.** Closes #6579 from turboFei/print_batch_report. Closes #6579 0651dad18 [Wang, Fei] show app details on app state change Authored-by: Wang, Fei Signed-off-by: Wang, Fei --- .../org/apache/kyuubi/ctl/cmd/log/LogBatchCommand.scala | 8 ++++++++ .../main/scala/org/apache/kyuubi/ctl/util/Render.scala | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/cmd/log/LogBatchCommand.scala b/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/cmd/log/LogBatchCommand.scala index f4ce390df..2e3f68b77 100644 --- a/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/cmd/log/LogBatchCommand.scala +++ b/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/cmd/log/LogBatchCommand.scala @@ -20,6 +20,8 @@ import java.util.{Map => JMap} import scala.collection.JavaConverters._ +import org.apache.commons.lang3.StringUtils + import org.apache.kyuubi.client.BatchRestApi import org.apache.kyuubi.client.api.v1.dto.{Batch, OperationLog} import org.apache.kyuubi.client.util.BatchUtils @@ -50,6 +52,7 @@ class LogBatchCommand( var done = false var batch = this.batch.getOrElse(batchRestApi.getBatchById(batchId)) + var appState = this.batch.map(_.getAppState).orNull val kyuubiInstance = batch.getKyuubiInstance withKyuubiInstanceRestClient(kyuubiRestClient, kyuubiInstance) { kyuubiInstanceRestClient => @@ -85,6 +88,11 @@ class LogBatchCommand( Option(batch).foreach { batch => info(s"Application report for ${batch.getAppId} (state: ${batch.getAppState})," + s" batch id: $batchId (state: ${batch.getState})") + if (appState != batch.getAppState && StringUtils.isNotBlank(batch.getAppId)) { + appState = batch.getAppState + val appDetails = Render.buildBatchAppInfo(batch).mkString("\t ", "\n\t ", "") + info(appDetails) + } } } Thread.sleep(conf.get(CTL_BATCH_LOG_QUERY_INTERVAL)) diff --git a/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/util/Render.scala b/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/util/Render.scala index 92db46d88..c2a10e6b8 100644 --- a/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/util/Render.scala +++ b/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/util/Render.scala @@ -122,7 +122,7 @@ private[ctl] object Render { millisToDateString(batch.getEndTime, "yyyy-MM-dd HH:mm:ss")).mkString("\n~\n")) } - private def buildBatchAppInfo(batch: Batch, showDiagnostic: Boolean = true): List[String] = { + def buildBatchAppInfo(batch: Batch, showDiagnostic: Boolean = true): List[String] = { val batchAppInfo = ListBuffer[String]() batch.getBatchInfo.asScala.foreach { case (key, value) => batchAppInfo += s"$key: $value"