You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 10 Next »

Status

StateDraft
Discussion Thread

Email: tbd.

Slack: #sig-examples

Vote Threadtbd.
Vote Result Threadtbd.
Progress Tracking (PR/GitHub Project/Issue Label)
Date Created

 

Version Releasedtbd.
Authors

Motivation

Airflow Examples have been grown in number and focus over the past years. They purpose multiple things:

  • Serve as tutorials to learn Airflow DAG implementation
  • Serve with code snippets for documentation
  • Serve for testing the setup
  • (some) service for CI integration testing

Some example DAGs are in a good quality, some are not following best practices. Current examples do not follow a structure.

There are example DAGs contained in the Airflow core (currently pushed to standard provider/example_dags) as well as there are more examples in other providers. But examples from other providers are lot loaded automatically.

So in the Airflow 3 Dev Calls there was a demand named to clean-up and optimize example DAGs.

Considerations / Targets

  • The number of examples should be reduced to 20-30
    • If possible examples from docs should be represented in examples. Some code examples which are stand-alone in code should be moved into examples if possible.
    • Otherwise example content not referenced in documentation might be questioned if beneficial
  • Examples should be arranged along a story-line if possible which might represent a virtual company and support real-life use cases. Might be good if we can structure it as growth of use-cases bringing in need for more features. i.e. starting off basic transformation → needing more complex task so using groups → using sensors, assets... showing progression of usage with project/company maturity. 
  • Examples should follow best practices in coding
  • Existing examples should be reviewed which DAGs are just used for testing. Testing DAGs should be separated and not pollute the example collection
  • Some examples are specific for providers. They should be moved to provider packages
  • A mechanism is to be created that uses DAG bundle loading mechanism to load example DAGs from providers w/o need to copy them to global examples.
  • Same like today if loading of example DAGs is enabled also needed plugins e.g. timetables should be usable out-of-the-box
  • (more tbd?)

Storyline

Note

tbd. - creative ideas welcome.

Current ideas collection:

  • "Tailwind" - A virtual / non existing wind park energy company that powers a farm of win-mills to produce clean energy. The company has a strong demand to ETL sensor data from the windmills as well as need to act on data events when base data changes or contracts with customers renew. The company values also the DEI rules and has sustainable targets for clean energy and CO2 reduction.

Technical Work Packages → Features

WIP

Work in progress

  • --load-example-dags must load examples from standard provider at least in Airflow 3.1 (same like in breeze hack today)
  • Testing DAGs must be loadable (at least in breeze) to be able to remove them from example tree
    Likely we should have a dedicated "test_dags" folder/bundle that should contain dags used for testing only. We can automatically add such dags to be used in unit test via auto-fixture in the shared conftest.py or similar - this way it will work in both breeze and local venv. I think we should aim to have breeze == local env
  • DAG Budles must be extended depending on installed/available providers to extend examples - allowing to move examples from core to providers (e.g. example_kubernetes_executor.py → cncf.kubernetes)
    Likely we can add "examples" section in provider.yaml and move the example dags from "tests" to separate "examples" folder that will be also embedded in the .whl file (so that you can also conditionally enable examples from a given provider). This means that "system" tests will not be a separate "system" folder, but something separate.
  • We should figure out a way how to show examples from a provider - possibly "load_core_examples=true/false" and "load_provider_examples=[list of providers]" would be a nice way how to do it


  • The example have to be reviewed with  "security" point of view. We often have security reports that are pointing to RCE , lack of sanitizations etc. in our examples - which is very important as those examples can be used by others and bad practices propagated to production code.

Proposed Technical Excellence in Example DAGs

Note

Draft / Brainstorming quality.

  • All code has documentation (pydoc)
  • All DAGs have DAG MD docs and task MD docs
  • All DAGs and Tasks use Typing
  • The Examples use tags mapping to use cases of storyline.
    • All examples carry the the tag "Example"
    • If the DAG is serving as a tuutorial, it is having the tag "Tutorial"
    • Current examples that we move off for testing (or which are dual-use) get a tag "Testing"
  • Ruff + Mypy checks are enabled and examples follow code quality guidelines
  • DAGs and Tasks have nice display names
  • Examples do not use deprecated functions
  • Examples do not carry top-level code
  • Code in the examples follow best practices with regards to security (sanitizatio, RCE protection, no exposure of sensitive information and the like)
  • All examples are running in the standard setup out-of-the-box. They need to run out-of-the-box (e.g. no connections, SW packages need to be created prior run)
    Note: This will not be possible for some provider examples - for example Google  - they need at least configuration of Google connection and some of them need a separate setup. Possibly in those cases we should just document prerequisites for them. Or we need to find other creative options like checking for existence and short-circuit if per-requisites are not existing (e.g. a snowflake back-end needed). If can be set-up automatically then setup- and teardown tasks might be an option.
  • Examples should integrate into the story-line and not just stand-alone to showcase a technical feature

Current Examples → Example DAG Target Panning

See https://github.com/apache/airflow/tree/main/airflow-core/src/airflow/example_dags

NameGapsProposed ChangeFeatures used

Core - airflow-core/src/airflow/example_dags

example_asset_alias.py



AssetAlias, taskflow

example_asset_alias_with_no_taskflow.py



AssetAlias

example_asset_decorator.py



assets, decorators

example_assets.py



assets

example_asset_with_watchers.py




example_bash_decorator.py




example_bash_operator.py




example_branch_datetime_operator.py




example_branch_day_of_week_operator.py




example_branch_labels.py




example_branch_operator_decorator.py




example_branch_operator.py




example_branch_python_dop_operator_3.py




example_complex.py




example_custom_weight.py



priority weights, 

example_dag_decorator.py




example_display_name.py




example_dynamic_task_mapping.py




example_dynamic_task_mapping_with_no_taskflow_operators.py




example_external_task_marker_dag.py




example_inlet_event_extra.py




example_kubernetes_executor.py




example_latest_only.py




example_latest_only_with_trigger.py




example_local_kubernetes_executor.py




example_nested_branch_dag.py




example_outlet_event_extra.py




example_params_trigger_ui.py




example_params_ui_tutorial.py




example_passing_params_via_test_command.py




example_python_decorator.py




example_python_operator.py




example_sensor_decorator.py




example_sensors.py




example_setup_teardown.py




example_setup_teardown_taskflow.py




example_short_circuit_decorator.py




example_short_circuit_operator.py




example_simplest_dag.py




example_skip_dag.py




example_task_group_decorator.py




example_task_group.py




example_time_delta_sensor_async.py




example_trigger_controller_dag.py




example_trigger_target_dag.py




example_workday_timetable.py




example_xcomargs.py




example_xcom.py




ArangoDB - providers/arangodb/src/airflow/providers/arangodb/example_dags

example_arangodb.py




Oracle - providers/oracle/src/airflow/providers/oracle/example_dags

example_oracle.py




Edge - providers/edge3/src/airflow/providers/edge3/example_dags

integration_test.py




win_notepad.py




win_test.py




List of features to cover in new examples

  • List out features here
  • No labels