HeartSaVioR commented on a change in pull request #23260: [SPARK-26311][CORE] 
New feature: apply custom log URL pattern for executor log URLs in SHS
URL: https://github.com/apache/spark/pull/23260#discussion_r250033325
 
 

 ##########
 File path: 
core/src/main/scala/org/apache/spark/deploy/history/HistoryAppStatusStore.scala
 ##########
 @@ -0,0 +1,123 @@
+/*
+ * 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.history
+
+import scala.util.matching.Regex
+
+import org.apache.spark.SparkConf
+import org.apache.spark.internal.Logging
+import 
org.apache.spark.internal.config.History.{APPLY_CUSTOM_EXECUTOR_LOG_URL_TO_INCOMPLETE_APP,
 CUSTOM_EXECUTOR_LOG_URL}
+import org.apache.spark.status.{AppStatusListener, AppStatusStore}
+import org.apache.spark.status.api.v1
+import org.apache.spark.status.api.v1.ExecutorSummary
+import org.apache.spark.util.kvstore.KVStore
+
+private[spark] class HistoryAppStatusStore(
+    conf: SparkConf,
+    store: KVStore,
+    listener: Option[AppStatusListener] = None)
+  extends AppStatusStore(store, listener) with Logging {
+
+  import HistoryAppStatusStore._
+
+  private val logUrlPattern: Option[String] = conf.get(CUSTOM_EXECUTOR_LOG_URL)
+  private val applyReplaceLogUrlToIncompleteApp: Boolean =
+    conf.get(APPLY_CUSTOM_EXECUTOR_LOG_URL_TO_INCOMPLETE_APP)
+
+  override def executorList(activeOnly: Boolean): Seq[v1.ExecutorSummary] = {
+    val execList = super.executorList(activeOnly)
+    logUrlPattern match {
+      case Some(pattern) =>
+        if (applyReplaceLogUrlToIncompleteApp || isApplicationCompleted) {
+          execList.map(replaceLogUrls(_, pattern))
+        } else {
+          execList
+        }
+
+      case None => execList
+    }
+  }
+
+  override def executorSummary(executorId: String): v1.ExecutorSummary = {
+    val execSummary = super.executorSummary(executorId)
+    logUrlPattern match {
+      case Some(pattern) =>
+        if (applyReplaceLogUrlToIncompleteApp || isApplicationCompleted) {
+          replaceLogUrls(execSummary, pattern)
+        } else {
+          execSummary
+        }
+
+      case None => execSummary
+    }
+  }
+
+  private def isApplicationCompleted: Boolean = {
+    val appInfo = super.applicationInfo()
+    appInfo.attempts.nonEmpty && appInfo.attempts.head.completed
+  }
+
+  private def replaceLogUrls(exec: ExecutorSummary, urlPattern: String): 
ExecutorSummary = {
+    val attributes = exec.attributes
+
+    val allPatterns = 
CUSTOM_URL_PATTERN_REGEX.findAllMatchIn(urlPattern).map(_.group(1)).toSet
+    val allPatternsExceptFileName = allPatterns.filter(_ != "FILE_NAME")
+    val allAttributeKeys = attributes.keySet
+    val allAttributeKeysExceptLogFiles = allAttributeKeys.filter(_ != 
"LOG_FILES")
+
+    if 
(allPatternsExceptFileName.diff(allAttributeKeysExceptLogFiles).nonEmpty) {
+      logFailToRenewLogUrls("some of required attributes are missing in app's 
event log.",
 
 Review comment:
   Totally agreed. Thanks for finding! Maybe we have flag here and show only 
once per instance. It would show up again when SparkUI for application is 
invalidated and recreated, but I don't think it will be noisy.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to