[TIL] Airflow의 다양한 고급 기능과 CI / CD 환경에 대해 학습 (2)

이원진·2023년 6월 27일
0

데브코스

목록 보기
52/54
post-thumbnail

학습내용


  1. 구글 시트 Redshift 테이블로 복사하기

  2. SQL 결과 구글 시트로 복사하기

  3. API & Airflow 모니터링

1. 구글 시트 Redshift 테이블로 복사하기



  • 스프레드시트 API를 활성화하고, 구글 서비스 어카운트를 생성해 그 내용을 JSON으로 다운로드

    • 해당 JSON 파일의 내용을 google_sheet_access_token이란 이름의 Variable로 등록

    • 해당 JSON 파일 내의 이메일 주소를 스프레드시트 파일에 공유

  • Airflow DAG쪽에서 해당 JSON 파일로 인증하고, 시트 조작

2. SQL 결과 구글 시트로 복사하기


  • gcp_conn_id라는 이름으로 Google Cloud Connection을 하나 생성

    • Admin → Connections → + 버튼

  • 앞서 서비스 어카운트 JSON 파일의 내용을 Keyfile JSON에 복사


3. API & Airflow 모니터링


  • Airflow API 활성화

    • airflow.cfg의 api 섹션에서 auth_backend의 값을 아래와 같이 변경

      [api]
      auth_backend = airflow.api.auth.basic_auth

    • Airflow 웹 UI에서 새로운 API 사용자 추가

      • Security → List Users → + 버튼

    • Health API 호출

      • curl -X GET --user “monitor:MonitorUser1” http://localhost:8080/health

      • 정상 응답
        {
        	 "metadatabase": {
        		 "status": "healthy"
        	 },
        	 "scheduler": {
        		 "status": "healthy",
        		 "latest_scheduler_heartbeat": "2022-03-12T06:02:38.067178+00:00"
        	 }
        }

  • API 사용 예시

    • 특정 DAG를 API로 트리거

      • curl -X POST --user “airflow:airflow” -H ‘Content-Type: application/json’ -d ‘{”execution_date”:”2023-05-24T00:00:00Z”}’ “http://localhost:8080/api/v1/HelloWorld/dagRuns”

    • 모든 DAG 리스트

      • curl -X GET --user “airflow:airflow” http://localhost:8080/api/v1/dags

    • 모든 Variable 리스트

      • curl -X GET --user “airflow:airflow” http://localhost:8080/api/v1/variables

  • Variables[Connections] Import[Export]

    • airflow variables[connections] import[export] variables.json[connections.json]

메모



0개의 댓글