When using the Flink Operator is there a specific ...
# troubleshooting
r
When using the Flink Operator is there a specific plug-in required to use log4j-related logging? I’m attempting to use the following configuration for a job:
Copy code
logConfiguration:
    log4j-console.properties: |+
      rootLogger.level = INFO
      rootLogger.appenderRef.console.ref = ConsoleAppender
      rootLogger.appenderRef.rolling.ref = RollingFileAppender

      # console logs go to gcp logging so we want json format
      appender.console.name = ConsoleAppender
      appender.console.type = CONSOLE
      appender.console.layout.type = JsonTemplateLayout
      appender.console.layout.eventTemplateUri = classpath:GcpLayout.json

      # log to file so logs show up in flink ui
      appender.rolling.name = RollingFileAppender
      appender.rolling.type = RollingFile
      appender.rolling.append = false
      appender.rolling.fileName = ${sys:log.file}
      appender.rolling.filePattern = ${sys:log.file}.%i
      appender.rolling.layout.type = PatternLayout
      appender.rolling.layout.pattern = %d{yyyy-MM-dd HH:mm:ss,SSS} %-5p %-60c %x - %m%n
      appender.rolling.policies.type = Policies
      appender.rolling.policies.size.type = SizeBasedTriggeringPolicy
      appender.rolling.policies.size.size=100MB
      appender.rolling.strategy.type = DefaultRolloverStrategy
      appender.rolling.strategy.max = 10
However, when the job runs it immediately crashes with the following series of errors:
Copy code
ERROR Null object returned for CONSOLE in Appenders
ERROR Unable to locate appender "ConsoleAppender" for logger config "root"
ERROR Unable to locate plugin type for JsonTemplateLayout
ERROR Unable to locate plugin for JsonTemplateLayout
ERROR Could not create plugin of type class org.apache.logging.log4j.core.appender.ConsoleAppender for element CONSOLE: java.lang.NullPointerException java.lang.NullPointerException
...
ERROR Unable to invoke factory method in class org.apache.logging.log4j.core.appender.ConsoleAppender for element CONSOLE: java.lang.IllegalStateException: No factory method found for class org.apache.logging.log4j.core.appender.ConsoleAppender java.lang.IllegalStateException: No factory method found for class org.apache.logging.log4j.core.appender.ConsoleAppender
Is there any additional configuration or plug-ins required to make this work/supported? The logging works when the job is run directly in IntelliJ locally, however I suspect that the Maven Shading process might be hiding these specific references?
I went ahead and reviewed over some of the dependencies in the jar and I can see the appropriate classes in the shaded jar:
Even with the above, it’s still doesn’t seem to find the appropriate layout:
Copy code
Unable to locate plugin type for JsonTemplateLayout
Still no luck on defining custom JSON-based templating for jobs running via the operator as I’m continually running into the following error when the job kicks off:
Copy code
ERROR Unable to locate plugin type for JsonTemplateLayout                                                                                                                                            ERROR Unable to locate plugin for JsonTemplateLayout                                                                                                                                                 ERROR Could not create plugin of type class org.apache.logging.log4j.core.appender.ConsoleAppender for element Console: java.lang.NullPointerException java.lang.NullPointerException
The logConfiguration for the job looks as follows:
Copy code
logConfiguration:
  log4j-console.properties: |+
    rootLogger.level = INFO
    rootLogger.appenderRef.console.ref = ConsoleAppender
    rootLogger.appenderRef.rolling.ref = RollingFileAppender

    ...
    appender.console.name = ConsoleAppender
    appender.console.type = Console
    appender.console.layout.type = JsonTemplateLayout
    appender.console.layout.eventTemplateUri = classpath:GcpLayout.json
I believe that all of the appropriate references are correct in the actual shaded jar itself as I can see things like the
JsonTemplateLayout
inside of it (under
org.apache.logging.log4j.template.json.JsonTemplateLayout
) as well as the GcpLayout that I’m targeting in the root of the shaded jar as well (see attached image) I’ve tried adjusting several different knobs/configurations but I’m still continually getting this same error. I’d be happy to share any additional configuration for the job any/or the FlinkDeployment where applicable. Just a bit stumped here.
p
I am assuming you looked at this example already https://github.com/apache/flink-kubernetes-operator/blob/main/examples/custom-logging.yaml One observation from my side is ( PS: I've only tested this once) Custom logConfiguration at FlinkDeployment level requires entire log4j-console.properties content, can not override a single parameter or append to existing configuration.
How about you specify
log4j-console.properties: |
instead of
log4j-console.properties: |+
and make sure you provide all necessary properties in there
r
Hi @Prithvi Dammalapati - thanks. I had previously seen the custom logging example as you imagined. I’ll try adjusting the log configuration syntax as well to see if that makes any difference. I posed a question on the mailing list related to this as well. Previously I was building a custom image (via Docker) that packages and shades all of my related jars and have previously used that image to easily point to a specific jar to run. Additionally as part of this process one of these log4j jars was being copied into the
/flink/lib
directory. I think the problem here is that I have an initContainer that handles copying the job from the original image onto the image the operator is running against (i.e.
flink-1.17
) to expose the jar, however I feel like I need to do the same for this logging dependency as well (but I don’t see any options as far as copying over custom libs like that), I’m using the
ENABLE_BUILT_IN_PLUGINS
functionality for some things and this feels slightly similar.
Yeah, I’ve tried a few of these and I think the primary problem is that there doesn’t seem to be a way to copy jar(s) into the
/flink/lib
directory for the image that the operator uses. I attempted to accomplish this via a volume/volumeMount as follows:
Copy code
podTemplate:
  apiVersion: v1
  kind: Pod
  metadata:
    name: task-manager-pod-template
  spec:
    initContainers:
      - name: copy-job-contents
        image: {{ $.Values.myCustomFlinkImage }}
        volumeMounts:
          - mouthPath: /flink/lib
            name: lib
        command: ["/bin/sh", "-c"]
        args:
        - cp /my/image/example.jar /flink/lib/example.jar
        - ...
...
containers:
  - name: flink-main-container
    ...
    volumeMounts:
      - mountPath: /flink/lib
        name: lib
...
volumes:
  - name: lib
    emptyDir: { }
However, when I attempt something like this it looks like the volume being mounted completely overwrites the lib directory causing the necessary Flink components to be unavailable (since
/flink/lib
is an actual non-empty active directory), so it’d be overwriting that with the volume. Is there any other way to add something to the class path at a given location (other than /flink/lib) when using the operator so that I could make something like this available?
g
Could you maybe build a custom Flink base image with the additional jars added to that? If this is about logging dependencies etc, this is probably easier than figuring out a way to inject this for every job independently
p
In our setup, we mount a custom json-layout configmap onto each pod
Copy code
volumes:
        - name: config
          configMap:
            # Provide the name of the ConfigMap you want to mount.
            name: flink-logging
            # An array of keys from the ConfigMap to create as files
            items:
              - key: "log-layout.json"
                path: "log-layout.json"
Each pod will then refer to this in its log configuration
Copy code
appender.console.layout.type = JsonTemplateLayout
      appender.console.layout.eventTemplateUri = file:///config/log-layout.json