squito 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_r249841142
 
 

 ##########
 File path: 
resource-managers/yarn/src/main/scala/org/apache/spark/scheduler/cluster/YarnClusterSchedulerBackend.scala
 ##########
 @@ -64,4 +66,42 @@ private[spark] class YarnClusterSchedulerBackend(
     }
     driverLogs
   }
+
+  override def getDriverAttributes: Option[Map[String, String]] = {
+    var attributes: Option[Map[String, String]] = None
+    try {
+      val yarnConf = new YarnConfiguration(sc.hadoopConfiguration)
+      val containerId = YarnSparkHadoopUtil.getContainerId
+      val clusterId: Option[String] = try {
+        Some(YarnConfiguration.getClusterId(yarnConf))
+      } catch {
+        case _: HadoopIllegalArgumentException => None
+      }
+
+      val httpAddress = System.getenv(Environment.NM_HOST.name()) +
+        ":" + System.getenv(Environment.NM_HTTP_PORT.name())
+
+      // lookup appropriate http scheme for container log urls
+      val yarnHttpPolicy = yarnConf.get(
+        YarnConfiguration.YARN_HTTP_POLICY_KEY,
+        YarnConfiguration.YARN_HTTP_POLICY_DEFAULT
+      )
+      val user = Utils.getCurrentUserName()
+      val httpScheme = if (yarnHttpPolicy == "HTTPS_ONLY") "https://"; else 
"http://";
+
+      attributes = Some(Map(
+        "HTTP_SCHEME" -> httpScheme,
+        "NODE_HTTP_ADDRESS" -> httpAddress,
+        "CLUSTER_ID" -> clusterId.getOrElse(""),
+        "CONTAINER_ID" -> ConverterUtils.toString(containerId),
+        "USER" -> user,
+        "LOG_FILES" -> "stderr,stdout"
+      ))
+    } catch {
+      case e: Exception =>
+        logInfo("Error while retrieving attributes on driver, so driver logs 
will not " +
+          "be replaced with custom log pattern", e)
+    }
+    attributes
 
 Review comment:
   you can avoid the `var` here by just having the final expression be the 
result at the end of the try and the catch:
   
   ```scala
   try {
     ...
     Some(Map(
       ...
     ))
   } catch {
     case e: Exception =>
      logInfo(...)
      None
   }
   ```

----------------------------------------------------------------
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