How to enable the JWS tomcat Access Log in OpenShift when JWS installed using Operator?

Solution Verified - Updated

Environment

  • Red Hat OpenShift Container Platform (OCP) 4.x
    • Red Hat JBoss Web Server (JWS) 5.6 deployed using operator or via template

Issue

  • How to enable the JWS tomcat Access Log Valve to log access messages to the standard output channel in OpenShift?
  • How to enable the JWS tomcat Access Log in OpenShift when JWS installed using Operator?

Resolution

Given the WebServer Custom Resource not having the Access log setting on its spec, the user will need to add ENABLE_ACCESS_LOG to true environmental variables directly on the JWS JWS application deployment configuration. This is usually not expected because the Operator creates/deploys the deployment yaml.

To do this changes using OC client, use following steps:

Step1: Edit the JWS tomcat deployments and add ENABLE_ACCESS_LOG to true.

$ oc edit deployments/jws-app

 spec:
      containers:
      - env:
        - name: KUBERNETES_NAMESPACE
          value: webserver-example-image-webserver
        - name: ENABLE_ACCESS_LOG
          value: "true"
        image: registry.redhat.io/jboss-webserver-5/jws56-openjdk8-openshift-rhel8@sha256:ed4f28495cebacb1500f009b0fca4a32634ef035964f>
        imagePullPolicy: Always

step2: Check the changes:

$ oc describe deployments/jws-app | grep -i ENABLE_ACCESS_LOG
      ENABLE_ACCESS_LOG:     true

step3: Check if pods are restarted.

$ oc get pod
NAME                       READY   STATUS              RESTARTS   AGE
jws-app-549cffbf5b-hpg5f   0/1     ContainerCreating   0          2s
jws-app-549cffbf5b-qwbkq   0/1     ContainerCreating   0          2s

$ oc get pod
NAME                       READY   STATUS              RESTARTS   AGE
jws-app-549cffbf5b-hpg5f   0/1     Running             0          5s
jws-app-549cffbf5b-qwbkq   0/1     ContainerCreating   0          5s

$ oc get pod
NAME                       READY   STATUS    RESTARTS   AGE
jws-app-549cffbf5b-hpg5f   1/1     Running   0          7s
jws-app-549cffbf5b-qwbkq   1/1     Running   0          7s

$ oc get pod
NAME                       READY   STATUS    RESTARTS   AGE
jws-app-549cffbf5b-hpg5f   1/1     Running   0          8s
jws-app-549cffbf5b-qwbkq   1/1     Running   0          8s

Root Cause

Template deployment will create a deployment(config) that controls the JWS containers.
JWS Operator creates a deployment yaml and it will control it (manage it), however the user can overwrite the deployment yaml and add the env settings (as above) without being overwritten by the JWS Operator:

### Create a Web Server CR
$ oc apply example-webserver.yaml
### The webserver:
$ oc get webserver
NAME                      AGE
example-image-webserver   20m
###  Get the deployment:
 oc get deployment
NAME                                                            READY   UP-TO-DATE   AVAILABLE   AGE
jws-app                                                                2/2     2            2           21m
jws-operator-controller-manager                  1/1     1            1           39m

Diagnostic Steps

  1. Verify the pod yaml has the env variable:
$ oc describe pod jws-app-549cffbf5b-r9bdq | grep ENABLE_ACCESS_LOG
      ENABLE_ACCESS_LOG:     true
  1. check the env variable and the pod logs:
$ oc rsh jws-app-ID
sh-4.4$ echo $ENABLE_ACCESS_LOG 
true
...
...
$ oc logs jws-app-ID
-XX:+UseParallelOldGC -XX:MinHeapFreeRatio=10 -XX:MaxHeapFreeRatio=20 -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -XX:MaxMetaspaceSize=100m -XX:+ExitOnOutOfMemoryError
INFO Configuring Access Log Valve.
-XX:+UseParallelOldGC -XX:MinHeapFreeRatio=10 -XX:MaxHeapFreeRatio=20 -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -XX:MaxMetaspaceSize=100m -XX:+ExitOnOutOfMemoryError
/opt/jws-5.6/tomcat/bin/launch/catalina.sh: line 12: /opt/jboss/container/prometheus/jws-prometheus-opts: No such file or directory
-XX:+UseParallelOldGC -XX:MinHeapFreeRatio=10 -XX:MaxHeapFreeRatio=20 -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -XX:MaxMetaspaceSize=100m -XX:+ExitOnOutOfMemoryError
INFO Running jboss-webserver-5/jws56-openjdk8-rhel8-openshift image, version 5.6.2
26-Aug-2022 12:24:29.901 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version name:   Apache Tomcat/9.0.50.redhat-00007
26-Aug-2022 12:24:29.902 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built:          Apr 13 2022 11:06:01 UTC
26-Aug-2022 12:24:29.902 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version number: 9.0.50.redhat-00007
26-Aug-2022 12:24:29.902 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name:               Linux
26-Aug-2022 12:24:29.903 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version:            4.18.0-305.49.1.el8_4.x86_64
26-Aug-2022 12:24:29.903 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture:          amd64
26-Aug-2022 12:24:29.903 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home:             /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.332.b09-2.el8_6.x86_64/jre
26-Aug-2022 12:24:29.903 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version:           1.8.0_332-b09
26-Aug-2022 12:24:29.903 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor:            Red Hat, Inc.
26-Aug-2022 12:24:29.903 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE:         /opt/jws-5.6/tomcat
26-Aug-2022 12:24:29.903 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME:         /opt/jws-5.6/tomcat
26-Aug-2022 12:24:29.903 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=/opt/jws-5.6/tomcat/conf/logging.properties
26-Aug-2022 12:24:29.903 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: 
Components
Category

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.