bakdata / kpops

Deploy Kafka pipelines to Kubernetes
https://bakdata.github.io/kpops
MIT License
12 stars 1 forks source link

Log4j2 Environment Lookup not substituted correctly #389

Open raminqaf opened 9 months ago

raminqaf commented 9 months ago

The Environment Lookup in Log4j2 cannot be processed correctly by KPOps. If we define the log4jConfig in the kafka-app like that:

kafka-app:
  app:
    streams:
      brokers: "${brokers}"
      schemaRegistryUrl: http://schema-registry:8081
    log4jConfig: |
      <?xml version="1.0" encoding="UTF-8"?>
      <Configuration>
          <Appenders>
              <Console name="Console" target="SYSTEM_OUT">
                  <PatternLayout pattern="%d{HH:mm:ss.SSS} %-5level %logger{36} - %msg%n"/>
              </Console>
          </Appenders>
          <Loggers>
              <Logger additivity="false" level="$${env:STREAMS_LOG_LEVEL:-info}" name="com.bakdata">
                  <AppenderRef ref="Console"/>
              </Logger>
              <Root level="info">
                  <AppenderRef ref="Console"/>
              </Root>
          </Loggers>
      </Configuration>
    labels:
      pipeline: ${pipeline_name_0}

And then use the KPOps generate ... --template the output of the ConfigMap (where the log config lives) looks like this:

# Source: streams-app/templates/log4j-configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: my-streams-app-log4j-configmap
data:
  log4j2.xml: |
    <?xml version="1.0" encoding="UTF-8"?>
    <Configuration>
        <Appenders>
            <Console name="Console" target="SYSTEM_OUT">
                <PatternLayout pattern="%d{HH:mm:ss.SSS} %-5level %logger{36} - %msg%n"/>
            </Console>
        </Appenders>
        <Loggers>
            <Logger additivity="false" level="${env:STREAMS_LOG_LEVEL:-info}" name="com.bakdata">
                <AppenderRef ref="Console"/>
            </Logger>
            <Root level="info">
                <AppenderRef ref="Console"/>
            </Root>
        </Loggers>
    </Configuration>
sujuka99 commented 7 months ago

That is because string.Template.substitute sees $$ as an escaped $, hence it removes 1 of the dollar signs.