dongjoon-hyun opened a new pull request, #60561:
URL: https://github.com/apache/spark/pull/60561

   ### What changes were proposed in this pull request?
   
   This PR aims to fix `dev/structured_logging_style.py` to scan the Scala 
files of the repository, and to migrate the log statements that it reports on 
`master` to the Structured Logging Framework.
   
   - `dev/structured_logging_style.py` changes the working directory to the 
repository root, which is derived from `__file__`, and finds `**/*.scala` from 
there. The file paths stay relative to the repository root, so the existing 
exclusion patterns match the same files wherever the repository is checked out. 
The result is the same whether the script runs from the repository root, 
`dev/`, or any other directory.
   - The 49 log statements (31 files) reported by the fixed script now use 
`log"...${MDC(KEY, value)}"`. The message texts and the logged values are 
unchanged. Existing `LogKeys` are reused, except for one new key, 
`PROCESS_UNLOADED_ONLY`, for the boolean flag of the `StateStore` maintenance 
task.
   
   | Module | Files | Log statements |
   |---|---:|---:|
   | `core` | 8 | 13 |
   | `resource-managers/kubernetes/core` | 2 | 5 |
   | `connector/kafka-0-10-sql` | 1 | 1 |
   | `sql/catalyst` | 2 | 3 |
   | `sql/core` | 12 | 15 |
   | `sql/connect/common` | 2 | 2 |
   | `sql/connect/server` | 1 | 7 |
   | `sql/pipelines` | 2 | 2 |
   | `streaming` | 1 | 1 |
   
   `StreamingShuffleServerHandler` mixes in `TaskContextAwareLogging`, whose 
`LogEntry` methods prefix the query ID and the shuffle ID as MDC values instead 
of the `[queryId = ...] [shuffleId = ...] [stageId = ...] [taskId = ...]` 
prefix of its `String` methods. So its termination ack message now has the same 
prefix as the other structured log messages of the streaming shuffle, such as 
those of `StreamingShuffleWriter`.
   
   ### Why are the changes needed?
   
   The `Scala structured logging check` step of the GitHub Actions lint job has 
been a no-op since #51087 (2025-06-06). The script globs 
`os.path.join(__file__, "../", "**", "*.scala")`, which is 
`./dev/structured_logging_style.py/../**/*.scala` when CI runs `python3.12 
./dev/structured_logging_style.py` from the repository root. A file is not a 
directory, so `glob` matches nothing and the script always prints `Structured 
logging style check passed.`
   
   ```
   $ python3 -c 'import glob, os; 
print(len(glob.glob(os.path.join("./dev/structured_logging_style.py", "../", 
"**", "*.scala"), recursive=True)))'
   0
   ```
   
   As a result, log statements with variables that bypass the Structured 
Logging Framework have accumulated on `master` unnoticed. All 49 statements in 
this PR were introduced after #51087.
   
   ### Does this PR introduce _any_ user-facing change?
   
   No functional change. The migrated log messages print the same text, except 
for the prefix of the `StreamingShuffleServerHandler` message described above. 
When structured logging is enabled 
(`spark.log.structuredLogging.enabled=true`), the variables of these messages 
are also available as MDC values in the JSON `context`.
   
   ### How was this patch tested?
   
   Pass the CIs. In addition, I checked the following manually.
   
   - Before this PR, the script passes without scanning any file.
     ```
     $ python3 dev/structured_logging_style.py
     Structured logging style check passed.
     ```
   - With only the script fix, it reports 49 errors such as `[error] 
core/src/main/scala/org/apache/spark/MapOutputTracker.scala:236:6`. The result 
is the same from the repository root, `dev/`, and another directory.
   - With this PR, it passes from the repository root and from `dev/`.
   - Compiled the affected modules with SBT, ran `scalastyle` on them, 
validated `scalafmt` of `sql/connect/common` and `sql/connect/server`, and ran 
`LogKeysSuite`.
     ```
     $ build/sbt -Pkubernetes common-utils-java/compile core/compile 
kubernetes/compile sql-kafka-0-10/compile catalyst/compile sql/compile 
connect-common/compile connect/compile pipelines/compile streaming/compile
     $ build/sbt "common-utils/testOnly org.apache.spark.util.LogKeysSuite"
     ```
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Claude Opus 5.5
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to