將日誌寫入 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

請注意,遠端日誌檔案的路徑列在第二行。

此條目是否有幫助?