Zhuoxi2000 opened a new pull request, #1495:
URL: https://github.com/apache/flink-agents/pull/1495
<!--
* Thank you very much for contributing to Flink Agents.
* Please add the relevant components in the PR title. E.g., [api],
[runtime], [java], [python], [hotfix], etc.
-->
<!-- Please link the PR to the relevant issue(s). Hotfix doesn't need this.
-->
Linked issue: #1494
### Purpose of change
<!-- What is the purpose of this change? -->
Trace Log files are now written in UTF-8 whatever the JVM default charset
is. Before, both writers used the default charset, so on JDK 11/17 with a
non-UTF-8 locale (for example `LANG=C`, or Windows) non-ASCII text was replaced
with `?` or written in a single-byte encoding that the Trace Tree reader, which
reads UTF-8, rejects with `UNREADABLE_FILE`.
* `FileTraceLogger` opens its `FileWriter` with `StandardCharsets.UTF_8`.
* `Slf4jTraceLogger` sets `StandardCharsets.UTF_8` on the `PatternLayout` of
the automatic `{log.file}.trace-log.log` appender. A user-configured logger or
appender is not touched.
### Behavioral Semantics
<!-- For a non-trivial code change whose implementation is largely
AI-assisted: interaction decisions, behavioral contracts, and failure behavior.
See `contribution-guides/ai-assisted-pr.md`. Remove this heading and this
comment otherwise. -->
#### Behavioral contracts
1. `traces-{jobId}-{taskName}-{subtask}.log` files are UTF-8, independent of
`file.encoding`.
2. The automatic `{log.file}.trace-log.log` appender encodes records as
UTF-8, independent of `file.encoding`.
#### Failure behavior
No new failure paths. `FileWriter` still replaces unencodable input (such as
an unpaired surrogate left by string truncation) instead of failing the write.
### Tests
<!-- How is this change verified? -->
| Contract | Tests |
|---|---|
| 1 | `FileTraceLoggerTest.testNonAsciiTextIsWrittenAsUtf8` |
| 2 |
`Slf4jTraceLoggerFailureTest.fileWriteFailuresAreCountedWithoutEscapingAndWarnOnlyOnce`
(asserts the appender layout charset) |
Both assertions pass on main when the JVM default charset is UTF-8, as in
CI, so they only show the bug with a non-UTF-8 default. Without the fix they
fail under:
```bash
JAVA_TOOL_OPTIONS=-Dfile.encoding=ISO-8859-1 mvn test -pl runtime
-Dtest='FileTraceLoggerTest,Slf4jTraceLogger*Test'
```
With the fix that run passes (29 tests), and `mvn verify -pl runtime` passes
with the default charset.
### API
<!-- Does this change touches any public APIs? -->
No public API change.
### Documentation
<!-- Do not remove this section. Check the proper box only. -->
- [ ] `doc-needed` <!-- Your PR changes impact docs -->
- [ ] `doc-not-needed` <!-- Your PR changes do not impact docs -->
- [x] `doc-included` <!-- Your PR already contains the necessary
documentation updates -->
`docs/content/docs/operations/monitoring.md` states that Trace Log files are
UTF-8.
### Was this patch authored or co-authored using generative AI tooling?
<!-- Do not remove this section. Check the proper box only. -->
- [x] Yes
- [ ] No
If yes, include a `Generated-by: <tool name and version> (<model name and
version>)` line, for example `Generated-by: Claude Code 2.1.226 (Claude Opus
4.6)`, in the commit message so it reaches Git history. Repeat the same line
here for reviewer visibility. See the [ASF generative tooling
guidance](https://www.apache.org/legal/generative-tooling.html).
Generated-by: Claude Code 2.1.259 (Claude Fable 5.2)
--
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]