-
Notifications
You must be signed in to change notification settings - Fork 209
Supporting extended configuration files #524
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gyli
wants to merge
14
commits into
astronomer:main
Choose a base branch
from
gyli:extends_config
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
6c097b6
add support of extends
6c1509c
Merge branch 'main' of https://github.com/astronomer/dag-factory into…
02f7ee6
Merge main
2eac39d
Correct doc
0e8250f
fix unit test after merging
85f5fb9
Format codes
ce5f1b0
create constant
96168ec
Simplify the doc
d9331dd
Add new test covering the priority
1c348cc
Remove mentioning version number from the doc
5615eaf
Merge branch 'main' into extends_config
gyli ec4e007
Merge branch 'main' into extends_config
gyli c8857ca
use existing funcs and move extends logic out of _load_dag_config
304edb4
Merge branch 'main' into extends_config
gyli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
|
@@ -5,3 +5,4 @@ | |
AIRFLOW3_MAJOR_VERSION = 3 | ||
|
||
DEFAULTS_FILE_NAME = "defaults.yml" | ||
EXTENDS_KEY = "__extends__" |
This file contains hidden or 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 hidden or 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 hidden or 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,19 @@ | ||
import os | ||
from pathlib import Path | ||
|
||
# The following import is here so Airflow parses this file | ||
# from airflow import DAG | ||
import dagfactory | ||
|
||
DEFAULT_CONFIG_ROOT_DIR = "/usr/local/airflow/dags/" | ||
CONFIG_ROOT_DIR = Path(os.getenv("CONFIG_ROOT_DIR", DEFAULT_CONFIG_ROOT_DIR)) | ||
|
||
# This config file demonstrates chained __extends__ functionality: | ||
# extends_example_dags.yml → extends_environment_specific.yml → extends_base.yml | ||
config_file = str(CONFIG_ROOT_DIR / "extends_example_dags.yml") | ||
|
||
example_dag_factory = dagfactory.DagFactory(config_file) | ||
|
||
# Creating task dependencies | ||
example_dag_factory.clean_dags(globals()) | ||
example_dag_factory.generate_dags(globals()) |
This file contains hidden or 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,17 @@ | ||
default: | ||
default_args: | ||
owner: "base_owner" | ||
start_date: "2024-01-01" | ||
retries: 1 | ||
retry_delay_sec: 300 | ||
email_on_failure: false | ||
email_on_retry: false | ||
schedule_interval: "@daily" | ||
catchup: false | ||
max_active_runs: 1 | ||
dagrun_timeout_sec: 3600 | ||
default_view: "tree" | ||
orientation: "LR" | ||
tags: | ||
- "dag-factory" | ||
- "base" |
This file contains hidden or 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,16 @@ | ||
__extends__: | ||
- "extends_base.yml" | ||
|
||
default: | ||
default_args: | ||
owner: "dev_team" | ||
retries: 3 | ||
retry_delay_sec: 180 | ||
email_on_failure: true | ||
email: ["[email protected]"] | ||
schedule_interval: "0 8 * * *" # 8 AM daily | ||
max_active_runs: 2 | ||
dagrun_timeout_sec: 7200 # 2 hours | ||
tags: | ||
- "development" | ||
- "etl" |
This file contains hidden or 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,48 @@ | ||
__extends__: | ||
- "extends_environment_specific.yml" | ||
|
||
# Override some defaults for this specific set of DAGs | ||
default: | ||
default_args: | ||
owner: "data_engineering_team" | ||
tags: | ||
- "production" | ||
- "daily_etl" | ||
|
||
# Define actual DAGs | ||
data_ingestion_dag: | ||
description: "Daily data ingestion from external sources" | ||
default_args: | ||
retries: 5 # Override for this specific DAG | ||
tasks: | ||
extract_source_a: | ||
operator: airflow.operators.bash_operator.BashOperator | ||
bash_command: "echo 'Extracting from source A'" | ||
extract_source_b: | ||
operator: airflow.operators.bash_operator.BashOperator | ||
bash_command: "echo 'Extracting from source B'" | ||
transform_data: | ||
operator: airflow.operators.bash_operator.BashOperator | ||
bash_command: "echo 'Transforming data'" | ||
dependencies: [extract_source_a, extract_source_b] | ||
load_data: | ||
operator: airflow.operators.bash_operator.BashOperator | ||
bash_command: "echo 'Loading data to warehouse'" | ||
dependencies: [transform_data] | ||
|
||
data_quality_dag: | ||
description: "Data quality checks on ingested data" | ||
schedule_interval: "0 10 * * *" # 10 AM daily, after ingestion | ||
default_args: | ||
owner: "data_quality_team" | ||
tasks: | ||
check_row_counts: | ||
operator: airflow.operators.bash_operator.BashOperator | ||
bash_command: "echo 'Checking row counts'" | ||
check_data_freshness: | ||
operator: airflow.operators.bash_operator.BashOperator | ||
bash_command: "echo 'Checking data freshness'" | ||
generate_quality_report: | ||
operator: airflow.operators.bash_operator.BashOperator | ||
bash_command: "echo 'Generating quality report'" | ||
dependencies: [check_row_counts, check_data_freshness] |
This file contains hidden or 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,33 @@ | ||
__extends__: | ||
- "extends_base.yml" | ||
- "extends_environment_specific.yml" | ||
|
||
# This demonstrates extending from multiple files at once | ||
# Later files in the extends list take precedence over earlier ones | ||
# So extends_environment_specific.yml will override extends_base.yml | ||
|
||
default: | ||
default_args: | ||
owner: "multiple_inheritance_team" | ||
tags: | ||
- "multi-extend" | ||
- "demo" | ||
|
||
reporting_dag: | ||
description: "Example DAG demonstrating multiple inheritance through __extends__" | ||
schedule_interval: "0 6 * * *" # 6 AM daily | ||
tasks: | ||
gather_metrics: | ||
operator: airflow.operators.bash_operator.BashOperator | ||
bash_command: "echo 'Gathering system metrics'" | ||
process_logs: | ||
operator: airflow.operators.bash_operator.BashOperator | ||
bash_command: "echo 'Processing application logs'" | ||
generate_dashboard: | ||
operator: airflow.operators.bash_operator.BashOperator | ||
bash_command: "echo 'Generating daily dashboard'" | ||
dependencies: [gather_metrics, process_logs] | ||
send_notifications: | ||
operator: airflow.operators.bash_operator.BashOperator | ||
bash_command: "echo 'Sending notifications to stakeholders'" | ||
dependencies: [generate_dashboard] |
This file contains hidden or 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 hidden or 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,15 @@ | ||
__extends__: | ||
- extends_base.yml | ||
|
||
default: | ||
default_args: | ||
owner: main_owner # This should override the base owner | ||
email: [email protected] # This should be added to the base config | ||
schedule_interval: "@hourly" # This should override the base schedule | ||
|
||
example_dag_with_extends: | ||
description: "DAG created with extends functionality" | ||
tasks: | ||
task_1: | ||
operator: airflow.operators.bash.BashOperator | ||
bash_command: echo "Hello from extended config" |
This file contains hidden or 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,19 @@ | ||
__extends__: | ||
- dag_factory_extends.yml | ||
|
||
default: | ||
default_args: | ||
owner: chained_owner # This should override both base and main config | ||
depends_on_past: false # This should be added | ||
end_date: 2023-12-31 # From the intermediate layer | ||
email_on_failure: true # From the intermediate layer | ||
max_active_runs: 1 # This should override the base value | ||
dagrun_timeout_sec: 1800 # From the intermediate layer | ||
orientation: TB # From the intermediate layer | ||
|
||
example_dag_chained_extends: | ||
description: "DAG created with chained extends functionality" | ||
tasks: | ||
task_1: | ||
operator: airflow.operators.bash.BashOperator | ||
bash_command: echo "Hello from chained extended config" |
This file contains hidden or 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,10 @@ | ||
default: | ||
default_args: | ||
owner: base_owner | ||
retries: 2 | ||
retry_delay_sec: 600 | ||
start_date: 2023-01-01 | ||
concurrency: 5 | ||
max_active_runs: 3 | ||
default_view: graph | ||
schedule_interval: "@daily" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this documentation would have to live in "### Combining multiple
defaults.yml
files", and we'd either replace the current description or we'd have both as sub-cases of this broader approach.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having both as sub-cases is exactly what I tried to do here. It has these H2 level title: