<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <id>https://your-docusaurus-test-site.com/blog</id>
    <title>Dev Logs Blog</title>
    <updated>2023-11-24T00:00:00.000Z</updated>
    <generator>https://github.com/jpmonette/feed</generator>
    <link rel="alternate" href="https://your-docusaurus-test-site.com/blog"/>
    <subtitle>Dev Logs Blog</subtitle>
    <icon>https://your-docusaurus-test-site.com/img/favicon.ico</icon>
    <entry>
        <title type="html"><![CDATA[Airflow Variable.get() 反思]]></title>
        <id>/2023/11/24/</id>
        <link href="https://your-docusaurus-test-site.com/blog/2023/11/24/"/>
        <updated>2023-11-24T00:00:00.000Z</updated>
        <summary type="html"><![CDATA[.]]></summary>
        <content type="html"><![CDATA[<p>最近在重构Airflow中大量的DAG，其中最主要的目的是添加DAG Validation的测试。Airflow中有现成的dagbag.import_errors(),但是最大的问题时dag中有大量的Variable.get(),每次解析dag代码的时候，它都会连接数据库，显然不符合unit test的原则。</p><p>所以不得不移除代码中的Variable.get()，也就是Airflow文档中的所说的top level code。可以使用{{ var.value.xxx }}，前提是Operator中的template_fields中支持</p><p>有几个难点无法直接用    </p><ul><li>对于DAG factory，如果使用了Variable.get()，则直接替换成{{ var.value.xxx }}</li><li>有的Operator，template_field不支持{{ var.value.xxx }}</li></ul><p>解决方案：</p><ul><li>使用Environment Variable来替换Variable.get()</li></ul><p>反思：
Variable.get()的最大优点是可以让用户直接通过UI来变更一些参数来灵活的改变DAG的行为，但是现实中大量的用户直接把secret之类的
数据也往Variable里边加，造成了一定的泄露风险。</p><p>平台团队应该</p><ul><li><strong>CI 中加入措施来防止top level代码中出现Variable.get</strong></li><li><strong>提供更好的access control来防止用户滥用Variable</strong></li></ul>]]></content>
        <author>
            <name>Y Wang</name>
            <uri>https://github.com/csimplestring</uri>
        </author>
        <category label="Airflow" term="Airflow"/>
    </entry>
</feed>