Savonitar commented on code in PR #28857:
URL: https://github.com/apache/flink/pull/28857#discussion_r3719638762


##########
flink-core/src/main/java/org/apache/flink/util/MdcUtils.java:
##########
@@ -149,4 +160,25 @@ public static Map<String, String> asContextData(
         context.put(JOB_ID, jobID.toHexString());
         return Collections.unmodifiableMap(context);
     }
+
+    /**
+     * Builds a thread-name suffix identifying the given job, e.g. {@code " 
(job: my-job /
+     * 0123...ef)"}. Long job names are truncated. The full hex job id matches 
the {@link #JOB_ID}
+     * MDC value, so thread dumps correlate with log output.
+     *
+     * @param jobInfo the job meta information
+     * @return a suffix to append to a thread name
+     */
+    public static String jobThreadNameSuffix(@Nonnull JobInfo jobInfo) {
+        final String hexJobId = jobInfo.getJobId().toHexString();
+        final String jobName = jobInfo.getJobName();
+        if (jobName == null || jobName.isEmpty()) {
+            return " (job: " + hexJobId + ")";
+        }
+        final String truncatedJobName =
+                jobName.length() <= MAX_JOB_NAME_IN_THREAD_NAME
+                        ? jobName
+                        : jobName.substring(0, MAX_JOB_NAME_IN_THREAD_NAME) + 
"...";

Review Comment:
   Agreed, e.g. for generated SQL job names, head-only truncation may collapse 
distinct jobs into identical thread names. Implemented, + added your example as 
the regression test: two names differing only in their -v1/-v2 tail.



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

Reply via email to