dongjoon-hyun opened a new pull request, #60566:
URL: https://github.com/apache/spark/pull/60566
### 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
`branch-4.x` to the Structured Logging Framework. This is a backport of #60561
(master commit 8aa399aea7f). The cherry-pick applied without conflicts and the
patch is identical to the master commit (same `git patch-id`).
- `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 script also fails when it finds no Scala
file, so that a wrong path cannot silently turn off the check again.
- 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, except that the `State.scala` message gets its missing words
(`destination not been previouslymaterialized` becomes `destination has not
been previously materialized`). Existing `LogKeys` are reused, except for one
new key, `PROCESS_UNLOADED_ONLY`, for the boolean flag of the `StateStore`
maintenance task.
`branch-4.x` has exactly the same violations as `master`, in the same files
and with the same count per file, so no `branch-4.x`-specific migration is
needed.
| 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), which is included in `branch-4.x` since
[v4.1.0](https://github.com/apache/spark/releases/tag/v4.1.0) (2025-12-11). 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 `branch-4.x` 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 and the corrected
wording of the `State.scala` 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 on `branch-4.x`
with JDK 17.
- 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 in 31 files, the same set
as on `master` (for example `[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, from `dev/`, and from
another directory.
- In a directory tree without Scala files, it fails with `[error] Found no
Scala files to check.` (exit code 255).
- Compiled the affected modules with SBT, ran `scalastyle` on them (0
errors, 0 warnings), 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 -Pkubernetes core/scalastyle kubernetes/scalastyle
sql-kafka-0-10/scalastyle catalyst/scalastyle sql/scalastyle
connect-common/scalastyle connect/scalastyle pipelines/scalastyle
streaming/scalastyle
$ build/sbt "common-utils/testOnly org.apache.spark.util.LogKeysSuite"
```
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Sonnet 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]