-
-
Notifications
You must be signed in to change notification settings - Fork 687
feat: add new dispatch compose #2826
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
Conversation
|
Next, time to fight with tests and adapt it |
ronag
left a comment
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 think just making it available with docs is sufficient here and then we can apply it in next with a revision of my PR.
mcollina
left a comment
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.
Missing docs and tests
|
I would also like us to have some kind of benchmark to this pattern to make sure it doesn't add too much overhead. |
Co-authored-by: Matteo Collina <[email protected]>
|
@ronag, did the Proxy worked for you? |
|
All tests passed. So I think so? |
|
Well, that's because we I've not pushed the tests for the compose feature; still in my machine and constantly failing, on top I forgot to add the extra dispatcher on the constructor for the Proxy. But its fine, I just wanted to be sure I had the whole picture. Most likely I'll put back the Agent where it was, and copy/paste and adapt a new copy of the Agent proxy to take into account the new dispatcher arg |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2826 +/- ##
==========================================
- Coverage 93.68% 93.48% -0.20%
==========================================
Files 87 89 +2
Lines 23973 24102 +129
==========================================
+ Hits 22458 22531 +73
- Misses 1515 1571 +56 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
docs/docs/api/Interceptors.md
Outdated
| const client = new Client("http://example.com"); | ||
|
|
||
| client.compose(proxy("http://proxy.com")); |
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.
| const client = new Client("http://example.com"); | |
| client.compose(proxy("http://proxy.com")); | |
| const client = new Client("http://example.com").compose(proxy("http://proxy.com")); |
docs/docs/api/Interceptors.md
Outdated
| const client = new Client("http://example.com"); | ||
|
|
||
| client.compose(redirect({ maxRedirections: 3, throwOnMaxRedirects: true })); |
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.
| const client = new Client("http://example.com"); | |
| client.compose(redirect({ maxRedirections: 3, throwOnMaxRedirects: true })); | |
| const client = new Client("http://example.com").compose(redirect({ maxRedirections: 3, throwOnMaxRedirects: true })); |
docs/docs/api/Interceptors.md
Outdated
| const client = new Client("http://example.com"); | ||
|
|
||
| client.compose( | ||
| retry({ | ||
| maxRetries: 3, | ||
| minTimeout: 1000, | ||
| maxTimeout: 10000, | ||
| timeoutFactor: 2, | ||
| retryAfter: true, | ||
| }) | ||
| ); |
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.
| const client = new Client("http://example.com"); | |
| client.compose( | |
| retry({ | |
| maxRetries: 3, | |
| minTimeout: 1000, | |
| maxTimeout: 10000, | |
| timeoutFactor: 2, | |
| retryAfter: true, | |
| }) | |
| ); | |
| const client = new Client("http://example.com").compose( | |
| retry({ | |
| maxRetries: 3, | |
| minTimeout: 1000, | |
| maxTimeout: 10000, | |
| timeoutFactor: 2, | |
| retryAfter: true, | |
| }) | |
| ); |
lib/interceptor/proxy.js
Outdated
| const ProxyAgent = require('../dispatcher/proxy-agent') | ||
| const DispatcherBase = require('../dispatcher/dispatcher-base') | ||
|
|
||
| class ProxyInterceptor extends DispatcherBase { |
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.
Please integrate this inside the ProxyAgent. We shouldn't have special classes for these.
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 think this should extend Dispatcher, not DispatcherBase.
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.
Please integrate this inside the ProxyAgent. We shouldn't have special classes for these.
Sure, let me double-check this part as I'm not totally confident about it, I'd try to first assess if the chain of dispatcher works as expected before trying to port it to the ProxyAgent
lib/interceptor/redirect.js
Outdated
| const Dispatcher = require('../dispatcher/dispatcher-base') | ||
| const RedirectHandler = require('../handler/RedirectHandler') | ||
|
|
||
| class RedirectDispatcher extends Dispatcher { |
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.
This class is useful as its own export.
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.
We can add it as a RedirectAgent
docs/docs/api/Interceptors.md
Outdated
| @@ -0,0 +1,68 @@ | |||
| # Interceptors | |||
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.
Generically I don't think we need a special page for the interceptors. They are more confusing than anything else. Let's only have Dispatchers.
Having the use specify (dispatcher) => new MyDispatcher(dispatcher, myOpts) is not a problem for most devs. These helpers only add noise.
lib/dispatcher/dispatcher.js
Outdated
|
|
||
| const EventEmitter = require('node:events') | ||
|
|
||
| const kDispatcherVersion = Symbol.for('undici.dispatcher.version') |
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.
Is this the same simbol we use for the global? I think we should use the same.
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 slightly disagree with @mcollina. I don't see any point in exposing the dispatcher classes themselves (why would you extend them)? Rather I would prefer exposing curry-able factory methods. That also makes the distinction between composable and non composable dispatcher clearer.
I pushed the change to put both options over the table and chat about which one we would like to follow. |
ronag
left a comment
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.
LGTM. Other than it doesn't make sense for proxy to be an interceptor.
|
@mcollina PTAL |
|
Actually |
Your initial suggestion was doing that somehow, but that will mean break the current |
It doesn't necessarily break it if the interceptor just passed a client factory that return the outer dispatcher? |
Right, that's true; but also we use the |
|
We can also just skip making it an interceptor. I'm fine with that. |
|
Dropped the |
mcollina
left a comment
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.
lgtm
This relates to...
Rationale
Changes
Features
Bug Fixes
Breaking Changes and Deprecations
Status