-
Airflow 3.0.1 remote logging 에러 해결Airflow 2025. 5. 25. 11:57
기존 2.10.3 버전을 사용중이던 Airflow를 3점대 버전으로 업그레이드 하는 과정에서 마주한 에러해결 과정을 공유해봅니다.
⚙️ 개발 환경
airflow를 ECS에서 멀티클러스터로 구축했습니다.- api-server
- scheduler
- dag-processor
- worker(CeleryExecutor)
- redis
Airflow UI에서 DAG 실행을 하면
1. DAG run이 생성이 되고 metadata DB에 queued 상태로 저장됨
2. dag-processor가 DAG를 파싱하고 DB내 DAG의 metadata 업데이트 함
3. Scheduler가 DB를 감지하고 있다가 queued task 정보(DAG ID, task ID, execution date, etc.)를 redis에 메세지로 보냄
4. 이 task는 Celery worker가 가져가서 작업할 수 있게 "available" 상태가 됨
5. Celery worker는 redis 큐에서 task 메세지를 가져가서 실행하고, DB에 running 상태로 업데이트 함
6. 작업 종료 후 DB에 task 상태를 success/fail로 업데이트하고 이후 작업이 남아있다면 Scheduler가 다시 체크하는 식의 반복
이러한 프로세스로 DAG가 실행되는데, 5번 worker가 작업을 실행하면 로컬 경로에 로그파일을 저장합니다.
하지만 컨테이너 기반의 서비스를 운영할 때의 문제점인 특정 서버 의존성을 방지하기 위해
"중앙 집중식 로그 저장"인 s3 remote logging 방식을 사용하려고 합니다.
이 때 로그 저장 및 read 프로세스는
1. airflow.cfg에 remote_logging = True 를 설정했다면 retmote logging에서 read 먼저 시도
2. remote logging이 실패해서 읽어들이지 못한다면, falls back to local 로컬 경로에서 읽기 시도
다음은 remote logging 설정 방법입니다:# airflow.cfg
remote_logging= True
remote_log_conn_id = s3_conn
remote_base_log_folder = s3://airflow-logs # 로그 저장할 버킷 경로
delete_local_logs = False # 로그 삭제는 기본으로 허용하지 않음
remote_task_handler_kwargs = {"delete_local_copy": true} # remote logging에 성공했을 시 로그 삭제
remote_log_conn_id에는 airflow connections에 추가할 변수명을 입력하고 airflow connections에도 다음과 같이 추가합니다.--airflow CLI
airflow connections add 's3_conn' --conn-type 'aws' --conn-extra '{"region": "ap-northeast-2"}'*airflow 2.x 버전에서는 conn-type이 's3'였지만, 3점대 부터는 'aws'로 변경해줄 것
AWS IAM role을 사용하면 직접 Access Key와 Secret Access Key를 사용하지 않아도 됨으로 보안상 안전함!
위와 같이 설정을 하고 난 이후에도 DAG task를 실행하면 계속 fail이 났는데 에러를 보면,# UI 실행 ::group::Log message source details: sources=["Could not read served logs: Invalid URL 'http://:8793/log/dag_id=init_test_3.0.1/run_id=manual__2025-05-22T01:53:43.876152+00:00/task_id=print_time/attempt=1.log': No host supplied"]
# webserver container cli - test/success details: sources=["Could not read served logs: HTTPConnectionPool(host='ip-172-XX-X-XXX.ap-northeast-2.compute.internal', port=8793): Max retries exceeded with url: /log/dag_id=init_test_3.0.1/run_id=manual__2025-05-22T02:23:08.251172+00:00/task_id=print_time/attempt=1.log (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0xffff795e7080>: Failed to establish a new connection: [Errno 111] Connection refused'))"] - trigger/fail details: sources=["Could not read served logs: Invalid URL 'http://:8793/log/dag_id=init_test_3.0.1/run_id=manual__2025-05-22T02:23:51.280531+00:00_chCfWUle/task_id=print_day/attempt=1.log': No host supplied"]
# worker container cli - test/success details: sources=["Could not read served logs: 404 Client Error: NOT FOUND for url: <http://ip-172-XX-X-XXX.ap-northeast-2.compute.internal:8793/log/dag_id=init_test_3.0.1/run_id=manual__2025-05-22T02:27:10.433362+00:00/task_id=print_time/attempt=1.log>"] - trigger/fail details: sources=["Could not read served logs: Invalid URL 'http://:8793/log/dag_id=init_test_3.0.1/run_id=manual__2025-05-22T02:27:45.665350+00:00_QmabUKOl/task_id=print_time/attempt=1.log': No host supplied"]
UI에서도 실행해보고, airflow cli로 airflow dags test와 trigger로도 실행해봐도
worker host를 찾지못하거나 connection error가 발생했습니다.
worker container 로그를 보면, task가 killed되어 죽는 것을 볼 수 있었고, 405 Method Not Allowed 에러를 발견했습니다.
또한 컨테이너 logs/ 경로 아래에도 보면 로그 파일은 쌓이지만, 빈 로그 파일이었기 때문에,
task를 실행하기도 전에 죽어서 task를 실행하지 못하고 있음을 볼 수 있었습니다.
또 다른 에러로는 scheduler container 로그에서 not_found in serialized_dag table 에러를 발견했는데
scheduler container log:ERROR - DAG 'init_test_3.0.1' for task instance <TaskInstance: init_test_3.0.1.print_time manual__2025-05-23T01:11:24.335987+00:00 [queued]> not found in serialized_dag table
해당 DAG를 찾지 못하는 것 같아서 DB에 serialized_dag 테이블을 확인해보면 DAG가 잘 저장되어 있었습니다.
그래서 refresh 차원에서 airflow db migrate와 airflow dags reserialize를 실행해 봤지만, 결과는 똑같았습니다..
그러다가!! 찾은 한줄기 빛!! ✨
https://github.com/apache/airflow/issues/50191base_url gives state mismatch and task fail error. · Issue #50191 · apache/airflow
Apache Airflow version 3.0.0 If "Other Airflow 2 version" selected, which one? No response What happened? Recently, I upgraded Airflow from 2.10 to 3.0. I've deployed Airflow behind Nginx. I was ab...
github.com
airflow git issue로 올라온 비슷한 케이스를 발견하고 아래 방법을 시도해봤습니다.
✅ 해결 방안
처음 3버전으로 setting 후 dag를 실행했을 때 발생한 worker 에러가 있었는데,AirflowConfigException: section/key [core/execution_api_server_url] not found in config
Airflow 3.0+에서는 CeleryExecutor를 사용하면 worker가 webserver에 호출될 때 execution API endpoint로 호출되므로,
API가 아래와 같이 airflow.cfg에 추가가 되어야 합니다:
[core] execution_api_server_url = http://<your-webserver-host>:8080
그래서 처음 초반에 <url>:8080으로 설정해놨었는데
default(주석처리)라면 endpoint path에 <base_url>/execution/ 이 붙겠지만,
custom하게 설정하면 뒤에 /execution/을 붙여주어야 했습니다.[core]
execution_api_server_url = http://<url>:8080/execution/
그래서 제가 마주한 에러를 순서대로 나열하자면, 이렇게 정리해 볼 수 있을 것 같습니다.
host not found > scheduler mark task state fail > no worker instace recorded> scheduler log not_found in serialized_dag table
에러 해결 과정에서 등록한 github issue도 공유합니다!
https://github.com/apache/airflow/issues/50866remote logging for s3 fails while still looking for internal logs · Issue #50866 · apache/airflow
Apache Airflow version 3.0.1 If "Other Airflow 2 version" selected, which one? No response What happened? After upgrading to airflow 3.0.1, remote logging is not working as intended. I have set air...
github.com
- 이상 오늘의 삽질일기 끄읏🌞여기저기 삽질도 해보고
날려도 먹으면서
배우는 게
결국 남는거다
- Z.Sabziller
반응형'Airflow' 카테고리의 다른 글
[Airflow] Airflow db 업그레이드 에러 해결(feat. 2.10.0 버전) (4) 2024.10.29 [Airflow] Airflow dag 추가 에러 현상 (0) 2024.02.24 [Airflow] Airflow DAG runs 개수 주기적으로 삭제하기 (0) 2023.08.01 [Airflow] Airflow-s3 remote logging 설정 방법 (0) 2023.03.31 [Airflow] Airflow ExternalTaskSensor 활용법(feat. DAG Dependency) (0) 2023.02.07