Making webserver config customisable#29926
Conversation
|
This looks like a work in progress? A lot of leftover and incorrectly formatted code. |
|
@uranusjr the unit test is a WIP. The application code is up to date. I do not see formatting issues in that file |
|
|
||
| if in_airflow_home: | ||
| log.warning( | ||
| "webserver_config.py is still present in %s, this will be deprecated and moved to %s", |
There was a problem hiding this comment.
| "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", |
There was a problem hiding this comment.
Good idea. Let me make this change
There was a problem hiding this comment.
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).
|
@potiuk I realised that the last version of this PR was very confusing. Re worked it to address your concerns too. |
|
Tests need fixing too. |
|
@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 . |
5b73b18 to
0f6b784
Compare
…w into webServerConfigurable
amoghrajesh
left a comment
There was a problem hiding this comment.
@jedcunningham @potiuk reworked the PR as per our slack discussion.Honestly, this PR looks much cleaner than what we had previously. Thanks!
|
LGTM - @jedcunningham ? |
…w into webServerConfigurable
|
@jedcunningham can you take a look when possible? |
| conf = initialize_config() | ||
| conf.validate() | ||
|
|
||
| assert WEBSERVER_CONFIG == os.path.join(AIRFLOW_HOME, "webserver_config.py") |
There was a problem hiding this comment.
Why does this pass? Shouldn't it be your new name instead?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
You might want to import it here after running initialize
Not sure how I can do that. Can i get some help here?
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Hmm, maybe try with conf_vars like this instead:
airflow/tests/operators/test_email.py
Line 59 in d6051fd
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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).
|
I will try to look into this based on your suggestion @jedcunningham |
…w into webServerConfigurable
| global WEBSERVER_CONFIG | ||
| WEBSERVER_CONFIG = AIRFLOW_HOME + "/webserver_config.py" | ||
|
|
||
| WEBSERVER_CONFIG = local_conf.get("webserver", "config_file") |
There was a problem hiding this comment.
Needs formatting, but I think we need:
| 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
There was a problem hiding this comment.
(or is it aautomaticaly handled with the default?
There was a problem hiding this comment.
It's automatically handled. Most fallbacks can go honestly, much more useful in providers than core.
There was a problem hiding this comment.
Yeah I vaguely recall that - I wanted to clean up the code doing it once and failed miserably :)
There was a problem hiding this comment.
Thanks for clarifying this. Was not so aware about this

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_filecloses: #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.rstor{issue_number}.significant.rst, in newsfragments.