Izeren commented on code in PR #28855:
URL: https://github.com/apache/flink/pull/28855#discussion_r3704075871
##########
flink-core/src/main/java/org/apache/flink/util/MdcUtils.java:
##########
@@ -112,7 +115,38 @@ public static ScheduledExecutorService scopeToJob(JobID
jobID, ScheduledExecutor
return new MdcAwareScheduledExecutorService(ses, asContextData(jobID));
}
+ /**
+ * Build MDC context for a job. Consults the {@link JobMdcRegistry} for
enriched context
+ * registered where the job {@link Configuration} is available; falls back
to the plain job ID
+ * entry.
+ */
public static Map<String, String> asContextData(JobID jobID) {
+ final Map<String, String> registered = JobMdcRegistry.lookup(jobID);
+ if (registered != null) {
+ return registered;
+ }
return Collections.singletonMap(JOB_ID, jobID.toHexString());
}
+
+ /**
+ * Build MDC context from a job ID and job configuration, enriching with
context entries
+ * configured via {@link MdcOptions#JOB_CONFIGURATION_TO_MDC_KEYS}.
+ */
+ public static Map<String, String> asContextData(
+ final JobID jobID, final Configuration jobConfiguration) {
+ final Map<String, String> mdcKeyMapping =
+ jobConfiguration.get(MdcOptions.JOB_CONFIGURATION_TO_MDC_KEYS);
+ final Map<String, String> context = new HashMap<>();
+ for (Map.Entry<String, String> entry : mdcKeyMapping.entrySet()) {
+ final String value = jobConfiguration.getString(entry.getKey(),
null);
+ if (value != null && !value.isBlank()) {
+ context.put(entry.getValue(), value);
Review Comment:
The asymmetry here comes from the fact that `key` maybe empty until upstream
service submitting the job is not providing the value in config. Key side acts
as a "switch" for configs that we might expect. Empty value though would be a
deliberate misconfiguration. So I'd not complicate the code here with extra
check
--
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]