-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
768 additions
and
83 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,99 @@ | |
|
||
[Apache Airflow](https://airflow.apache.org) utilities for for configuration of many DAGs and DAG environments | ||
|
||
[](https://github.com/airflow-laminar/airflow-config/actions?query=workflow%3A%22Build+Status%22) | ||
[](https://github.com/airflow-laminar/airflow-config/actions/workflows/build.yml) | ||
[](https://codecov.io/gh/airflow-laminar/airflow-config) | ||
[](https://github.com/airflow-laminar/airflow-config) | ||
[](https://pypi.python.org/pypi/airflow-config) | ||
|
||
## Overview | ||
|
||
This library allows for `YAML`-driven configuration of Airflow, including DAGs, Operators, and declaratively defined DAGs (à la [dag-factory](https://github.com/astronomer/dag-factory)). It is built with [Pydantic](https://pydantic.dev), [Hydra](https://hydra.cc), and [OmegaConf](https://omegaconf.readthedocs.io/). | ||
|
||
Consider the following basic DAG: | ||
|
||
```python | ||
from airflow import DAG | ||
from airflow.operators.bash import BashOperator | ||
from datetime import datetime, timedelta | ||
|
||
with DAG( | ||
dag_id="test-dag", | ||
default_args={ | ||
"depends_on_past": False, | ||
"email": ["[email protected]"], | ||
"email_on_failure": False, | ||
"email_on_retry": False, | ||
"retries": 0, | ||
}, | ||
description="test that dag is working properly", | ||
schedule=timedelta(minutes=1), | ||
start_date=datetime(2024, 1, 1), | ||
catchup=False, | ||
tags=["utility", "test"], | ||
): | ||
BashOperator( | ||
task_id="test-task", | ||
bash_command="echo 'test'", | ||
) | ||
``` | ||
|
||
We can already see many options that we might want to drive centrally via config, perhaps based on some notion of environment (e.g. `dev`, `prod`, etc). | ||
|
||
- `"email": ["[email protected]"]` | ||
- `"email_on_failure": False` | ||
- `"email_on_retry": False` | ||
- `"retries": 0` | ||
- `schedule=timedelta(minutes=1)` | ||
- `tags=["utility", "test"]` | ||
|
||
If we want to change these in our DAG, we need to modify code. Now imagine we have hundreds of DAGs, this can quickly get out of hand, especially since Airflow DAGs are Python code, and we might easily inject a syntax error or a trailing comma or other common problem. | ||
|
||
Now consider the alternative, config-driven approach: | ||
|
||
`config/config.yaml` | ||
|
||
```yaml | ||
# @package _global_ | ||
_target_: airflow_config.Configuration | ||
global_: | ||
_target_: airflow_config.GlobalDagConfiguration | ||
owner: test | ||
email: [[email protected]] | ||
email_on_failure: false | ||
email_on_retry: false | ||
retries: 0 | ||
depends_on_past: false | ||
schedule: "01:00" | ||
start_date: "2024-01-01" | ||
catchup: false | ||
tags: ["utility", "test"] | ||
``` | ||
```python | ||
from airflow import DAG | ||
from airflow.operators.bash import BashOperator | ||
from airflow_config import DAG, load_config | ||
|
||
config = load_config() | ||
|
||
with DAG(dag_id="test-dag", description="test that dag is working properly", config=config): | ||
BashOperator( | ||
task_id="test-task", | ||
bash_command="echo 'test'", | ||
) | ||
``` | ||
This has a number of benefits: | ||
- Make changes without code changes, with static type validation | ||
- Make changes across any number of DAGs without having to copy-paste | ||
- Organize collections of DAGs into groups, e.g. via enviroment like `dev`, `prod`, etc | ||
|
||
## Configuration | ||
|
||
More documentation coming soon! | ||
|
||
## License | ||
|
||
This software is licensed under the Apache 2.0 license. See the [LICENSE](LICENSE) file for details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
__version__ = "0.1.0" | ||
|
||
from .configuration import * | ||
from .exceptions import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .airflow import GlobalDagConfiguration, DagConfiguration | ||
from .base import Configuration, load_config | ||
from .python import PythonConfiguration |
Oops, something went wrong.