Skip to content

Display discovered clients in the profiler #154

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

Merged
merged 1 commit into from
Apr 26, 2017
Merged

Display discovered clients in the profiler #154

merged 1 commit into from
Apr 26, 2017

Conversation

fbourigault
Copy link
Contributor

@fbourigault fbourigault commented Apr 19, 2017

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Related tickets fixes #133
Documentation N/A
License MIT

Content

Auto discovered clients were not visible in the profiler. This behavior is broken since at least 1.3. I didn't test any further back to find when it was broken.

This also fixes the root cause of #133. The easier way to test it is with knplabs/github-api.

The bug root cause was caused by the stopwatch plugin which was shared between every clients. When a client was configured, the stopwatch plugin gets decorated with the ProfilePlugin and when executed, no stack plugin was executed before.

About plugins state

So we have a plugin instance per client. I don't know if it's a good or a bad thing but we probably have to be clear on what to do. I think its ok to share a plugin if it is stateless, but if the plugin is stateful it should not be shared at all (like the StackPlugin which hold the client name).

I think we should choose a way to go, shared plugins or no shared plugins. Doing the choice will probably allow us to do some refactoring in the bundle container extension, which looks like really complicated to met.

Ping @Nyholm @sagikazarmark @dbu

@Nyholm
Copy link
Member

Nyholm commented Apr 24, 2017

I think it is fair to share plugins. The plugins should generally be stateless.. But the StackPlugin is special. Can it be treated in a special way o should we try to make it stateless?

@fbourigault
Copy link
Contributor Author

StackPlugin is already managed in a special way (i.e. not decorated with PluginClient).

I think we have to work on how plugins are decorated. If the plugin is a shared one, we have to register it once and decorate only once. If the plugin is defined in the client, from httplug catalogue (means stopwatch, redirect), we have to create an instance per client and decorate this instance.

What we can do for user created plugins? Shall we consider them like shared plugins and document that sharing a plugin not designed for can be harmful?

In the current definition, I would make all plugins from plugins.xml abstract, then iterate over the shared plugin configuration and create required plugins from abstract definition (decorated with ProfileClient if profiling is on).
Then loop over clients definition and create specific definition for httplug shipped plugins (decorated with ProfileClient).
For the user defined plugins, we have to write some logic to ensure that the service will be decorated only once with ProfileClient.

And then we add a StackPlugin as first plugin.

WDYT?

@Nyholm
Copy link
Member

Nyholm commented Apr 24, 2017

StackPlugin is already managed in a special way

Good

What we can do for user created plugins? Shall we consider them like shared plugins and document that sharing a plugin not designed for can be harmful

Yes.

I would make all plugins from plugins.xml abstract,

That is a BC break, right? Why don't we use the same logic for user defined plugins as we do with ours?

@fbourigault fbourigault changed the title [WIP] Add StackPlugin for discovered clients Add StackPlugin for discovered clients Apr 24, 2017
@fbourigault
Copy link
Contributor Author

That is a BC break, right? Why don't we use the same logic for user defined plugins as we do with ours?
This is probably a BC break. I will not change that.

I will share again the stopwatch plugin and only focus this PR on fixing #133.

$pluginServiceId = $serviceId.'.plugin.'.$pluginName;

$definition = class_exists(ChildDefinition::class)
? new ChildDefinition('httplug.plugin'.'.'.$pluginName)
Copy link
Member

Choose a reason for hiding this comment

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

There too many concats here.

ChildDefinition('httplug.plugin.'.$plug...

Copy link
Member

Choose a reason for hiding this comment

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

Same on the next line

@Nyholm
Copy link
Member

Nyholm commented Apr 24, 2017

Im testing this PR. The auto_discovered_client does not show up the the profiler.

@fbourigault fbourigault changed the title Add StackPlugin for discovered clients Display discovered clients in the profiler Apr 24, 2017
@fbourigault
Copy link
Contributor Author

Finally I focused this PR about displaying auto discovered clients in the profiler and fixing #133.

Copy link
Member

@Nyholm Nyholm left a comment

Choose a reason for hiding this comment

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

Excellent. I've tested the code and it works flawlessly.

Copy link
Collaborator

@dbu dbu left a comment

Choose a reason for hiding this comment

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

great work, thanks!

we can merge as is, or we can do our future selves a favor and add a line to each method to explain what it does (beyond what the method name says - some of the methods do have such one-liners and i find them helpful)


/**
* @param ContainerBuilder $container
* @param $pluginServiceId
Copy link
Collaborator

Choose a reason for hiding this comment

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

missing typehint

* @param string $pluginName
* @param array $pluginConfig
*
* @return string
Copy link
Collaborator

Choose a reason for hiding this comment

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

please add something like "service id for this plugin"

@fbourigault
Copy link
Contributor Author

Thanks for your review. I will add some description to extracted methods.

@fbourigault
Copy link
Contributor Author

I fixed issues pointed out by @dbu. I also added one line description for new methods. Proofreading is welcome!

Copy link
Collaborator

@dbu dbu left a comment

Choose a reason for hiding this comment

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

thanks! i went over the docs and commented where i am still confused. but we can totally merge as is, its quite some improvement in here! the comments that are left basically are things that are now more visible that i find confusing in the existing code already.

if you want to improve the phpdoc some more, please do but otherwise feel free to squash and merge.

->getDefinition('httplug.collector.plugin_journal')
->addMethodCall('setPlugins', [$name, ['httplug.plugin.stopwatch']])
;
// Add the newstack plugin
Copy link
Collaborator

Choose a reason for hiding this comment

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

new stack plugin? or newstack? if i guess correctly what we do here, lets do: // To profile requests, we put a stack plugin instance as first plugin in the chain, followed by the stopwatch plugin

*/
private function configureNewStackPlugin(ContainerBuilder $container, $clientName, $serviceId)
{
$pluginServiceId = $serviceId.'.plugin.newstack';
Copy link
Collaborator

Choose a reason for hiding this comment

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

i see that this is a refactoring and you just kept the previous name, but why do we call it "newstack"? its kind of confusing to me. its not really more new than other services, just specific to this httplug client, right?

*
* @param ContainerBuilder $container
* @param string $clientName
* @param string $serviceId
Copy link
Collaborator

Choose a reason for hiding this comment

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

is this the service id of a httplug client? if so, lets say that.

* Configure a new StackPlugin for a client.
*
* @param ContainerBuilder $container
* @param string $clientName
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is used to configure the stack plugin so that we can show the right client name in the profiler, right? maybe mention this here...

@fbourigault
Copy link
Contributor Author

@dbu I improved comments. Hope this is now easier to understand.

Copy link
Collaborator

@dbu dbu left a comment

Choose a reason for hiding this comment

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

LGTM

@fbourigault fbourigault merged commit 8c98056 into php-http:master Apr 26, 2017
@fbourigault fbourigault deleted the fix-missing-stack branch April 26, 2017 09:11
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.

There's not always a Stack on the Collector
4 participants