Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[HttpClient] Added TraceableHttpClient and WebProfiler panel #30494

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

Closed

Conversation

jeremyFreeAgent
Copy link
Contributor

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets
License MIT
Doc PR

That PR adds TraceableHttpClient and the DataCollector.

Needs #30419 for the integration of HttpClient in FrameworkBundle.

Preview:
screenshot 2019-03-08 at 17 50 30

@nicolas-grekas nicolas-grekas added this to the next milestone Mar 8, 2019
@jeremyFreeAgent jeremyFreeAgent changed the title ❤️ Added TraceableHttpClient and DataCollector Added TraceableHttpClient and DataCollector Mar 8, 2019
@nicolas-grekas nicolas-grekas changed the title Added TraceableHttpClient and DataCollector [HttpClient] Added TraceableHttpClient and DataCollector Mar 8, 2019
@nicolas-grekas nicolas-grekas mentioned this pull request Mar 9, 2019
18 tasks
Copy link
Contributor

@HeahDude HeahDude left a comment

Choose a reason for hiding this comment

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

Thank you for that PR!

@nicolas-grekas
Copy link
Member

Unlocked: FrameworkBundle integration PR is now merged, see #30419

@jeremyFreeAgent
Copy link
Contributor Author

@nicolas-grekas great news thanks!

@jeremyFreeAgent jeremyFreeAgent marked this pull request as ready for review April 5, 2019 15:06
@jeremyFreeAgent
Copy link
Contributor Author

Thank you @nicolas-grekas for the OnProgress trick.

@IonBazan
Copy link
Contributor

IonBazan commented Jun 7, 2019

@jeremyFreeAgent Do you need any help on this?

@jeremyFreeAgent
Copy link
Contributor Author

Sorry guys for the delay. I've to focus on work these past weeks.

I rework missing things that week.

Thanks for the up @IonBazan

@IonBazan
Copy link
Contributor

Thing to consider: using Stopwatch to track the timing.

@nicolas-grekas nicolas-grekas changed the base branch from master to 4.4 June 19, 2019 07:19
@nicolas-grekas nicolas-grekas changed the title [HttpClient] Added TraceableHttpClient and DataCollector [HttpClient] Added TraceableHttpClient and WebProfiler panel Jun 19, 2019
@nicolas-grekas nicolas-grekas force-pushed the traceable-http-client branch 4 times, most recently from 6291ef0 to 744d361 Compare June 19, 2019 11:00
@nicolas-grekas
Copy link
Member

nicolas-grekas commented Jun 19, 2019

I squashed all commits and made some changes to show what we can collect.
One missing step for this PR: add tests please.
Note that the displayed options are the ones passed to the "request" method. Any others set by scoping clients are not shown. Of course, the response info will still contain their side-effects when there is one visible (eg added headers, absolute URL, etc)

For future PRs (let's make this one mergeable asap):

  • the panel UI could be improved I suppose
  • putting requests in the "Performance" tab would be great (all timings are already in the collected "info")
  • response bodies are not collected yet
  • when a transport error occurs, (ie the "error" info is populated) we should maybe have a better display too?
  • add "copy as curl" button

Note that it should be possible to collect a response that didn't complete yet (eg http_code is 0), since everything is lazy. The twig file shouldn't break when this happens.

Here is an example output:
image

@nicolas-grekas nicolas-grekas force-pushed the traceable-http-client branch from 744d361 to 37b6851 Compare June 19, 2019 11:16
@nicolas-grekas nicolas-grekas force-pushed the traceable-http-client branch from 37b6851 to b4b2097 Compare June 19, 2019 11:27
@IonBazan
Copy link
Contributor

@nicolas-grekas Thank you for your changes. To be honest, I am not a fan of simply dumping all the collected data in profiler UI. For example, headers and performance information should be presented in more "structured" way. What do you think?

I will add tests by the end of this week to make it mergeable 😄

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Jun 20, 2019

@IonBazan sure, that's why it's the 1st item in my list for a future PRs. For headers, don't forget about redirections (try one you'll see what I mean when working on this). Waiting for the tests, thanks!

@tsantos84
Copy link
Contributor

Sometimes we need to make lot of external requests and the profiler can have a big scroll to show all the information of all requests. A simple suggestion is to add a collapse button (like in messager panel) in each collected request and start all of them collapsed excepted the first one of each configured http client. To help quickly see the status of each request (considering it is hide) you can add the status code before the method on request's title.

@tsantos84
Copy link
Contributor

Collapse in/out of messenger panel.

Messenger Panel

@nicolas-grekas
Copy link
Member

One more idea added to my list above: add a copy-as-curl button next to each request in the profiler panel.

@@ -1898,6 +1908,19 @@ private function registerHttpClientConfiguration(array $config, ContainerBuilder
->setArguments([new Reference('http_client'), [$scope => $scopeConfig], $scope]);
}

if ($debug) {
Copy link
Member

Choose a reason for hiding this comment

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

It could be interesting to add a tag to the service a this point, and to do the wiring logic in a compiler pass for all services having this tag. It will allow bundles to easily plug their own clients in the profiler.

For instance, we have this use case in API Platform.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm almost done except your comment.

To be sure to get your point I looked the Messenger stuff. So we are ok to add a tag to all http client here https://github.com/symfony/symfony/blob/4.4/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php#L1946-L1953
Like http_client.client ?

Then adding a HttpClientPass to make the call to the dataCollector in all service tagged with http_client.client. (if data_collector is registered of course).

Right ?

@fabpot
Copy link
Member

fabpot commented Jul 8, 2019

@jeremyFreeAgent What's the next step? Can we merge something fast and iterate from there?


<service id="debug.http_client" class="Symfony\Component\HttpClient\TraceableHttpClient" decorates="http_client">
<argument type="service" id="debug.http_client.inner" />
</service>
Copy link
Member

Choose a reason for hiding this comment

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

I would move these definitions to a http_client_debug.xml file like done for other components.

@tyx
Copy link
Contributor

tyx commented Aug 6, 2019

Hi guys, I had a talk with @jeremyFreeAgent and I will help on this PR.

Apparently, we only miss test to merge ? And then continue to work with small PR about refinements ?

On my side what is the best way to work with this ongoing PR ? Start another PR by adding the jeremy's commit or we can do better ?

@nicolas-grekas
Copy link
Member

you could create a new PR that would start with the commit in this PR, and add yours on top

@fabpot
Copy link
Member

fabpot commented Aug 6, 2019

And please, can you take the remaining comments into accounts?

@chalasr
Copy link
Member

chalasr commented Aug 19, 2019

Closing in favor of #33015. Thanks for your work @jeremyFreeAgent

@chalasr chalasr closed this Aug 19, 2019
@nicolas-grekas nicolas-grekas self-assigned this Aug 23, 2019
@nicolas-grekas
Copy link
Member

See also #33311

nicolas-grekas added a commit that referenced this pull request Aug 23, 2019
… panel (jeremyFreeAgent)

This PR was merged into the 4.4 branch.

Discussion
----------

[HttpClient] Added TraceableHttpClient and WebProfiler panel

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | yes <!-- please update src/**/CHANGELOG.md files -->
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

Replace #30494

I added :
- tests
- move debug services declaration in dedicated `http_client_debug.xml` file
- rename stuff to follow messenger data collector stuff
- add CompilerPass to allow bundle to trace their own http client

I didn't add all @nicolas-grekas requests on UI profiler. I will continue to make more PR after this one.

IMO everything looks fine to make a first merge except one strange behavior that I am not sure to get :

When making a sub request :
- we still have the http_client parent data. (like messenger, but currently I did not see anything in code that could avoid that, so different topic I guess).
- The data collected are already "converted" to VarDumper data, so I have errors when trying to do all the unset stuff in the TraceableHttpClient.

Is it for this reason, some collector use `lateCollect` ? Should we also move to lateCollect in the `HttpClientDataCollector` ?

But I'm still new on this subject but glad to help, so feel free to request more changes !

Commits
-------

5164001 [HttpClient] Added TraceableHttpClient and WebProfiler panel
@nicolas-grekas nicolas-grekas modified the milestones: next, 4.4 Oct 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.