<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
    <channel>
        <title>Dev Logs Blog</title>
        <link>https://your-docusaurus-test-site.com/blog</link>
        <description>Dev Logs Blog</description>
        <lastBuildDate>Fri, 24 Nov 2023 00:00:00 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <language>zh-Hans</language>
        <item>
            <title><![CDATA[Airflow Variable.get() 反思]]></title>
            <link>https://your-docusaurus-test-site.com/blog/2023/11/24/</link>
            <guid>/2023/11/24/</guid>
            <pubDate>Fri, 24 Nov 2023 00:00:00 GMT</pubDate>
            <description><![CDATA[.]]></description>
            <content:encoded><![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:encoded>
            <category>Airflow</category>
        </item>
    </channel>
</rss>