You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "zeotuan (via GitHub)" <gi...@apache.org> on 2024/05/03 09:12:21 UTC

[PR] [SPARK-47240][CORE][PART1] Migrate logInfo with variables to structured logging framework [spark]

zeotuan opened a new pull request, #46362:
URL: https://github.com/apache/spark/pull/46362

   <!--
   Thanks for sending a pull request!  Here are some tips for you:
     1. If this is your first time, please read our contributor guidelines: https://spark.apache.org/contributing.html
     2. Ensure you have added or run the appropriate tests for your PR: https://spark.apache.org/developer-tools.html
     3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][SPARK-XXXX] Your PR title ...'.
     4. Be sure to keep the PR description updated to reflect all changes.
     5. Please write your PR title to summarize what this PR proposes.
     6. If possible, provide a concise example to reproduce the issue for a faster review.
     7. If you want to add a new configuration, please read the guideline first for naming configurations in
        'core/src/main/scala/org/apache/spark/internal/config/ConfigEntry.scala'.
     8. If you want to add or modify an error type or message, please read the guideline first in
        'common/utils/src/main/resources/error/README.md'.
   -->
   The PR aims to migrate `logInfo` in Core module with variables to structured logging framework.
   
   ### Why are the changes needed?
   <!--
   Please clarify why the changes are needed. For instance,
     1. If you propose a new API, clarify the use case for a new API.
     2. If you fix a bug, you can clarify why it is a bug.
   -->
   To enhance Apache Spark's logging system by implementing structured logging.
   
   ### Does this PR introduce _any_ user-facing change?
   <!--
   Note that it means *any* user-facing change including all aspects such as the documentation fix.
   If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
   If possible, please also clarify if this is a user-facing change compared to the released Spark versions or within the unreleased branches such as master.
   If no, write 'No'.
   -->
   No.
   
   
   ### How was this patch tested?
   <!--
   If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
   If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
   If tests were not added, please describe why they were not added and/or why it was difficult to add.
   If benchmark tests were added, please run the benchmarks in GitHub Actions for the consistent environment, and the instructions could accord to: https://spark.apache.org/developer-tools.html#github-workflow-benchmarks.
   -->
   - Pass GA.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   <!--
   If generative AI tooling has been used in the process of authoring this patch, please include the
   phrase: 'Generated-by: ' followed by the name of the tool and its version.
   If no, write 'No'.
   Please refer to the [ASF Generative Tooling Guidance](https://www.apache.org/legal/generative-tooling.html) for details.
   -->
   No.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-47240][CORE][PART1] Migrate logInfo with variables to structured logging framework [spark]

Posted by "gengliangwang (via GitHub)" <gi...@apache.org>.
gengliangwang commented on code in PR #46362:
URL: https://github.com/apache/spark/pull/46362#discussion_r1591871165


##########
core/src/main/scala/org/apache/spark/deploy/FaultToleranceTest.scala:
##########
@@ -187,7 +188,7 @@ private object FaultToleranceTest extends App with Logging {
       fn
       numPassed += 1
       logInfo("==============================================")
-      logInfo("Passed: " + name)
+      logInfo(log"Passed: ${MDC(TEST_NAME, name)}")

Review Comment:
   We don't need to migrate the log entries from tests. Let's revert the changes in this file to avoid introducing new log keys.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-47240][CORE][PART1] Migrate logInfo with variables to structured logging framework [spark]

Posted by "gengliangwang (via GitHub)" <gi...@apache.org>.
gengliangwang commented on code in PR #46362:
URL: https://github.com/apache/spark/pull/46362#discussion_r1591663918


##########
core/src/main/scala/org/apache/spark/MapOutputTracker.scala:
##########
@@ -489,21 +488,24 @@ private[spark] class MapOutputTrackerMasterEndpoint(
   extends RpcEndpoint with Logging {
 
   logDebug("init") // force eager creation of logger
+  private def logInfoMsg(msg: MessageWithContext, shuffleId: Int, context: RpcCallContext): Unit = {

Review Comment:
   nit: add a blank line



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-47240][CORE][PART1] Migrate logInfo with variables to structured logging framework [spark]

Posted by "gengliangwang (via GitHub)" <gi...@apache.org>.
gengliangwang commented on PR #46362:
URL: https://github.com/apache/spark/pull/46362#issuecomment-2099352057

   @zeotuan FYI I pushed a commit https://github.com/apache/spark/pull/46362/commits/b45b340d93ff6c6a972e255ee5325ce1b1c7d226 to reduce a log key. Please help review it and let me know what you think of it.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-47240][CORE][PART1] Migrate logInfo with variables to structured logging framework [spark]

Posted by "zeotuan (via GitHub)" <gi...@apache.org>.
zeotuan commented on PR #46362:
URL: https://github.com/apache/spark/pull/46362#issuecomment-2099461633

   @gengliangwang Thank you, LGTM!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-47240][CORE][PART1] Migrate logInfo with variables to structured logging framework [spark]

Posted by "gengliangwang (via GitHub)" <gi...@apache.org>.
gengliangwang commented on PR #46362:
URL: https://github.com/apache/spark/pull/46362#issuecomment-2097081527

   > I was just wondering if there is any plan to fix/apply all these scalafmt changes or why would it produce such different result.
   
   There has been such discussions. The major concern of not having such a format tool is to avoid making the git blame harder.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-47240][CORE][PART1] Migrate logInfo with variables to structured logging framework [spark]

Posted by "gengliangwang (via GitHub)" <gi...@apache.org>.
gengliangwang closed pull request #46362: [SPARK-47240][CORE][PART1] Migrate logInfo with variables to structured logging framework
URL: https://github.com/apache/spark/pull/46362


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-47240][CORE][PART1] Migrate logInfo with variables to structured logging framework [spark]

Posted by "zeotuan (via GitHub)" <gi...@apache.org>.
zeotuan commented on PR #46362:
URL: https://github.com/apache/spark/pull/46362#issuecomment-2097065571

   > @zeotuan Thanks for the work. However, there are a lot of unnecessary changes in this PR, which are probably from scalafmt. This makes the PR review hard. Usually, Spark PRs require cleaner code changes. Could you revert to [c9e0209](https://github.com/apache/spark/commit/c9e020926f562e3205598396bec7f2071030a2cd)? You will have to fix the errors from `./dev/lint-scala` manually.
   
   Sure I will revert it. I was just wondering if there is any plan to fix/apply all these scalafmt changes or why would it produce such different result.
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-47240][CORE][PART1] Migrate logInfo with variables to structured logging framework [spark]

Posted by "gengliangwang (via GitHub)" <gi...@apache.org>.
gengliangwang commented on PR #46362:
URL: https://github.com/apache/spark/pull/46362#issuecomment-2096574657

   @zeotuan Thanks for the work. However, there are a lot of unnecessary changes in this PR, which are probably from scalafmt. This makes the PR review hard. 
   Usually, Spark PRs require cleaner code changes. Could you revert to https://github.com/apache/spark/pull/46362/commits/c9e020926f562e3205598396bec7f2071030a2cd? You will have to fix the errors from `./dev/lint-scala` manually.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-47240][CORE][PART1] Migrate logInfo with variables to structured logging framework [spark]

Posted by "gengliangwang (via GitHub)" <gi...@apache.org>.
gengliangwang commented on code in PR #46362:
URL: https://github.com/apache/spark/pull/46362#discussion_r1591860394


##########
core/src/main/scala/org/apache/spark/SparkContext.scala:
##########
@@ -1855,7 +1859,9 @@ class SparkContext(config: SparkConf) extends Logging {
         root,
         if (uri.getFragment != null) uri.getFragment else source.getName)
       logInfo(
-        s"Unpacking an archive $path from ${source.getAbsolutePath} to ${dest.getAbsolutePath}")
+        log"Unpacking an archive ${MDC(LogKeys.PATH, path)}" +
+          log" from ${MDC(LogKeys.SOURCE_ABSOLUTE_PATH, source.getAbsolutePath)}" +

Review Comment:
   nit: how about simply `SOURCE_PATH`



##########
core/src/main/scala/org/apache/spark/SparkContext.scala:
##########
@@ -1855,7 +1859,9 @@ class SparkContext(config: SparkConf) extends Logging {
         root,
         if (uri.getFragment != null) uri.getFragment else source.getName)
       logInfo(
-        s"Unpacking an archive $path from ${source.getAbsolutePath} to ${dest.getAbsolutePath}")
+        log"Unpacking an archive ${MDC(LogKeys.PATH, path)}" +
+          log" from ${MDC(LogKeys.SOURCE_ABSOLUTE_PATH, source.getAbsolutePath)}" +
+          log" to ${MDC(LogKeys.DESTINATION_ABSOLUTE_PATH, dest.getAbsolutePath)}")

Review Comment:
   nit: how about simply `DESTINATION_PATH`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-47240][CORE][PART1] Migrate logInfo with variables to structured logging framework [spark]

Posted by "gengliangwang (via GitHub)" <gi...@apache.org>.
gengliangwang commented on PR #46362:
URL: https://github.com/apache/spark/pull/46362#issuecomment-2099522988

   Thanks, merging to master


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-47240][CORE][PART1] Migrate logInfo with variables to structured logging framework [spark]

Posted by "gengliangwang (via GitHub)" <gi...@apache.org>.
gengliangwang commented on code in PR #46362:
URL: https://github.com/apache/spark/pull/46362#discussion_r1591645132


##########
core/src/main/scala/org/apache/spark/BarrierTaskContext.scala:
##########
@@ -56,19 +57,27 @@ class BarrierTaskContext private[spark] (
   // with the driver side epoch.
   private var barrierEpoch = 0
 
+  private def logProgressInfo(msg: MessageWithContext, startTime: Option[Long]): Unit = {
+    val waitMsg = startTime.fold(log"")(st => log", waited " +
+      log"for ${MDC(TOTAL_TIME, System.currentTimeMillis() - st)} ms,")
+    logInfo(log"Task ${MDC(TASK_ATTEMPT_ID, taskAttemptId())}" +
+          log" from Stage ${MDC(STAGE_ID, stageId())}" +

Review Comment:
   nit: two spaces indent



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-47240][CORE][PART1] Migrate logInfo with variables to structured logging framework [spark]

Posted by "gengliangwang (via GitHub)" <gi...@apache.org>.
gengliangwang commented on code in PR #46362:
URL: https://github.com/apache/spark/pull/46362#discussion_r1591342894


##########
core/src/main/scala/org/apache/spark/BarrierCoordinator.scala:
##########
@@ -39,16 +40,18 @@ private case class ContextBarrierId(stageId: Int, stageAttemptId: Int) {
 
 /**
  * A coordinator that handles all global sync requests from BarrierTaskContext. Each global sync
- * request is generated by `BarrierTaskContext.barrier()`, and identified by
- * stageId + stageAttemptId + barrierEpoch. Reply all the blocking global sync requests upon
- * all the requests for a group of `barrier()` calls are received. If the coordinator is unable to
- * collect enough global sync requests within a configured time, fail all the requests and return
- * an Exception with timeout message.
+ * request is generated by `BarrierTaskContext.barrier()`, and identified by stageId +

Review Comment:
   Please remove unnecessary changes



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-47240][CORE][PART1] Migrate logInfo with variables to structured logging framework [spark]

Posted by "gengliangwang (via GitHub)" <gi...@apache.org>.
gengliangwang commented on code in PR #46362:
URL: https://github.com/apache/spark/pull/46362#discussion_r1591870856


##########
repl/src/test/scala/org/apache/spark/repl/SparkShellSuite.scala:
##########
@@ -26,6 +26,8 @@ import scala.concurrent.duration._
 
 import org.apache.spark.ProcessTestUtils.ProcessOutputCapturer
 import org.apache.spark.SparkFunSuite
+import org.apache.spark.internal.{MDC, MessageWithContext}

Review Comment:
   We don't need to migrate the log entries from tests.  Let's revert the changes in this file to avoid introducing new log keys.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-47240][CORE][PART1] Migrate logInfo with variables to structured logging framework [spark]

Posted by "gengliangwang (via GitHub)" <gi...@apache.org>.
gengliangwang commented on PR #46362:
URL: https://github.com/apache/spark/pull/46362#issuecomment-2097536320

   LGTM otherwise. Thanks for the good work!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-47240][CORE][PART1] Migrate logInfo with variables to structured logging framework [spark]

Posted by "zeotuan (via GitHub)" <gi...@apache.org>.
zeotuan commented on code in PR #46362:
URL: https://github.com/apache/spark/pull/46362#discussion_r1590481881


##########
common/utils/src/main/scala/org/apache/spark/internal/LogKey.scala:
##########
@@ -26,13 +26,16 @@ trait LogKey {
 }
 
 /**
- * Various keys used for mapped diagnostic contexts(MDC) in logging.
- * All structured logging keys should be defined here for standardization.
+ * Various keys used for mapped diagnostic contexts(MDC) in logging. All structured logging keys

Review Comment:
   Many of these formatting changes happened as the result of running dev/scalafmt. Should we keep them? 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-47240][CORE][PART1] Migrate logInfo with variables to structured logging framework [spark]

Posted by "zeotuan (via GitHub)" <gi...@apache.org>.
zeotuan commented on code in PR #46362:
URL: https://github.com/apache/spark/pull/46362#discussion_r1590481881


##########
common/utils/src/main/scala/org/apache/spark/internal/LogKey.scala:
##########
@@ -26,13 +26,16 @@ trait LogKey {
 }
 
 /**
- * Various keys used for mapped diagnostic contexts(MDC) in logging.
- * All structured logging keys should be defined here for standardization.
+ * Various keys used for mapped diagnostic contexts(MDC) in logging. All structured logging keys

Review Comment:
   Many of these formatting changes happened after running dev/scalafmt. Should we keep them? 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-47240][CORE][PART1] Migrate logInfo with variables to structured logging framework [spark]

Posted by "zeotuan (via GitHub)" <gi...@apache.org>.
zeotuan commented on PR #46362:
URL: https://github.com/apache/spark/pull/46362#issuecomment-2095094081

   @gengliangwang Hi please help review


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org