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
Provider API Redesign #1938
Provider API Redesign #1938
Conversation
@jeff-hiner I have created a new API based on your comments. Please check it out and see if there is still something wrong. |
@jeff-hiner, would you be able to provide feedback on this? |
I'll take a look today. |
@jeff-hiner Is there any feedback? |
Sorry for the delay. This seems to work really well with very minimal changes required on my end. Thank you SO MUCH for your hard work here! |
This is great news. Thank you @jeff-hiner for taking the time to review. And @XOR-op, thank you for spending all the time to clean all of this up for this use case. Do either of you think there might be a way for us to put in place a test or something that we could mark as "do not modify" as it's a public API that would be expensive to change, etc? I guess I'm asking, how can we avoid folks ending up spending time on similar things happing with API changes in the future? |
Thanks Jeff for your feedback! And @bluejekyll I have rebased to make this PR up-to-date, so that you could give it a code review. As for how to keep the functionality of public API stable, I think there are a few things we can do. First, I think is we need to check if some docs are misleading. The original doc of ConnectionProvider says it is "Needed mainly for mocking purposes." which we really should avoid. I think the only acceptable expressions are "should ONLY be used for internal use" if we have to expose as pub, or just say nothing. Beyond that, test is always good for compatibility. If someone wants to change a API and we don't want to lose compatibility, there should be an existent test. Otherwise we should add extra tests before changing this API. Also we can distinguish user-level test from internal test. Internal tests are used to verify the internal correctness, while user-level tests verify if users could use public API as intended. I think user-level test can be put into |
Yeah, this one is a bit rough because honestly I'm abusing the internals of the crate in order to do things it wasn't designed to do, when instead I originally should have PR'd in a fix to add a config field to have trust-dns inject the https headers. Do we want to maybe mark these internals as |
I think for this case, it's still a valid need. Although originally it's for mocking purpose, I don't see this interface will prohibit any future design and I don't see we will gain any from the deprecation to my understanding. But if we need to deprecate it finally, we should implement appropriate alternatives for that, although it could be hard to know how users use this interface. My mistake is in previous PR I thought such case could also be implemented with some efforts without losing compatibility, but indeed it failed. |
I like the idea of adding an example for this. If either of you have time for that, I think it would be useful. And then we could note that the example should not significantly change the internal API given valid external use cases for it. We can merge this as is, but if either of you have time to add that example, that would be awesome. Again, thank you both for your effort on this. |
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.
Looks good. Mostly a bunch of renaming. It does simplify some of the generic interfaces which is a good improvement.
I'm good with this. @djc, any concerns?
I don't have time to dig through this again, it sounds like the issues have been resolved though! |
In the later discussion of #1876, @jeff-hiner argues that the current Provider API doesn't offer a convenient way to statefully create
DnsHandle
. This PR redesigns the Provider API.This PR replaces the original
CreateConnection
trait with the new factory traitConnectionProvider
, allowing stateful connection creation. Now we have two layers of customization,ConnectionProvider
andRuntimeProvider
. TheRuntimeProvider
is a factory to create TCP or UDP connections, as well as runtime-specific timer. TheConnectionProvider
is a factory to create aDnsHandle
with the help ofRuntimeProvider
.If a user wants to override the default networking behavior, he/she can simply implement a new
RuntimeProvider
, without the need of re-implementing theGenericConnection
internal logic. If a user wants to override the upper logic of aDnsHandle
, for example add an auth field to the HTTP header, he/she can just implement a newConnectionProvider
and reuse currentRuntimeProvider
(It's also possible not to use a connection provided byRuntimeProvider
, as long as the user insists).Currently, the default handle is
GenericConnection
and the default connection provider isGenericProvider
.This PR also clarifies the usage of Provider API. The original comment in 0.22 as well as #1876 is kind of misleading.