https://airflow.apache.org/docs/apache-airflow/stable/upgrading-from-1-10/index.html
Upgrading from 1.10 to 2 — Airflow Documentation
airflow.apache.org
공식 문서가 존재한다.
현재 쓰는 건 1.10.15인데, 이걸 2.3.4로 올려야 한다.
2.3버전대부터는 파이썬 3.6을 지원하지 않아서 3.7이상을 써야하고, 1.10에서 2로 바로 올릴 수 없어서 브릿지 버전인 1.10.15가 존재하는데, 다행스럽게도 나는 1.10.15를 쓰고 있어서 따로 설치해줄 필요가 없다.
사실 list_dags을 쓰면서 왜 1버전대가 2버전 얘기를 하나 했는데, 문서에 1.10.15가 브릿지 버전이라고 해서 그제서야 이해했다.
# airflow version
1.10.15
# airflow list_dags
The 'list_dags' command is deprecated and removed in Airflow 2.0, please use 'dags list', or 'dags report' instead
업그레이드 체크 스크립트를 지원해줘서 현재 설정(airflow.cfg)과 DAG들이 업그레이드시 어떤 문제가 있을지 보고서를 생성해준다.
# pip install apache-airflow-upgrade-check
# airflow upgrade_check
보고서 확인 후에 2.3.4를 설치했는데, 파이썬 3.7에서 psycopg2 ImportError: undefined symbol: PQconninfo 오류가 나서 그냥 파이썬 3.8.12에서 설치 했다. (구글클라우드 문서에는 3.8 쓰라고 한 게 이런 이유였나 싶다.)
mkdir 설치경로
export AIRFLOW_HOME=설치경로
pip3 install "apache-airflow==2.3.4" --constraint "https://raw.githubusercontent.com/apache/airflow/constraints-2.3.4/constraints-3.8.txt" --ignore-installed
airflow version으로 2.3.4가 나오는 걸 확인 했고, 내 경우에는 보고서에 거의 아래 내용만 있어서 DAG들을 수정해야 했다.
Using `airflow.contrib.operators.ssh_operator.SSHOperator` should be replaced by `airflow.providers.ssh.operators.ssh.SSHOperator`.
Using `airflow.operators.http_operator.SimpleHttpOperator` should be replaced by `airflow.providers.http.operators.http.SimpleHttpOperator`.
Using `airflow.sensors.http_sensor.HttpSensor` should be replaced by `airflow.providers.http.sensors.http.HttpSensor`.
sed로 일괄 수정
sed -i 's/airflow.contrib.operators.ssh_operator/airflow.providers.ssh.operators.ssh/g' *.py
sed -i 's/airflow.operators.http_operator/airflow.providers.http.operators.http/g' *.py
sed -i 's/airflow.sensors.http_sensor/airflow.providers.http.sensors.http/g' *.py
위처럼 한 건, import를 from .... import HttpSensor 이런 식으로 하고 있어서 변경되는 부분만 하느라 위처럼 했다.
그리고 airflow db upgrade 실행 후 scheduler와 webserver를 실행 했는데, 웹UI로 접근해보니 기존 사용자 정보로 접속이 안 됐다.
airflow users list를 해보니 No data found... 혹시나 해서 dags list를 해보니 dags은 멀쩡했다.
아마 rbac = False로 쓰고 있어서 사용자 정보는 옮겨지지 않은 거 같다. (rbac 내용 참고: https://airflow.apache.org/docs/apache-airflow/stable/upgrading-from-1-10/index.html#step-5-upgrade-airflow-dags)
사용자는 그냥 새로 생성해주고, UI에 접속을 했는데,
airflow dags list-import-errors
위 커맨드로도 확인이 가능한데, 오류로 표기 되는 내용이 다 같았다.
airflow.exceptions.AirflowException: Invalid arguments were passed to SimpleHttpOperator (task_id: test). Invalid arguments were:
**kwargs: {'xcom_push': True}
xcom_push 때문이었고, 검색을 해보니 do_xcom_push로 바꾸면 돼서 그냥 변경했다.
https://forum.astronomer.io/t/xcom-push-will-be-deprecated-in-airflow-version-2-0/662
Xcom_push will be deprecated in Airflow version 2.0
Hi there, I noticed xcom_push in operators like PostgresOperator is deprecating in Airflow version 2.0. What is your take on this? How do we suppose to exchange information by the result set of select query with its downstream tasks where we want to use th
forum.astronomer.io
허나 이슈가 두 개가 더 있었는데,
While upgrading the metadatabase, Airflow had to move some bad data in order to apply new constraints. The moved data can be found in the following tables:
Source table Table with moved rows
task_fail _airflow_moved__2_3__dangling__task_fail
task_fail _airflow_moved__2_3__duplicates__task_fail
task_instance _airflow_moved__2_2__dangling__task_instance
Please inspect the moved data to decide whether you need to keep them, and manually drop the moved tables to dismiss this warning. Read more about it in Upgrading.
업그레이드 하느라 일부 잘못된 데이터를 옮겨버렸다는 얘기고, 저거 뜨는 거 보기 싫으면 지우라는 얘기였다.
SELECT해서 내용을 봐도 딱히 필요한 게 아니라서 DROP TABLE 하니까 안 뜸.
Do not use SequentialExecutor in production. Click here for more information.
이건 프로덕션에서는 executor를 SequentialExecutor로 쓰지 말라는 얘기. airflow.cfg에 executor기본적으로 들어 있던 설정 파일이라 원래 쓰던 CeleryExecutor로 변경해줌.
에어플로우 재시작 하면 설정이 적용 되는데, 웹UI가 뜨는 게 많이 느려서 뭐 잘못한줄 알았다.