如何让带有日志错误 FileNotFound 的 dbt 运行 触发非 0 的退出代码?

How to have dbt run with log error FileNotFound to trigger an exit code that isn't 0?

我们正在 运行宁 dbt 版本 0.16.1。我们已经在 Airflow 中将数据管道设置为 运行,并设置了一个库以将每个 dbt 模型 运行 映射到 Airflow 上它自己的 bash 运算符中。

执行的dbt运行命令如下:

cd /usr/local/airflow/models/[PACKAGE_NAME] && dbt --log-format json run --models [MODEL_NAME]--no-version-check --profiles-dir=/usr/local/airflow/dags/dags-enterprise-model/enterprise_model/include --target=[TARGET] --profile=[PROFILE]

偶尔(可能当两个模型同时 运行 时),Airflow 会在 dbt run 命令中显示以下消息:

INFO - FileNotFoundError: [Errno 2] No such file or directory: 'logs/dbt.log' -> 'logs/dbt.log.1'

这是有问题的,因为日志文件没有得到更新,但任务的退出代码列为 0:

Command exited with return code 0

这会导致 Airflow 将任务标记为成功;但是,日志没有打印成功。

我的问题:

  1. 有没有办法将这些错误作为实际错误提出?
  2. 否则,有没有办法指定一个唯一的日志文件?

我不确定这是我理解上的差距,还是 dbt 日志记录中的错误,或者两者兼而有之?

这听起来确实是同时多次调用 dbt 并写入相同文件的结果。这不是 dbt 错误,因为我们不打算同时调用 dbt;单个调用可以通过线程处理并发模型运行。日志冲突是将 dbt 的模型 DAG 重新实现为 Airflow DAG 的风险之一。

这些都是公平的问题:

  1. 历史上,dbt 仅使用两个日志级别:debuginfo。请参阅相关问题的评论:dbt#2680. I totally appreciate that Airflow and other orchestration tools have well defined notification behaviors when presented with different log levels. A community member actually just opened a PR to add error-level logging (dbt#2723).

  2. 可以使用 dbt_project.yml (docs)

    中的 log-path 配置为 dbt 调用设置自定义日志路径