터칭 데이터

Airflow 운영과 대안 본문

Airflow 고급 기능, dbt, Data Catalog

Airflow 운영과 대안

터칭 데이터 2024. 1. 4. 02:12

 

 

 

3. Airflow 운영과 대안

 

Airflow 운영과 대안에 대해 배워보자

 

 

 

 

 

 

 

 

프로덕션 사용을 위한 Airflow 환경설정

 

 

 

 

 

 

 

 

 

Things to Change (1)

 

airflow.cfg is in /var/lib/airflow/airflow.cfg

Any changes here will be reflected when you restart the webserver and scheduler
[core] 섹션의 dags_folder가 DAG들이 있는 디렉토리가 되어야함
    - /var/lib/airflow/dags
dag_dir_list_interval: dags_folder를 Airflow가 얼마나 자주 스캔하는지 명시 (초 단위)

 

Airflow Database upgrade (Airflow 설치때 설명)

Sqlite -> Postgres or MySQL (이 DB는 주기적으로 백업되어야함)
sql_alchemy_conn in Core section of airflow.cfg

 

SequentialExecutor 사용 (Airflow 설치때 설명)

Executor in Core section of airflow.cfg
Single Server: from SequentialExecutor to LocalExecutor or CeleryExecutor
    - Cluster: from SequentialExecutor to CeleryExecutor or KubernetesExecutor

 

 

 

 

 

 

 

 

Things to Change (2)

 

Enable Authentication & use a strong password

In Airflow 2.0, authentication is ON by default
되도록이면VPN (Virtual Private Network) 뒤에 위치

 

Large disk volume for logs and local data

Logs -> /dev/airflow/logs in (Core section of airflow.cfg)

    - base_log_folder
    - child_process_log_directory
Local data -> /dev/airflow/data


Periodic Log data cleanup

The above folders need to be cleaned up periodically (아니면 S3와 같은 클라우드 스토리지로 복사)
You can write a shell Operator based DAG for this purpose

 

 

 

 

 

 

 

 

Things to Change (3)

 

From Scale Up to Scale Out

Go for Cloud Airflow options (Cloud Composer or MWAA) or Docker/K8s


Backup Airflow metadata database

Backup variables and connections (command lines or APIs)
    - airflow variables export variables.json
    - airflow connections export connections.json


Add health-check monitoring

https://airflow.apache.org/docs/apache-airflow/stable/logging-monitoring/check-health.html
    - API를 먼저 활성화하고 Health Check Endpoint API를 모니터링 툴과 연동
    - 앞서 설명
어느 정도 규모가 된다면 DataDog, Grafana등을 사용하는 것이 일반적 (DevOps팀과 협업)

 

 

 

 

 

 

 

 

 

 

 

GCP’s Cloud Composer Screenshots

 

 

 

 

 

 

 

 

 

 

 

 

 

Amazon MWAA

 

 

 

 

 

 

 

 

 

 

 

 

Microsoft Azure: Data Factory

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Airflow 로그 파일 삭제하기


Airflow에서 발생되는 로그파일의 크기는 작지 않다. 이를 주기적으로 삭제하거나 백업하는 것에 대해 알아보자

 

 

 

 

 

 

 

 

 

Airflow 로그 위치


두 군데에 별도의 로그가 기록됨. 이를 주기적으로 삭제하거나 백업 (s3) 필요

 

 

[logging]
# The folder where airflow should store its log files
# This path must be absolute
base_log_folder = /var/lib/airflow/logs

 

[scheduler]
child_process_log_directory = /var/lib/airflow/logs/scheduler

 

 

 

 

 

 

 

 

 

Airflow 로그 위치 - docker compose

 

docker compose로 실행된 경우 logs 폴더가 host volume의 형태로 유지

 

volumes:
 - ${AIRFLOW_PROJ_DIR:-.}/dags:/opt/airflow/dags
 - ${AIRFLOW_PROJ_DIR:-.}/logs:/opt/airflow/logs

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Airflow 메타데이터 백업하기


Airflow 메타데이터 DB를 주기적으로 백업하는 방법에 대해 알아보자

 

 

 

 

 

 

 

 

Airflow 메타데이터의 주기적인 백업

 

이 데이터베이스가 외부에 있다면 (특히 AWS RDS라면)

거기에 바로 주기적인 백업 셋업

 

Airflow와 같은 서버에 메타 데이터 DB가 있다면 (예를 들어 PostgreSQL)

그러면 DAG등을 이용해 주기 백업 실행 (S3로 저장)

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Airflow 대안


Airflow 말고 다른 ETL 프레임웍으로 무엇이 있는지 살펴보자

 

 

 

 

 

 

 

Airflow 이외의 다른 데이터 파이프라인 프레임웍들

 

Prefect (Open Source)

 

Dagster (Open Source)

 

Airbyte (Open Source)

 

SaaS 형태의 데이터 통합 툴들

FiveTran
Stitch Data
Segment

 

 

 

 

 

 

 

 

 

 

Prefect

Open-Source

 

Airflow와 상당히 흡사하며 좀더 경량화된 버전

 

데이터 파이프라인을 동적으로 생성할 수 있는 강점이 있음

 

 

 

 

 

 

 

 

 

Dagster: 데이터 파이프라인과 데이터를 동시 관리

 

 

 

 

 

 

 

 

 

 

 

 

Airbyte: 코딩 툴이라기 보다는 Low-Code 툴에 가까움

 

 

 

 

 

 

'Airflow 고급 기능, dbt, Data Catalog' 카테고리의 다른 글

DBT - 사용 시나리오  (0) 2024.01.04
DBT - Database Normalization  (0) 2024.01.04
Dynamic Dags  (0) 2024.01.03
Task Groups  (0) 2024.01.03
Airflow DB 살펴보기  (0) 2024.01.03