Skip to content

Add dynamic DAG bundle configuration from file path - #63928

Closed
tardunge wants to merge 4 commits into
apache:mainfrom
tardunge:feature/dynamic-dag-bundle-config
Closed

tardunge wants to merge 4 commits into
apache:mainfrom
tardunge:feature/dynamic-dag-bundle-config

Conversation

@tardunge

@tardunge tardunge commented Mar 19, 2026 •

Copy link
Copy Markdown

Add a new dag_bundle_config_path setting that allows loading DAG bundle configurations from JSON files in a directory, enabling hot-reloading without restarting the DAG processor.

Motivation: In Kubernetes environments, bundle configurations need to change frequently (e.g., via ConfigMaps). The current dag_bundle_config_list requires static config in airflow.cfg and a processor restart. This feature allows mounting a directory of JSON files and having the DAG processor automatically detect and apply changes.

Key changes:

  • DagBundlesManager: new _parse_config_from_path(), check_config_path_changes(), and get_bundle_path_safe() methods
  • DagFileProcessorManager: reuses a single DagBundlesManager instance; detects config path changes in the refresh loop, cleaning up removed bundles (processors, file stats, DAGs)
  • ParseImportError.full_file_path(): graceful handling when bundles are removed
  • config.yml: new dag_bundle_config_path option under [dag_processor]

JSON config format:

{
  "name": "my-git-repo",
  "classpath": "airflow.providers.git.bundles.git.GitDagBundle",
  "kwargs": {
    "tracking_ref": "main",
    "git_conn_id": "my_git_conn"
  }
}

Behavior:

  • When dag_bundle_config_path is set, it takes precedence over dag_bundle_config_list
  • The DAG processor monitors the directory for JSON file additions, removals, and modifications via mtime tracking
  • On change: reloads config, syncs to DB, cleans up removed bundle processors/DAGs, force-refreshes active bundles
  • Invalid JSON files are logged and skipped; duplicate bundle names are warned and skipped

Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code (Opus 4.6)

Generated-by: Claude Code (Opus 4.6) following the guidelines


Important

🛠️ Maintainer triage note for @tardunge · by @potiuk · 2026-06-17 14:51 UTC

Helpful heads-up from the maintainers — please address before this PR can be reviewed:

  • Static / docs checks failing (CI image checks / Build documentation (--spellcheck-only)). Run them locally with prek run --all-files (or pre-commit run --all-files) and push the fixes.
  • Failing test jobs: provider distributions tests / Compat 2.11.1:P3.10:, provider distributions tests / Compat 3.0.6:P3.10:, provider distributions tests / Compat 3.1.8:P3.10:, provider distributions tests / Compat 3.2.1:P3.10:. Reproduce and fix locally, then push.
  • See the Pull Request quality criteria.

The ball is in your court — you've been assigned to this PR. Fix the above, then mark it Ready for review.

Automated triage — may be imperfect; a maintainer takes the next look.

@boring-cyborg

boring-cyborg Bot commented Mar 19, 2026

Copy link
Copy Markdown

Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide (https://github.com/apache/airflow/blob/main/contributing-docs/README.rst)
Here are some useful points:

  • Pay attention to the quality of your code (ruff, mypy and type annotations). Our prek-hooks will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example DAG that shows how users should use it.
  • Consider using Breeze environment for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
  • Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: [email protected]
    Slack: https://s.apache.org/airflow-slack

@tardunge
tardunge force-pushed the feature/dynamic-dag-bundle-config branch 3 times, most recently from fbdca7e to 7cfe224 Compare March 20, 2026 02:41
@uranusjr

Copy link
Copy Markdown
Member

It looks to me this relies on the directory content following certain conventions that did not previously exist. This is a problem on its own, but it means descriptions must be added to the documentation in relevant sections.

@potiuk potiuk added the ready for maintainer review Set by triage when all criteria pass, or by the fork CI reconciler when fork CI is green. label Mar 20, 2026
@kaxil
kaxil requested a review from Copilot April 2, 2026 00:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for dynamically loading DAG bundle configuration from a directory of JSON files (with change detection), enabling hot-reload behavior in the DAG processor without requiring restarts.

Changes:

  • Add dag_bundle_config_path config option and JSON-directory parsing logic to DagBundlesManager
  • Add config-path change detection + bundle cleanup/reload flow in DagFileProcessorManager
  • Make ParseImportError.full_file_path() resilient when a referenced bundle has been removed

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
airflow-core/tests/unit/dag_processing/bundles/test_dag_bundle_manager.py Adds unit tests for config-path parsing, precedence, change detection, and safe bundle accessors
airflow-core/src/airflow/models/errors.py Avoids raising when a bundle referenced by an import error has been removed
airflow-core/src/airflow/dag_processing/manager.py Reuses a bundles manager and triggers reload/cleanup when config-path changes
airflow-core/src/airflow/dag_processing/bundles/manager.py Implements config-path parsing, mtime tracking, and “safe” bundle access methods
airflow-core/src/airflow/config_templates/config.yml Documents new dag_bundle_config_path setting

@tardunge

tardunge commented Apr 27, 2026 •

Copy link
Copy Markdown
Author

It looks to me this relies on the directory content following certain conventions that did not previously exist. This is a problem on its own, but it means descriptions must be added to the documentation in relevant sections.

@uranusjr
Added in 368bfa50 — new "Dynamic Dag bundle configuration via config path" subsection under "Configuring Dag bundles" in airflow-core/docs/administration-and-deployment/dag-bundles.rst. Covers the JSON file format, hot-reload semantics (mtime-based change detection, what reload does), precedence over dag_bundle_config_list, validation behaviour for invalid/duplicate files, and the multi-team interaction.

TARDUNGE and others added 4 commits April 27, 2026 21:44
Adds a new `dag_bundle_config_path` setting that allows loading DAG bundle
configurations from JSON files in a directory. This enables hot-reloading
of bundle configurations without restarting the DAG processor, which is
particularly useful in Kubernetes environments where ConfigMaps can be
mounted as files.

When `dag_bundle_config_path` is set, it takes precedence over the
existing `dag_bundle_config_list` setting. The DAG processor monitors
the directory for file additions, removals, and modifications, and
automatically reloads bundles when changes are detected.

Key changes:
- DagBundlesManager: new _parse_config_from_path(), check_config_path_changes(),
  and get_bundle_path_safe() methods
- DagFileProcessorManager: reuses a single DagBundlesManager instance and
  detects config path changes in the refresh loop, cleaning up removed bundles
- ParseImportError: graceful handling when bundles are removed
- config.yml: new dag_bundle_config_path option
Rename loop variable to avoid shadowing Path-typed file_path with
str-typed iteration variable from dict.items().
…nges

The check_config_path_changes() call in _refresh_dag_bundles() must use
`is True` identity check rather than truthiness, because MagicMock
returns a truthy MagicMock object by default. Also restore sync_bundles()
and get_all_bundles() to use throwaway DagBundlesManager instances
(matching upstream pattern) to avoid mock interference.
Adds a prose section to dag-bundles.rst describing the directory
convention, JSON file format, hot-reload semantics, precedence over
dag_bundle_config_list, and validation behaviour for the new
dag_bundle_config_path option (the previous PR commits only added a
config.yml description).

Also addresses review correctness/robustness feedback on the
DagBundlesManager directory mode:

- Track every *.json file's mtime regardless of parse outcome, so
  invalid or duplicate-name files no longer cause check_config_path_changes
  to report "changed" on every poll.
- Use st_mtime_ns instead of float st_mtime for reliable detection on
  filesystems with coarse-resolution timestamps.
- Validate that the JSON "name" is a non-empty string before adding it
  to the duplicate-detection set; non-string names previously raised
  TypeError when added to a set.
- Clear bundle_config and config_path_mtime on the early-return paths
  (missing directory, no valid configs found) so removed bundles get
  cleaned up instead of staying configured.
- Replace time.sleep(0.01) in the test with an explicit os.utime mtime
  bump so the test doesn't depend on filesystem timestamp granularity.
@tardunge
tardunge force-pushed the feature/dynamic-dag-bundle-config branch from 368bfa5 to 8abfb21 Compare April 27, 2026 13:44
@potiuk
potiuk marked this pull request as draft June 18, 2026 21:46
@potiuk

potiuk commented Jul 2, 2026

Copy link
Copy Markdown
Member

Note

🗑️ Closing stale draft · by @potiuk · 2026-07-02 18:44 UTC

This draft has been inactive for ~14 days. Closing to keep the queue tidy — no judgment on the change itself. Please reopen (or open a fresh PR) whenever you pick it back up, and a maintainer will be glad to take a look.

Automated triage — may be imperfect.

@potiuk potiuk closed this Jul 2, 2026
@infused-kim

Copy link
Copy Markdown
Contributor

I am also in need of this feature. @tardunge are you still interested in continuing working on this or can someone else take it over?

Perhaps the PR just needs to be reopened and a review requested?

This PR solves the following issues:
#59799
#60859
#66858

So, there is a lot of interest for this.

@tardunge

Copy link
Copy Markdown
Author

Please take over.

@tardunge tardunge removed their assignment Jul 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ConfigTemplates area:dag-processor ready for maintainer review Set by triage when all criteria pass, or by the fork CI reconciler when fork CI is green.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants