You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "Birne94 (via GitHub)" <gi...@apache.org> on 2024/02/19 19:31:38 UTC

[PR] Add secret caching for Airflow CLI [airflow]

Birne94 opened a new pull request, #37551:
URL: https://github.com/apache/airflow/pull/37551

   This PR adds secret caching for the Airflow CLI. [Secret caching](https://airflow.apache.org/docs/apache-airflow/stable/configurations-ref.html#use-cache) current only works for the DAG-processing job, but is ignored when parsing the files through the CLI. This currently causes slow response times from the Airflow CLI for DAGs that use top-level variables.
   
   By initializing the cache as part of the CLI startup, we make sure the cache is enabled properly for parsing. If the user did not configure caching explicitly, the added cache initialization is a no-op and the behavior is the same as before.
   
   closes: #37543 
   
   I did not add a test case yet because I did not find an existing one for `__main__.main()` yet. I am open for suggestions on how to properly test the added caching, however since this is a very small change that does not change behavior until explicitly configured we may be good without one.
   
   ---
   **^ Add meaningful description above**
   Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)** for more information.
   In case of fundamental code changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals)) is needed.
   In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
   In case of backwards incompatible changes please leave a note in a newsfragment file, named `{pr_number}.significant.rst` or `{issue_number}.significant.rst`, in [newsfragments](https://github.com/apache/airflow/tree/main/newsfragments).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add secret caching for Airflow CLI [airflow]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] closed pull request #37551: Add secret caching for Airflow CLI
URL: https://github.com/apache/airflow/pull/37551


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add secret caching for Airflow CLI [airflow]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #37551:
URL: https://github.com/apache/airflow/pull/37551#issuecomment-2041247934

   This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 5 days if no further activity occurs. Thank you for your contributions.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add secret caching for Airflow CLI [airflow]

Posted by "Birne94 (via GitHub)" <gi...@apache.org>.
Birne94 commented on code in PR #37551:
URL: https://github.com/apache/airflow/pull/37551#discussion_r1495837423


##########
airflow/__main__.py:
##########
@@ -54,6 +55,11 @@ def main():
         conf = write_default_airflow_configuration_if_needed()
         if args.subcommand in ["webserver", "internal-api", "worker"]:
             write_webserver_configuration_if_needed(conf)
+
+    # Some tasks require parsing DAG files, so we enable secret caching for improved performance.
+    # If the user did not configure secret caching, this action is a no-op.

Review Comment:
   I updated the comment, does it make more sense now?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add secret caching for Airflow CLI [airflow]

Posted by "dirrao (via GitHub)" <gi...@apache.org>.
dirrao commented on code in PR #37551:
URL: https://github.com/apache/airflow/pull/37551#discussion_r1495204356


##########
airflow/__main__.py:
##########
@@ -54,6 +55,11 @@ def main():
         conf = write_default_airflow_configuration_if_needed()
         if args.subcommand in ["webserver", "internal-api", "worker"]:
             write_webserver_configuration_if_needed(conf)
+

Review Comment:
   Why can't we use `AIRFLOW__SECRETS__USE_CACHE` instead of explicitly adding it in CLI?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add secret caching for Airflow CLI [airflow]

Posted by "uranusjr (via GitHub)" <gi...@apache.org>.
uranusjr commented on code in PR #37551:
URL: https://github.com/apache/airflow/pull/37551#discussion_r1495301611


##########
airflow/__main__.py:
##########
@@ -54,6 +55,11 @@ def main():
         conf = write_default_airflow_configuration_if_needed()
         if args.subcommand in ["webserver", "internal-api", "worker"]:
             write_webserver_configuration_if_needed(conf)
+
+    # Some tasks require parsing DAG files, so we enable secret caching for improved performance.
+    # If the user did not configure secret caching, this action is a no-op.

Review Comment:
   The comment is too vague. What is “some” and why does secret caching affect performance on DAG-parsing?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add secret caching for Airflow CLI [airflow]

Posted by "boring-cyborg[bot] (via GitHub)" <gi...@apache.org>.
boring-cyborg[bot] commented on PR #37551:
URL: https://github.com/apache/airflow/pull/37551#issuecomment-1953060748

   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 [pre-commits]( https://github.com/apache/airflow/blob/main/contributing-docs/08_static_code_checks.rst#prerequisites-for-pre-commit-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](https://github.com/apache/airflow/blob/main/docs/apache-airflow/howto/custom-operator.rst) Consider adding an example DAG that shows how users should use it.
   - Consider using [Breeze environment](https://github.com/apache/airflow/blob/main/dev/breeze/doc/README.rst) 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](https://www.apache.org/foundation/policies/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]( https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#coding-style-and-best-practices).
   - 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: dev@airflow.apache.org
   Slack: https://s.apache.org/airflow-slack
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add secret caching for Airflow CLI [airflow]

Posted by "Birne94 (via GitHub)" <gi...@apache.org>.
Birne94 commented on code in PR #37551:
URL: https://github.com/apache/airflow/pull/37551#discussion_r1495837191


##########
airflow/__main__.py:
##########
@@ -54,6 +55,11 @@ def main():
         conf = write_default_airflow_configuration_if_needed()
         if args.subcommand in ["webserver", "internal-api", "worker"]:
             write_webserver_configuration_if_needed(conf)
+

Review Comment:
   The way that secret caching is implemented currently is that the `SecretCache` class is always used for looking up. If caching is not explicitly enabled, the cache [will never be initialized](https://github.com/apache/airflow/blob/08bc0f44904fe0d8bc8779e0e892e4d42def3983/airflow/secrets/cache.py#L57-L59) and essentially is a no-op.
   
   The problem is that `SecretCache.init()` is only called [in the dag processing job](https://github.com/apache/airflow/blob/08bc0f44904fe0d8bc8779e0e892e4d42def3983/airflow/dag_processing/manager.py#L1066). This means that if we configure caching and process the DAG there, it will work as expected. However if we load a DAG from any other place (e.g. the CLI), our caching configuration is ignored and cache creation is skipped.
   
   With the change I suggest, the `secrets.use_cache` option will be honored from the CLI and caching will be enabled as expected.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org