Skip to content

Making webserver config customisable#29926

Merged
potiuk merged 30 commits into
apache:mainfrom
amoghrajesh:webServerConfigurable
May 18, 2023
Merged

Making webserver config customisable#29926
potiuk merged 30 commits into
apache:mainfrom
amoghrajesh:webServerConfigurable

Conversation

@amoghrajesh

@amoghrajesh amoghrajesh commented Mar 5, 2023

Copy link
Copy Markdown
Contributor

The webserver_config.py is hard coded and is not customisable at the moment. It would be nice to read this config from a property in the configs instead of hardcoding it. Added support for reading the webserver_config.py through [webserver] config_file
closes: #10206


^ Add meaningful description above

Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
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.

@boring-cyborg boring-cyborg Bot added the area:webserver Webserver related Issues label Mar 5, 2023
@uranusjr

uranusjr commented Mar 5, 2023

Copy link
Copy Markdown
Member

This looks like a work in progress? A lot of leftover and incorrectly formatted code.

@amoghrajesh

Copy link
Copy Markdown
Contributor Author

@uranusjr the unit test is a WIP. The application code is up to date. I do not see formatting issues in that file

Comment thread airflow/configuration.py Outdated

if in_airflow_home:
log.warning(
"webserver_config.py is still present in %s, this will be deprecated and moved to %s",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
"webserver_config.py is still present in %s, this will be deprecated and moved to %s",
"webserver_config.py is still present in %s, this locaation is deprecated. You should move your webserver_config.py to %s",

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good idea. Let me make this change

potiuk
potiuk previously requested changes Mar 5, 2023

@potiuk potiuk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think generating the webserver_config.py to the new location by default should be also part of this PR. Otherwise - if we forget about it, we will end up when you install airflow for the first time - with deprecation warning out-of-the-box.

(and we need to update documentation too).

@amoghrajesh
amoghrajesh requested a review from potiuk March 5, 2023 11:01
@amoghrajesh

Copy link
Copy Markdown
Contributor Author

@potiuk I realised that the last version of this PR was very confusing. Re worked it to address your concerns too.

@potiuk

potiuk commented Mar 5, 2023

Copy link
Copy Markdown
Member

Tests need fixing too.

@amoghrajesh

Copy link
Copy Markdown
Contributor Author

@potiuk fixed the code. There are lot of occurrences in the docs. Should we handle it in a separate Github issue and PR?

@potiuk

potiuk commented Mar 5, 2023

Copy link
Copy Markdown
Member

@potiuk fixed the code. There are lot of occurrences in the docs. Should we handle it in a separate Github issue and PR?

No. We should update docs in the same PR that changes the code. This should be done together, then it is better cherry-pickable .

@potiuk
potiuk force-pushed the webServerConfigurable branch from 5b73b18 to 0f6b784 Compare March 5, 2023 20:24
Comment thread airflow/configuration.py Outdated
Comment thread airflow/configuration.py Outdated
@amoghrajesh

Copy link
Copy Markdown
Contributor Author

@potiuk @uranusjr can you take another look at the PR?

@uranusjr I commented on your review comments - maybe I didn't understand them correctly

@potiuk handled the review comments - added changes in the docs too. Did I include all the files?

@amoghrajesh
amoghrajesh removed the request for review from potiuk March 13, 2023 15:32

@amoghrajesh amoghrajesh left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@jedcunningham @potiuk reworked the PR as per our slack discussion.Honestly, this PR looks much cleaner than what we had previously. Thanks!

Comment thread tests/www/views/test_views.py Outdated
@amoghrajesh
amoghrajesh requested review from jedcunningham and removed request for potiuk March 20, 2023 07:50
@potiuk

potiuk commented Mar 21, 2023

Copy link
Copy Markdown
Member

LGTM - @jedcunningham ?

Comment thread airflow/config_templates/config.yml Outdated
Comment thread airflow/configuration.py Outdated
Comment thread tests/www/views/test_views.py Outdated
@amoghrajesh

Copy link
Copy Markdown
Contributor Author

@jedcunningham can you take a look when possible?

Comment thread tests/www/views/test_views.py Outdated
Comment thread tests/www/views/test_views.py Outdated
Comment thread tests/www/views/test_views.py Outdated
conf = initialize_config()
conf.validate()

assert WEBSERVER_CONFIG == os.path.join(AIRFLOW_HOME, "webserver_config.py")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why does this pass? Shouldn't it be your new name instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I might be wrong but as per my understanding and running the debugger: Initially, the default path is taken. Once we reach lines: https://github.com/apache/airflow/pull/29926/files#diff-2ab05df659c739ff335a407c4a6cddc5f177e9c402aca296991f53fa341f4dfeR1537-R1542, it generates the file to the new path instead.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It's good that the assert down below passes (meaning Airflow does create it in the right place). However, we should also test that WEBSERVER_CONFIG gets set to the file in the config. You might want to import it here after running initialize?

This also has the potential of side effects. You should switch back to using mock.patch.dict, and you should also try and clean up the file as well with a try/finally.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You might want to import it here after running initialize

Not sure how I can do that. Can i get some help here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think the issue is that the local_conf.get("webserver", "config_file") is unable to return the right value of the webserver config file here. This is because the mock.patch.dict doesn't seem to add these values correctly for the unit test. Could i get some help here @jedcunningham ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

image

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Adding a log statement to print the env variable set and it seems to reflect it there.

PASSED           [100%][2023-05-10T14:10:06.620+0530] {test_views.py:68} WARNING - /tmp/my_custom_webserver_config.py

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hmm, maybe try with conf_vars like this instead:

with conf_vars({("email", "email_backend"): "tests.operators.test_email.send_email_test"}):

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not helpful. Wondering if we can get the main feature in here and then I can create a follow up PR to investigate this in more detail and fix it. @jedcunningham thoughts?

@jedcunningham jedcunningham May 17, 2023

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I pushed a commit into your branch that fixes the test. Took me a bit of time to get it actually working, but that exercises the config option and doesn't have any side effects (like leaving WEBSERVER_CONFIG with the custom config from this test).

Comment thread tests/www/views/test_views.py Outdated
@amoghrajesh

Copy link
Copy Markdown
Contributor Author

I will try to look into this based on your suggestion @jedcunningham
Thanks for the feedback

Comment thread airflow/config_templates/config.yml Outdated
Comment thread airflow/configuration.py Outdated
@amoghrajesh
amoghrajesh requested a review from jedcunningham May 17, 2023 07:38
@jedcunningham
jedcunningham requested a review from potiuk May 17, 2023 17:31
Comment thread airflow/configuration.py
global WEBSERVER_CONFIG
WEBSERVER_CONFIG = AIRFLOW_HOME + "/webserver_config.py"

WEBSERVER_CONFIG = local_conf.get("webserver", "config_file")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Needs formatting, but I think we need:

Suggested change
WEBSERVER_CONFIG = local_conf.get("webserver", "config_file")
WEBSERVER_CONFIG = local_conf.get("webserver", "config_file",
fallback= AIRFLOW_HOME + "/webserver_config.py")

Otherwise it will fail for those who have the old config file

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(or is it aautomaticaly handled with the default?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It's automatically handled. Most fallbacks can go honestly, much more useful in providers than core.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah I vaguely recall that - I wanted to clean up the code doing it once and failed miserably :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for clarifying this. Was not so aware about this

@potiuk
potiuk merged commit 30e93ff into apache:main May 18, 2023
@jedcunningham jedcunningham added this to the Airflow 2.7.0 milestone May 30, 2023
@jedcunningham jedcunningham added the type:new-feature Changelog: New Features label May 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:webserver Webserver related Issues type:new-feature Changelog: New Features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make webserver_config.py location customizable

4 participants