将日志写入 Azure Blob Storage

Airflow 可以配置为在 Azure Blob Storage 中读取和写入任务日志。它使用现有的 Airflow 连接来读取或写入日志。如果您没有正确设置连接,此过程将失败。

按照以下步骤启用 Azure Blob Storage 日志记录

要启用此功能,必须按照此示例配置 airflow.cfg

[logging]
# Airflow can store logs remotely in AWS S3, Google Cloud Storage or Elastic Search.
# Users must supply an Airflow connection id that provides access to the storage
# location. If remote_logging is set to true, see UPDATING.md for additional
# configuration requirements.
remote_logging = True
remote_base_log_folder = wasb-base-folder/path/to/logs

[azure_remote_logging]
remote_wasb_log_container = my-container
  1. 使用 pip install apache-airflow-providers-microsoft-azure 安装提供程序包

  2. 确保 连接 已设置,具有对 Azure Blob Storage 中 remote_wasb_log_container 容器和路径 remote_base_log_folder 的读写访问权限。

  3. 设置上述配置值。请注意,remote_base_log_folder 应以 wasb 开头,以便选择正确的处理程序(如上所示),并且容器必须已经存在。

  4. 重启 Airflow webserver 和 scheduler,并触发(或等待)新的任务执行。

  5. 验证新执行任务的日志是否出现在您定义的指定基本路径的容器中。

  6. 验证 Azure Blob Storage 查看器在 UI 中是否正常工作。打开一个新执行的任务,并验证您是否看到类似以下内容:

*** Found remote logs:
***   * https://my-container.blob.core.windows.net/wasb-base-folder/path/to/logs/dag_id=tutorial_dag/run_id=manual__2023-07-22T22:22:25.891267+00:00/task_id=load/attempt=1.log
[2023-07-23, 03:52:47] {taskinstance.py:1144} INFO - Dependencies all met for dep_context=non-requeueable deps ti=<TaskInstance: tutorial_dag.load manual__2023-07-22T22:22:25.891267+00:00 [queued]>
[2023-07-23, 03:52:47] {taskinstance.py:1144} INFO - Dependencies all met for dep_context=requeueable deps ti=<TaskInstance: tutorial_dag.load manual__2023-07-22T22:22:25.891267+00:00 [queued]>
[2023-07-23, 03:52:47] {taskinstance.py:1346} INFO - Starting attempt 1 of 3

请注意,远程日志文件的路径列在第二行。

此条目是否有帮助?