在气流上部署dag文件的有效方法 [英] Efficient way to deploy dag files on airflow

查看:59
本文介绍了在气流上部署dag文件的有效方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否将最佳实践部署到气流中来?

Are there any best practices that are followed for deploying new dags to airflow?

我在google论坛上看到了几条评论,指出这些dags已保存在GIT存储库中,并且定期将其同步到气流集群中的本地位置.
关于这种方法,我有几个问题

  • 我们是否为单独的环境维护单独的dag文件?(测试.生产)
  • 如果新版本存在错误,如何处理ETL回滚到旧版本?

    I saw a couple of comments on the google forum stating that the dags are saved inside a GIT repository and the same is synced periodically to the local location in the airflow cluster.
    Regarding this approach, I had a couple of questions

  • Do we maintain separate dag files for separate environments? (testing. production)
  • How to handle rollback of an ETL to an older version in case the new version has a bug?

    我们非常感谢您的帮助.如果您需要更多详细信息,请告诉我?

    Any help here is highly appreciated. Let me know in case you need any further details?

    推荐答案

    这是我们为团队管理的方式.

    Here is how we manage it for our team.

    首先,在命名约定方面,我们的每个 DAG文件名都与DAG本身(包括DAG版本)的内容中的 DAG ID 相匹配.这很有用,因为最终它是您在Airflow UI中看到的DAG ID,因此您将确切知道每个DAG后面使用了哪个文件.

    First in terms of naming convention, each of our DAG file name matches the DAG Id from the content of the DAG itself (including the DAG version). This is useful because ultimately it's the DAG Id that you see in the Airflow UI so you will know exactly which file has been used behind each DAG.

    像这样的DAG的示例:

    Example for a DAG like this:

    from airflow import DAG
    from datetime import datetime, timedelta
    
    default_args = {
      'owner': 'airflow',
      'depends_on_past': False,
      'start_date': datetime(2017,12,05,23,59),
      'email': ['me@mail.com'],
      'email_on_failure': True
    }
    
    dag = DAG(
      'my_nice_dag-v1.0.9', #update version whenever you change something
      default_args=default_args,
      schedule_interval="0,15,30,45 * * * *",
      dagrun_timeout=timedelta(hours=24),
      max_active_runs=1)
      [...]
    

    DAG文件的名称为: my_nice_dag-v1.0.9.py

    • 我们所有的DAG文件都存储在Git存储库中(除其他外)
    • 每次在master分支中完成合并请求时,Continuous Integration管道都会开始新的构建并将DAG文件打包为zip(我们使用Atlassian Bamboo,但还有其他解决方案,例如Jenkins,Circle CI,Travis ...)
    • 在Bamboo中,我们配置了一个部署脚本(外壳),该脚本解压缩程序包并将DAG文件放置在Airflow服务器上的/dags 文件夹中.
    • 我们通常将DAG部署在DEV中进行测试,然后部署到UAT,最后部署到PROD.借助上面提到的shell脚本,只需在Bamboo UI中单击一个按钮即可完成部署.

    好处

    1. 由于在文件名中包含了DAG版本,因此DAG文件夹中的DAG文件的先前版本不会被覆盖,因此您可以轻松地返回到它.
    2. 当新的DAG文件加载到Airflow中时,由于版本号的原因,您可以在UI中识别它.
    3. 由于您的DAG文件名= DAG ID,您甚至可以通过添加一些Airflow命令行来改进部署脚本,以在新DAG部署后自动将它们打开.
    4. 由于DAG的每个版本都已在Git中进行了历史化,因此如果需要,我们总是可以恢复到以前的版本.

    这篇关于在气流上部署dag文件的有效方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆