將日誌寫入 Azure Blob 儲存體¶
Airflow 可以設定為在 Azure Blob 儲存體中讀取和寫入任務日誌。它使用現有的 Airflow 連線來讀取或寫入日誌。如果您沒有正確設定連線,此過程將會失敗。
請按照以下步驟啟用 Azure Blob 儲存體日誌記錄
若要啟用此功能,必須像此範例中一樣配置 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
使用
pip install apache-airflow-providers-microsoft-azure
安裝供應商套件確保已設定連線,以便在
remote_wasb_log_container
容器和remote_base_log_folder
路徑中具有 Azure Blob 儲存體的讀取和寫入權限。設定上述組態值。請注意,
remote_base_log_folder
應以wasb
開頭,以選擇正確的處理程序,如上所示,且容器應已存在。重新啟動 Airflow Web 伺服器和排程器,並觸發(或等待)新的任務執行。
驗證日誌是否顯示在您定義的指定基礎路徑的容器中,以用於新執行的任務。
驗證 Azure Blob 儲存體檢視器在 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
請注意,遠端日誌檔的路徑列在第二行。