Uploaded image for project: 'Flink'
  1. Flink
  2. FLINK-17969

Enhance Flink (Task) logging to include job name as context diagnostic information

    XMLWordPrintableJSON

Details

    Description

      Problem statement:
      We use a shared session cluster (Standalone/Yarn) to execute jobs. All logs from the cluster are shipped using log aggregation framework (Logstash/Splunk) so that application diagnostic is easier.
      However, we are missing one vital information in the logline. i.e. Job name so that we can filter the logs for a single job.

      Background
      Currently, Flink logging uses SLF4J as API to abstract away from concrete logging implementation (log4j 1.x, Logback or log4j2) and configuration of logging pattern and implementation can be configured at deployment, However, there is no MDC info from framework indicating job context.

      Proposed improvement.

      Add jobName field to Task class so that we can add it as MDC when task thread starts executing.

      Change is trivial and uses SLF4J MDC API.

      With this change, user can customise logging pattern to include MDC (e.g. in Logback %X

      {jobName}

      )

      Change required.

      @@ -319,6 +323,7 @@ public class Task implements Runnable, TaskSlotPayload, TaskActions, PartitionPr
       
                      this.jobId = jobInformation.getJobId();
      +               this.jobName = jobInformation.getJobName();
                      this.vertexId = taskInformation.getJobVertexId();
      @@ -530,8 +535,10 @@ public class Task implements Runnable, TaskSlotPayload, TaskActions, PartitionPr
              @Override
              public void run() {
                      try {
      +                       MDC.put("jobName", this.jobName);
                              doRun();
                      } finally {
      +                       MDC.remove("jobName");
                              terminationFuture.complete(executionState);
                      }
              }
      

      if we are in agreement for this small change. Will raise PR.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              dasbh Bhagavan
              Votes:
              2 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: