Skip to content
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

Remove default port from grpc ChannelOptions #81

Closed
wants to merge 2 commits into from

Conversation

shsms
Copy link
Contributor

@shsms shsms commented Sep 3, 2024

URIs should always specify a port. If they don't, a ValueError will be raised.

Closes #80

@github-actions github-actions bot added part:docs Affects the documentation part:code Affects the code in general labels Sep 3, 2024
@shsms
Copy link
Contributor Author

shsms commented Sep 3, 2024

Draft because this is based on #79

@github-actions github-actions bot added the part:tests Affects the unit, integration and performance (benchmarks) tests label Sep 3, 2024
@llucax llucax added this to the v0.7.0 milestone Sep 3, 2024
URIs should always specify a port.  If they don't, a `ValueError` will
be raised.

Signed-off-by: Sahas Subramanian <[email protected]>
Signed-off-by: Sahas Subramanian <[email protected]>
@shsms shsms marked this pull request as ready for review September 3, 2024 09:58
@shsms shsms requested a review from a team as a code owner September 3, 2024 09:58
llucax
llucax previously approved these changes Sep 3, 2024
@llucax llucax dismissed their stale review September 3, 2024 10:00

Wait wait wait

Copy link
Contributor

@llucax llucax left a comment

Choose a reason for hiding this comment

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

Mmm, I'm not convinced about completely removing the possibility to set a default port. I agree that for the base client it doesn't make sense, as we don ´t know anything about the API. But for subclasses, where we will probably have well defined service locations, it might make sense to have a default port and only leave a floating address (I can see the case for that if you want to change between staging and production for example).

At least I think @Marenz made a point about this.

I don ´t know, for now I would make the port int | None = None and only raise if the default_port is None.

@shsms
Copy link
Contributor Author

shsms commented Sep 3, 2024

But for subclasses, where we will probably have well defined service locations, it might make sense to have a default port and only leave a floating address

People can type the ports themselves. We are only introducing opportunities to fail, by providing defaults.

(I can see the case for that if you want to change between staging and production for example).

This example sounds particularly dangerous to me, relying on defaults for switching between staging and production is a definite way to mess things up.

Saving a few keystrokes to type the ports is not worth the risks/complications having a default would introduce.

@Marenz
Copy link
Contributor

Marenz commented Sep 3, 2024

It's not about saving keystrokes, it's about making the usage easier.
Optimally, the end user only needs to know dispatch.frequenz.io (or whatever url we use) and the client fills in port/encryption etc automatically.

For staging, of course a different domain would be better dispatch.staging.frequenz.io for example) but I am working with what I got and that's just one server/ip/domain currently ;)

@llucax
Copy link
Contributor

llucax commented Sep 4, 2024

Yeah, I'm even thinking about what if we want to have different versions of an API running in different ports. A service (client) could known which port uses each version, and try to find first the latest version and only connect to older versions if unavailable. I can really see use cases for letting the client chose the port (i.e. using a default). I agree is not about saving keystrokes, is about abstraction.

@llucax
Copy link
Contributor

llucax commented Sep 4, 2024

This example sounds particularly dangerous to me, relying on defaults for switching between staging and production is a definite way to mess things up.

How is it dangerous? Is not relying on defaults, is using different host names, user-provided host names, is using the DNS to look for a particular instance.

@llucax
Copy link
Contributor

llucax commented Sep 4, 2024

There is a reason why port numbers are standarized, the whole IANA thing. Ports do have meaning, even if you could use a non-standard one.

https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml

@shsms
Copy link
Contributor Author

shsms commented Sep 4, 2024

Fine, let me get out of the way then.

@shsms shsms closed this Sep 4, 2024
@shsms shsms deleted the no-default-port branch September 4, 2024 15:27
@llucax
Copy link
Contributor

llucax commented Sep 4, 2024

I still see value in part of the PR, I don't think the base client should set a default port, it should just allow clients to set one. If some concrete client think it is best not to provide a default port, they can do so, and that will actually be the default.

I don't know why the door slam 😟

@llucax
Copy link
Contributor

llucax commented Sep 4, 2024

This is what I mean:

@shsms
Copy link
Contributor Author

shsms commented Sep 5, 2024

I don't think the base client should set a default port, it should just allow clients to set one.

To me it is always better to be explicit, users are going to copy-paste the urls anyway, I don't see how this is useful, and but I think it could mess things up if multiple services are running on the same domain name, like for different users, etc., which we already have examples for. But just opinions, and not really strong ones.

I don't know why the door slam 😟

No, of course not, more like a door opening. It looks like the majority thinks it is nice to have, so I won't block you, but I'd rather not do it myself.

@llucax
Copy link
Contributor

llucax commented Sep 5, 2024

To me it is always better to be explicit, users are going to copy-paste the urls anyway, I don't see how this is useful, and but I think it could mess things up if multiple services are running on the same domain name, like for different users, etc., which we already have examples for.

I agree with all of this, but still in general URLs allow omitting the port, and this is still a general purpose library (even when it might be a bit specific to our use case). With the PR I'm proposing, the default is still to require an explicit port, but if some client thinks a default port makes sense, they can do so. So unless some downstream project explicitly defines a default port, it will be required. If a downstream project goes to the trouble of setting a default, I would trust they know what they are doing. For sure it exist cases for using default ports, they are used everywhere (most services we use on a daily basis have a default port) and they are not required by the URL/URI standard. So I think it makes sense to leave the door open in this library, but go with a safe default.

No, of course not, more like a door opening. It looks like the majority thinks it is nice to have, so I won't block you, but I'd rather not do it myself.

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
part:code Affects the code in general part:docs Affects the documentation part:tests Affects the unit, integration and performance (benchmarks) tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Don't use a default port for creating grpcio channels
3 participants