GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat: add new dispatch compose by metcoder95 · Pull Request #2826 · nodejs/undici

Conversation

@metcoder95

@metcoder95 metcoder95 commented Feb 23, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

This relates to...

Rationale

Changes

Features

Bug Fixes

Breaking Changes and Deprecations

Status

  • I have read and agreed to the Developer's Certificate of Origin
  • Tested
  • Benchmarked (optional)
  • Documented
  • Review ready
  • In review
  • Merge ready

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@metcoder95
feat: add new dispatch compose
560d35b
@metcoder95

metcoder95 commented Feb 23, 2024

Copy link
Copy Markdown
Member Author

Next, time to fight with tests and adapt it

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ronag
ronag approved these changes Feb 23, 2024
View reviewed changes
ronag
ronag reviewed Feb 23, 2024
View reviewed changes

@ronag ronag left a comment

Copy link
Copy Markdown
Member

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
mcollina
mcollina requested changes Feb 23, 2024
View reviewed changes

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread lib/interceptor/redirect.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread lib/interceptor/retry.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

ronag
ronag reviewed Feb 23, 2024
View reviewed changes
Comment thread lib/interceptor/proxy.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

ronag
ronag reviewed Feb 23, 2024
View reviewed changes
Comment thread lib/interceptor/proxy.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

ronag
ronag reviewed Feb 23, 2024
View reviewed changes
Comment thread lib/interceptor/proxy.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

ronag
ronag reviewed Feb 23, 2024
View reviewed changes
Comment thread lib/interceptor/proxy.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

ronag
ronag reviewed Feb 23, 2024
View reviewed changes
Comment thread lib/interceptor/proxy.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

@ronag

ronag commented Feb 25, 2024

Copy link
Copy Markdown
Member

I would also like us to have some kind of benchmark to this pattern to make sure it doesn't add too much overhead.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

metcoder95 and others added 3 commits February 25, 2024 11:30
@metcoder95 @mcollina
fix: review
5337ea0
Co-authored-by: Matteo Collina <[email protected]>
@metcoder95
revert: linting
8019e59
@metcoder95
docs: add documentation
1d54170
@metcoder95

metcoder95 commented Feb 25, 2024

Copy link
Copy Markdown
Member Author

@ronag, did the Proxy worked for you?
I'm trying to add some testing, and it seems it will require several pieces to be changed; especially around the way we handle withe dispatch usage for connect

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ronag

ronag commented Feb 25, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

All tests passed. So I think so?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@metcoder95

metcoder95 commented Feb 25, 2024

Copy link
Copy Markdown
Member Author

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

ronag reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Carlos Fuentes added 2 commits February 25, 2024 19:13
Carlos Fuentes
Merge remote-tracking branch 'origin/main' into feat/compose-dispatch
051caa1
Carlos Fuentes
fix: smaller tweaks to proxy interceptor
b45ecad
@codecov-commenter

ghost commented Feb 28, 2024 •
edited by codecov-commenter
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 49.53271% with 54 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.48%. Comparing base (0b5a451) to head (620f9bc).
⚠️ Report is 825 commits behind head on main.

Files with missing lines Patch % Lines
lib/interceptor/redirect.js 16.66% 20 Missing ⚠️
lib/interceptor/retry.js 21.05% 15 Missing ⚠️
lib/dispatcher/dispatcher.js 74.46% 12 Missing ⚠️
lib/dispatcher/client.js 46.15% 7 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ronag
ronag reviewed Feb 28, 2024
View reviewed changes
Comment thread docs/docs/api/Interceptors.md Outdated
Comment on lines +23 to +25
const client = new Client("http://example.com");

client.compose(proxy("http://proxy.com"));

ghost Feb 28, 2024

Copy link
Copy Markdown
Member

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.

Suggested change
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"));

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
ronag
ronag reviewed Feb 28, 2024
View reviewed changes
Comment thread docs/docs/api/Interceptors.md Outdated
Comment on lines +40 to +42
const client = new Client("http://example.com");

client.compose(redirect({ maxRedirections: 3, throwOnMaxRedirects: true }));

ghost Feb 28, 2024

Copy link
Copy Markdown
Member

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.

Suggested change
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 }));

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
ronag
ronag reviewed Feb 28, 2024
View reviewed changes
Comment thread docs/docs/api/Interceptors.md Outdated
Comment on lines +57 to +67
const client = new Client("http://example.com");

client.compose(
retry({
maxRetries: 3,
minTimeout: 1000,
maxTimeout: 10000,
timeoutFactor: 2,
retryAfter: true,
})
);

ghost Feb 28, 2024

Copy link
Copy Markdown
Member

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.

Suggested change
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,
})
);

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
mcollina
mcollina requested changes Feb 28, 2024
View reviewed changes
Comment thread lib/interceptor/proxy.js Outdated
const ProxyAgent = require('../dispatcher/proxy-agent')
const DispatcherBase = require('../dispatcher/dispatcher-base')

class ProxyInterceptor extends DispatcherBase {

ghost Feb 28, 2024

Copy link
Copy Markdown
Member

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

ghost Feb 28, 2024

Copy link
Copy Markdown
Member

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

metcoder95 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

ghost Feb 28, 2024 •
edited by metcoder95
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread lib/interceptor/redirect.js Outdated
const Dispatcher = require('../dispatcher/dispatcher-base')
const RedirectHandler = require('../handler/RedirectHandler')

class RedirectDispatcher extends Dispatcher {

ghost Feb 28, 2024

Copy link
Copy Markdown
Member

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

ghost Feb 29, 2024

Copy link
Copy Markdown
Member Author

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread docs/docs/api/Interceptors.md Outdated
@@ -0,0 +1,68 @@
# Interceptors

ghost Feb 28, 2024

Copy link
Copy Markdown
Member

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

metcoder95 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread docs/docs/api/Dispatcher.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread lib/dispatcher/dispatcher.js Outdated

const EventEmitter = require('node:events')

const kDispatcherVersion = Symbol.for('undici.dispatcher.version')

ghost Feb 28, 2024

Copy link
Copy Markdown
Member

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

metcoder95 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread lib/dispatcher/dispatcher.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread lib/interceptor/proxy.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

Carlos Fuentes added 2 commits February 28, 2024 12:34
Carlos Fuentes
test: fix tests for proxy
9048eb5
Carlos Fuentes
refactor: expose interceptor as is
7656e1b
ronag
ronag reviewed Feb 29, 2024
View reviewed changes

ghost left a comment •
edited by ronag
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@metcoder95

ghost commented Feb 29, 2024

Copy link
Copy Markdown
Member Author

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.
On this one, I agree with @ronag the dispatcher classes made for the interceptors might be better to keep internal, as we are looking to introduce the concept of composable-dispatcher. Otherwise it kind of becomes more like building Agents we already have the concept of

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Carlos Fuentes
Merge branch 'main' into feat/compose-dispatch
9f0631e
ronag
ronag reviewed Mar 1, 2024
View reviewed changes
Comment thread index.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

@ronag

ghost commented Mar 10, 2024

Copy link
Copy Markdown
Member

Actually ProxyAgent might make sense as an interceptor if [kClient] is the outer dispatcher.

Your initial suggestion was doing that somehow, but that will mean break the current ProxyAgent; wdyt if we drop the ProxyInterceptor and we migrate the ProxyAgent to also be an interceptor in the next major?

It doesn't necessarily break it if the interceptor just passed a client factory that return the outer dispatcher?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@metcoder95

ghost commented Mar 10, 2024

Copy link
Copy Markdown
Member Author

Actually ProxyAgent might make sense as an interceptor if [kClient] is the outer dispatcher.

Your initial suggestion was doing that somehow, but that will mean break the current ProxyAgent; wdyt if we drop the ProxyInterceptor and we migrate the ProxyAgent to also be an interceptor in the next major?

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 client.connect to obtain the socket from the Proxy and pass it down to the connector for doing an upgrade if necessary.
We would need to provide a wrapper around that as well; but its true might be doable within minor

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ronag

ghost commented Mar 11, 2024

Copy link
Copy Markdown
Member

We can also just skip making it an interceptor. I'm fine with that.

metcoder95 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Carlos Fuentes
Merge branch 'main' into feat/compose-dispatch
eb065f7
ronag
ronag approved these changes Mar 12, 2024
View reviewed changes
Carlos Fuentes
feat: drop proxy
620f9bc
@metcoder95

ghost commented Mar 13, 2024

Copy link
Copy Markdown
Member Author

Dropped the proxy interceptor 👍

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mcollina
mcollina approved these changes Mar 13, 2024
View reviewed changes

ghost left a comment

Copy link
Copy Markdown
Member

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@ronag
ronag merged commit a1ee3ca into main Mar 13, 2024
@metcoder95
metcoder95 deleted the feat/compose-dispatch branch March 13, 2024 20:53
@mcollina mcollina mentioned this pull request Mar 18, 2024
Provide an alternative to interceptors #2802
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@mcollina mcollina mcollina approved these changes
@ronag ronag ronag approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@metcoder95 @ronag @codecov-commenter @mcollina
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.