Is anyone outputting JSON-based logs via jobs usin...
# troubleshooting
r
Is anyone outputting JSON-based logs via jobs using the Flink Operator? As far as I can tell, Log4J2 (the operator I believe is targeting 2.17.1) supports the use of a JsonTemplateLayout configuration which I have being included in the JAR for my job specifically:
Copy code
<dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-layout-template-json</artifactId>
</dependency>
Additionally, I’ve also included the appropriate reference which should be available on the classpath for the pods as well via an
initContainer
and the
pipeline.classpaths
configuration:
Copy code
spec:
  image: flink:1.17
  flinkVersion: v1_17
  flinkConfiguration:
  ...
    pipeline.classpaths: file:///opt/flink/external/log4j-layout-template-json-2.17.1.jar
  ...
  jobManager:
    ...
    podTemplate:
      apiVersion: v1
      kind: Pod
      metadata:
        name: job-manager
      spec:
        initContainers:
          - name: copy-job-contents
            image: {{ $values.image }}
            volumeMounts:
              - mountPath: /opt/flink/jars
                name: jars
              - mountPath: /opt/flink/external
                name: external
            command: ["/bin/sh", "-c"]
            args:
            # Copy logging dependency and executable jar from base image
            - cp /flink/lib/log4j-layout-template-json-2.17.1.jar /opt/flink/external/log4j-layout-template-json-2.17.1.jar; cp /opt/flink-vvp/ica-flink-risk-scoring.jar /opt/flink/jars/ica-flink-risk-scoring.jar
When I attempt to use the following logConfiguration:
Copy code
logConfiguration:
  ...
  appender.console.layout.type = JsonTemplateLayout
It immediately encounters an error when running the pods related to the job:
Copy code
ERROR Unable to locate plugin for JsonTemplateLayout
g
Can you try adding this to the libs of your docker image? You can create a custom image build
r
In my specific case, the operator itself is wrapped by a custom operator that doesn’t support custom images (for security purposes), so I wasn’t able to add it directly to the
/opt/flink/lib
directory. I can see all of the usual files available on the classpath however in the logs:
Copy code
org.apache.flink.runtime.entrypoint.ClusterEntrypoint        [] -  Classpath: /opt/flink/lib/flink-cep-1.17.2.jar:/opt/flink/lib/flink-connector-files-1.17.2.jar:/opt/flink/lib/flink-csv-1.17.2.jar:/opt/flink/lib/flink-json-1.17.2.jar:/opt/flink/lib/flink-scala_2.12-1.17.2.jar:/opt/flink/lib/flink-table-api-java-uber-1.17.2.jar:/opt/flink/lib/flink-table-planner-loader-1.17.2.jar:/opt/flink/lib/flink-table-runtime-1.17.2.jar:/opt/flink/lib/log4j-1.2-api-2.17.1.jar:/opt/flink/lib/log4j-api-2.17.1.jar:/opt/flink/lib/log4j-core-2.17.1.jar:/opt/flink/lib/log4j-slf4j-impl-2.17.1.jar:/opt/flink/lib/flink-dist-1.17.2.jar::::
I had hoped that copying the other jar to the appropriate location and using the
pipeline.classpaths
would make it available on the classpath as well. Unless the error above is a red-herring and it isn’t an issue of that jar being available on the classpath at all.
g
probably pipeline classpaths is only resolved when the java code is executed and not before that which would be needed for logging
r
Is there a way to confirm that the
pipeline.classpaths
is working properly? Should I see this jar within that
Classpath: …
logs?
g
I don’t know if Flink logs anything for that, you can check the source code where this config is used to make sure
You have some options here: 1. Create a custom image 2. Inject the entire content of libs in an init container including your custom logging jar
r
Hrm, this is interesting:
Copy code
/**
 * Mount the Flink User Lib directory to enable Flink to pick up a Jars defined in
 * pipeline.classpaths. Used for starting standalone application clusters
 */
public class UserLibMountDecorator extends AbstractKubernetesStepDecorator {
    private static final String USER_LIB_VOLUME = "user-lib-dir";
    private static final String USER_LIB_PATH = "/opt/flink/usrlib";

    private final StandaloneKubernetesJobManagerParameters kubernetesJobManagerParameters;

    public UserLibMountDecorator(
            StandaloneKubernetesJobManagerParameters kubernetesJobManagerParameters) {
        this.kubernetesJobManagerParameters = checkNotNull(kubernetesJobManagerParameters);
    }
g
I have seen you asked the same question several times both on the ML and slack, I think you can assume that we don’t have a good answer other than what I have just told you 🙂
r
I don’t currently have the
user-lib-dir
mounted, but it’s possible it’s required for
pipeline.classpaths
.
g
you can try that
r
Haha, yeah, this has been a troublesome one for sure.
It’s one of the few lingering issues to complete a migration off of Ververica Platform to the operator.
g
We also use json logging and I am pretty sure many others are as well. It’s very rare to not have a chance to build custom images, especially for security reasons is good to have a way to fix any bugs / add dependencies etc.
r
Yup, we used custom images previous which made this trivial (just copy the dependency over into lib and you are done). I initially tried that but it turns out that volumes/volumeMounts don’t like when those directories are non-empty, so I went down the avenue to try and see if I could get something on the classpath without explicitly adding it to /lib.
g
you can’t add files into another dir that has files already but you could copy the contents of lib + your jars into a new lib directory
r
I may give that a try since I’m already using initContainers to copy my jars from my other image, it might not be a huge lift.
I’ll report back - thanks for the suggestions @Gyula Fóra!
g
Although I don’t really see what you gain from a security perspective by doing this 😄
r
Haha, I agree. It makes everything so much easier, but it’s unfortunately not in our control :(
So I eventually had to go down the road of overwriting the lib directory from my custom image. It wasn’t too bad, basically grabbing the appropriate version in my Dockerfile and copying over the lib directory to a temp location and initContainer copying it to /opt/flink/lib.