-
Notifications
You must be signed in to change notification settings - Fork 183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix canonical URL when setting either port of host from the CLI #196
Fix canonical URL when setting either port of host from the CLI #196
Conversation
@@ -99,6 +99,10 @@ def _init_worker_options( | |||
self.app.conf.web_host = web_host | |||
if web_transport is not None: | |||
self.app.conf.web_transport = web_transport | |||
if web_port is not None or web_host is not None: | |||
self.app.conf.canonical_url = ( | |||
f"http://{self.app.conf.web_host}:{self.app.conf.web_port}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be if web_port is not None and web_host is not None:
?
Otherwise we could end up with http://:8000
or http://myhost:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also do we need to think about supporting https
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- I don't believe we need to replace the "or" with an "and". These CLI configurations override the ones in the app configuration (look here: https://faust.readthedocs.io/en/latest/userguide/settings.html) under web_host, web_port, and canonical_url... so, I think the order of configuration is:
a) Use the provided app configuration (web_host, web_port, and canonical_url...)
b) If non are provided, use the default (i.e. port = 6066, host = socket.gethostname(), canonical_url= f"http://{web_host}:{web_port}"
c) Override these values by the CLI param --web_host --web_port (and after this PR the canonical_url as well :-) )
So when the CLI configures the app, it's guaranteed that web_port and web_host have some value
You can test this by setting web_port = 1111 for the app and then start Faust:
faust worker -A main.app --web-port 8001 -l info
and verify that the port is indeed 8001 and not 1111
- Maybe, at the moment, the use case that I am working on is table_route (i.e. routing requests between workers), so as long as all the workes are in the same subnet we are good. If you can think of a use case where workers are in different networks, external or with security risks, then I guess we need to consider HTTPS as well. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense. Maybe if someone needs cross-network support they can use nginx to wrap it. Or that can be a separate PR in the future.
This seems to have broken elsewhere in 6.10. We only set |
Thanks, @ondrejchmelar can you please provide more details? |
OK, I've looked at it a bit closer Version 0.6.9 Looking at this line: web_host CLI config, it looks like when running the Faust worker from a command line, web_host always gets a value (either the default value or the given param) So this code: checking if web_host is not NULL is a bit confusing. And actually App.conf.web_host is always overwritten by the worker by this value I've managed to replicate this in version 0.6.9: So this behaviour existed also in 0.6.9 Version 0.7.0 running @ondrejchmelar does it make sense? |
@ondrejchmelar can you please see if this PR resolves your issue: |
@ran-ka Yep, that seems right, I would expect it to behave the same way as |
Description
Please describe your pull request.
A small bug fix to set the right canonical_url when specifying web_port or web_host using the CLI