Skip to content

feat: allow caller to initialize the channel #93

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nmooscisco
Copy link
Contributor

In some scenarios, such as when using a Deterministic Simulation Testing environment such as turmoil, when mocking the behaviour of etcd itself, or using non-Tokio sockets for connecting to etcd, it is desirable to construct a Tonic channel externally, then "wrap" it in a Client object. This patch enables this use case by creating a RawClient type, which is constructed from an existing Tonic channel.

In order to ensure maximum code re-use, the existing Client is updated to use the RawClient type internally.

@davidli2010
Copy link
Contributor

Why not just add the Client::from_channel() function?

@nmooscisco
Copy link
Contributor Author

That would also work, however, the Client seems to require that the balanced channel Sender be passed into it as well. In the current design for this PR, I have made the assumption that if the caller wishes to use load-balancing, it will handle the load balancing externally, by owning the Sender itself, allowing the caller to handle construction of the connector. It is also possible, in this case, for the caller to use a non-LB Channel if the caller should so desire.

I could also make the Sender optional in Client so as to allow this, or maybe there is another way that I'm not seeing. I'm open to suggestions, thank you!

@davidli2010
Copy link
Contributor

Make the Sender optional in Client is OK, IMO. And I think Client::from_channel() need a feature gate, because it's not recommended.

@nmooscisco nmooscisco force-pushed the feature/caller-managed-channel branch from 831325f to c45233e Compare March 24, 2025 18:06
@nmooscisco
Copy link
Contributor Author

@davidli2010 Done. I created a new feature gate named raw-channel.

@nmooscisco nmooscisco marked this pull request as ready for review March 24, 2025 18:12
@nmooscisco nmooscisco force-pushed the feature/caller-managed-channel branch 2 times, most recently from 64ce678 to 728418a Compare March 24, 2025 21:31
@nmooscisco
Copy link
Contributor Author

Actually, after some more thoughts, I believe that what will make the most sense, if a caller needs to customize the channel more deeply, would be for the caller to be able to supply their own Service impl that can be wrapped by the generated code. Is this something that would be acceptable for this project?

@nmooscisco
Copy link
Contributor Author

I had a chance to hack on this a bit more, and a prototype is in #98. This way, generics don't proliferate across the codebase -- the different supported types of Channel are all packaged in the enum provided in that PR.

Let me know what you think! The added flexibility in my change will help out quite significantly when using this crate in environments with dynamic infrastructure.

@nmooscisco nmooscisco force-pushed the feature/caller-managed-channel branch from 728418a to 1439f33 Compare March 27, 2025 16:51
@nmooscisco nmooscisco marked this pull request as draft March 27, 2025 17:00
@nmooscisco nmooscisco force-pushed the feature/caller-managed-channel branch 2 times, most recently from 28a3caf to d085bfa Compare March 31, 2025 18:43
@nmooscisco nmooscisco force-pushed the feature/caller-managed-channel branch 2 times, most recently from 06bf92f to 6f2c635 Compare April 22, 2025 17:00
@nmooscisco nmooscisco marked this pull request as ready for review April 22, 2025 17:00
@nmooscisco nmooscisco force-pushed the feature/caller-managed-channel branch 2 times, most recently from 8a75bd9 to a8f6785 Compare April 22, 2025 17:22
In some scenarios, such as when using a Deterministic Simulation
Testing environment such as `turmoil`, when mocking the behaviour of
etcd itself, or using non-Tokio sockets for connecting to etcd, it is
desirable to construct a Tonic channel externally, then "wrap" it in a
`Client` object. This patch enables this use case by adding a
`raw-channel` Cargo feature, which enables the `Client::from_channel`
function.
@nmooscisco nmooscisco force-pushed the feature/caller-managed-channel branch from a8f6785 to 0d9fc83 Compare April 22, 2025 17:29
@nmooscisco
Copy link
Contributor Author

@davidli2010 Thanks to merging #98, this patch is now ready! Thank you for your reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants