DAG在Google Cloud Composer网络服务器上不可单击,但在本地Airflow上工作正常 [英] DAGs not clickable on Google Cloud Composer webserver, but working fine on a local Airflow
问题描述
我正在使用
正如我所解释的那样,DAG不可单击,并且最近任务和 DAG运行列将永久加载。每个DAG名称旁边的信息标记表示:此DAG在网络服务器的DagBag对象中不可用。它显示在此列表中是因为调度程序将其标记为在元数据数据库中处于活动状态。
当然,刷新没有用,何时刷新通过直接URL( https://****.appspot.com/admin/airflow/graph?dag_id = my_dag_1
)访问DAG Graph View,它显示了一个错误: DAG my_dag_1似乎丢失。
本地气流结果
在本地Airflow上导入脚本时,Web服务器可以正常工作:
一些测试
如果我替换行 entries = gcs_conn.list(存储桶,前缀= prefix)
带有硬编码的值,例如 entries = [u'my_dag_1',u'my_dag_2',u'my_dag_3',u'my_dag_4']
,然后在Composer Web UI上单击DAG(并且出现链接列上的所有按钮)。看来,从我对最初的问题进行的其他测试来看,从钩子中调用方法(不仅仅是初始化钩子)会导致问题。当然,Composer中的DAG可以在简单的示例上正常工作(不涉及任何钩子方法调用。)
我不知道为什么会这样,我还检查了日志(通过在 airflow.cfg
中设置 logging_level = DEBUG
),但看不到任何错误。我怀疑网络服务器中存在错误,但无法获得大量堆栈跟踪信息。无法使用来自Composer(托管在App Engine上)的Web服务器日志,或者至少我没有找到访问它们的方法。
有人遇到过相同或类似的问题吗?有Composer Web UI吗?我认为问题出在钩子的使用上,但我可能是错的。这可能只是副作用。老实说,我在测试了很多东西后迷路了。如果有人可以帮助我,我会很高兴。谢谢!
更新
在Kubernetes上按照本指南部署自管理Web服务器时: https://cloud.google.com/composer/docs/how-to/managing / deploy-webserver ,我的DAG可以从此自我管理的Web服务器上单击。
Composer Web服务器运行与Composer GKE群集中的节点不同的服务帐户。您应该确保已为网络服务器的服务帐户分配了适当的角色/权限。
例如如果您的网络服务器的网址是:
foo-tp.appspot.com
然后该服务帐户为:
foo-tp @ appspot.gserviceaccount.com
I'm using Google Cloud Composer (managed Airflow on Google Cloud Platform) with image version composer-0.5.3-airflow-1.9.0
and Python 2.7, and I'm facing a weird issue : after importing my DAGs, they are not clickable from the Web UI (and there are no buttons "Trigger DAG", "Graph view", ...), while all works perfectly when running a local Airflow.
Even if non usable from the webserver on Composer, my DAGs still exist. I can list them using CLI (list_dags
), describe them (list_tasks
) and even trigger them (trigger_dag
).
Minimal example reproducing the issue
A minimal example I used to reproduce the issue is shown below. Using a hook (here, GoogleCloudStorageHook
) is very important, since the bug on Composer happens when a hook is used. Initially, I was using a custom hook (in a custom plugin), and was facing the same issue.
Basically here, the example lists all entries in a GCS bucket (my-bucket
) and generate a DAG for each entry beginning with my_dag
.
import datetime
from airflow import DAG
from airflow.contrib.hooks.gcs_hook import GoogleCloudStorageHook
from airflow.operators.bash_operator import BashOperator
google_conn_id = 'google_cloud_default'
gcs_conn = GoogleCloudStorageHook(google_conn_id)
bucket = 'my-bucket'
prefix = 'my_dag'
entries = gcs_conn.list(bucket, prefix=prefix)
for entry in entries:
dag_id = str(entry)
dag = DAG(
dag_id=dag_id,
start_date=datetime.datetime.today(),
schedule_interval='0 0 1 * *'
)
op = BashOperator(
task_id='test',
bash_command='exit 0',
dag=dag
)
globals()[dag_id] = dag
Results on Cloud Composer
After importing this file to Composer, here's the result (I have 4 files beginning with my_dag
in my-bucket
) :
As I explained, DAGs are not clickable and the columns "Recent Tasks" and "DAG Runs" are loading forever. The "info" mark next to each DAG name says : This DAG isn't available in the webserver DagBag object. It shows up in this list because the scheduler marked it as active in the metadata database
.
Of course, refreshing is not useful, and when accessing the DAG Graph View by the direct URL (https://****.appspot.com/admin/airflow/graph?dag_id=my_dag_1
), it shows an error : DAG "my_dag_1" seems to be missing.
Results on local Airflow
When importing the script on a local Airflow, the webserver works fine :
Some tests
If I replace the line entries = gcs_conn.list(bucket, prefix=prefix)
with hard-coded values like entries = [u'my_dag_1', u'my_dag_2', u'my_dag_3', u'my_dag_4']
, then DAGs are clickable on Composer Web UI (and all buttons on "links" columns appear). It seems that, from other tests I have made on my initial problem, calling a method from a hook (not just initializing the hook) causes the issue. Of course, DAGs in Composer work normally on simple examples (no hooks method calls involved).
I have no idea why this happened, I have also inspected the logs (by setting logging_level = DEBUG
in airflow.cfg
) but could not see something wrong. I'm suspecting a bug in the webserver, but I cannot get a significant stack trace. Webserver logs from Composer (hosted on App Engine) are not available, or at least I did not find a way to access them.
Did someone experienced the same issue or similar ones with Composer Web UI ? I think the problem is coming from the usage of hooks, but I may be wrong. It can just be a side effect. To be honest, I am lost after testing so many things. I'll be glad if someone can help me. Thanks!
Update
When deploying a self-managed webserver on Kubernetes following this guide : https://cloud.google.com/composer/docs/how-to/managing/deploy-webserver, my DAGs are clickable from this self-managed webserver.
The Composer webserver runs with a different service account than the nodes in the Composer GKE cluster. You should make sure you have assigned the appropriate role/permissions to your webserver's service account.
E.g. if your webserver's url is:
foo-tp.appspot.com
then the service account is:
foo-tp@appspot.gserviceaccount.com
这篇关于DAG在Google Cloud Composer网络服务器上不可单击,但在本地Airflow上工作正常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!