气流作业电子邮件通知设置

我们使用的 SMTP 服务基于 AWS 简单电子邮件服务 (SES),我们更新了气流配置文件以包含主机名、smtp 用户和密码、端口号、邮件地址等。

这是我们在配置文件中设置的方式。邮件发件人地址是一个 google 群组,其域归我们的 SES 服务所有,并已通过我们使用的 SES 验证。

[email]
email_backend = airflow.utils.email.send_email_smtp

[smtp]

# If you want airflow to send emails on retries,failure,and you want to use
# the airflow.utils.email.send_email_smtp function,you have to configure an
# smtp server here
smtp_host = email-smtp.us-west-2.amazonaws.com
smtp_starttls = True
smtp_ssl = False
# Example: smtp_user = airflow
smtp_user = <user name>
# Example: smtp_password = airflow
smtp_password = <password>
smtp_port = 587
smtp_mail_from = <verified email service> (this is verified on SES)

在 DAG 作业中,我们设置了 send_email_smtp 函数的参数如下

args = {
    'owner': 'airflow','email': ['*******s5t8@salesforceiq.slack.com'],(this reciepient address is also verified,basically if you send email to this address,the slack channel will get notified)
    'depends_on_past': False,'start_date': datetime(2021,5,2),'end_date':datetime(2021,6,2)
}

然后我添加了一个应该失败并发送电子邮件的 DAG 作业,但是在日志文件中,由于此错误,电子邮件没有成功发送

[2021-05-06 21:22:46,787] {{taskinstance.py:1194}} INFO - Marking task as FAILED. dag_id=testemaildag,task_id=fail_task,execution_date=20210506T212242,start_date=20210506T212246,end_date=20210506T212246
[2021-05-06 21:22:46,804] {{configuration.py:338}} WARNING - section/key [smtp/smtp_user] not found in config
[2021-05-06 21:22:46,804] {{taskinstance.py:1200}} ERROR - Failed to send email to: ['v8i4h9j3e2n1s5t8@salesforceiq.slack.com']
[2021-05-06 21:22:46,805] {{taskinstance.py:1201}} ERROR - [Errno 99] Cannot assign requested address
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/airflow/models/taskinstance.py",line 984,in _run_raw_task
    result = task_copy.execute(context=context)
  File "/usr/local/lib/python3.7/dist-packages/airflow/operators/python_operator.py",line 113,in execute
    return_value = self.execute_callable()
  File "/usr/local/lib/python3.7/dist-packages/airflow/operators/python_operator.py",line 118,in execute_callable
    return self.python_callable(*self.op_args,**self.op_kwargs)
  File "/mnt/apps/airflow_dags/test_alert2.py",line 11,in throwerror
    raise ValueError("Failure")
ValueError: Failure

我在网上搜索了此错误并找到了相关答案 (https://stackoverflow.com/a/64330227/4240869),但我不太明白我应该添加的修复程序以使其正常工作。 就我而言,气流服务在容器中运行,因此我测试了一些快速修复,包括

  1. 在此处公开 Dockerfile 中的 587 端口
  2. 也在 nomad 作业中添加端口 587 作为保留端口

这是在我进行更改之后,为 docker 映像公开的 587 端口和主机上的端口 587 正在侦听它。但是,我在测试作业失败通知时仍然看到相同的错误。

# docker ps
CONTAINER ID   IMAGE                                                                 COMMAND                  CREATED             STATUS             PORTS                                                                                                                            NAMES
<container id>   <image tag>                       "/entrypoint.sh webs…"   2 minutes ago       Up 2 minutes       10.27.0.119:587->587/tcp,10.27.0.119:587->587/udp,5555/tcp,10.27.0.119:8080->8080/tcp,10.27.0.119:8080->8080/udp,8793/tcp   airflow-webserver-098d9c23-c6f5-0c85-f970-83e8e5ab9fc6 

我发现了一个与我的案例 (https://github.com/puckel/docker-airflow/issues/338) 类似的 Github 问题,看起来它尚未解决。我想知道这是否是尚未解决的已知问题。

iCMS 回答:气流作业电子邮件通知设置

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/107997.html

大家都在问