Skip to content

Not able to use custom logging with airflow helm chart #27498

@venkatnpedada

Description

@venkatnpedada

Apache Airflow version

2.4.2

What happened

Im trying to use custom logger to print the logs to console instead of the local directory. Im using official airflow helm chart. Below are the steps to re-produce the issue.

step 1: Create custom logger class to ${AIRFLOW_HOME}/config/airflow_local_settings.py by adding below in airflowLocalSettings property

airflowLocalSettings: |-

from copy import deepcopy
from airflow.config_templates.airflow_local_settings import DEFAULT_LOGGING_CONFIG
import sys

LOGGING_CONFIG = deepcopy(DEFAULT_LOGGING_CONFIG)
LOGGING_CONFIG["handlers"]["processor"] = {
    "class": "logging.StreamHandler",
    "formatter": "airflow",
    "stream": sys.stdout,
}

step 2: Set logging_config_class property to config.log_config.LOGGING_CONFIG in airflow.cfg by adding below in property

config:
  logging:
     logging_config_class: airflow_local_settings.LOGGING_CONFIG

While deploying the helm chart got below error from running migrations in "wait-for-airflow-migrations" container

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/airflow/logging_config.py", line 40, in configure_logging
    logging_config = import_string(logging_class_path)
  File "/usr/local/lib/python3.7/dist-packages/airflow/utils/module_loading.py", line 32, in import_string
    module = import_module(module_path)
  File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'airflow_local_settings'

Suspecting the helm chart not mounted the airflowLocalSettings config on this init container and only mounted the actual airflow.cfg - https://github.com/apache/airflow/blob/main/chart/templates/scheduler/scheduler-deployment.yaml#L138-L142

What you think should happen instead

official airflow helm chart should support using the custom logging as provided in the above without any issue. We might need to mount the airflowLocalSettings config aswell in the init container wait-for-airflow-migrations

https://github.com/apache/airflow/blob/main/chart/templates/scheduler/scheduler-deployment.yaml#L210-L215

            {{- if .Values.airflowLocalSettings }}
            - name: config
              mountPath: {{ template "airflow_local_setting_path" . }}
              subPath: airflow_local_settings.py
              readOnly: true
            {{- end }}

How to reproduce

step 1: Create custom logger class to ${AIRFLOW_HOME}/config/airflow_local_settings.py by adding below in airflowLocalSettings property

airflowLocalSettings: |-

from copy import deepcopy
from airflow.config_templates.airflow_local_settings import DEFAULT_LOGGING_CONFIG
import sys

LOGGING_CONFIG = deepcopy(DEFAULT_LOGGING_CONFIG)
LOGGING_CONFIG["handlers"]["processor"] = {
    "class": "logging.StreamHandler",
    "formatter": "airflow",
    "stream": sys.stdout,
}

step 2: Set logging_config_class property to config.log_config.LOGGING_CONFIG in airflow.cfg by adding below in property

config:
  logging:
     logging_config_class: airflow_local_settings.LOGGING_CONFIG

While deploying the helm chart got below error from running migrations in "wait-for-airflow-migrations" container

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/airflow/logging_config.py", line 40, in configure_logging
    logging_config = import_string(logging_class_path)
  File "/usr/local/lib/python3.7/dist-packages/airflow/utils/module_loading.py", line 32, in import_string
    module = import_module(module_path)
  File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'airflow_local_settings'

Operating System

Debian GNU/Linux 10 (buster)

Versions of Apache Airflow Providers

No response

Deployment

Official Apache Airflow Helm Chart

Deployment details

No response

Anything else

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions