Skip to content

Add a discovery strategy #85

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 5 commits into from
Jul 15, 2016
Merged

Add a discovery strategy #85

merged 5 commits into from
Jul 15, 2016

Conversation

Nyholm
Copy link
Member

@Nyholm Nyholm commented Jul 3, 2016

The clients found by discovery is not logged by the dev toolbar. This PR will add a new strategy that make sure we find a configured client.

Problems

We need to make sure constructor of ConfiguredClientsStrategy is executed. Because everything in the dependency injection is cached we can rely on that.
A hack that will work is to register httplug.strategy as a event listener on kernel.request and console.command... Not sure if Im happy with that. Any input is welcome.

This PR is blocked by

@@ -0,0 +1,43 @@
<?php

namespace Http\HttplugBundle;
Copy link
Collaborator

Choose a reason for hiding this comment

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

should we put this in a sub-namespace "Discovery"?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure.

@dbu
Copy link
Collaborator

dbu commented Jul 4, 2016

this makes sense to me. what happens if we have no client explicitly configured? then the HttplugBundle uses discovery itself - do we have a chicken-and-egg problem here?

this is not complete yet, you need to prepend the discovery strategy so that it actually does something, right? do you want to add a container tag for discovery strategies? not sure how you can make this executed in the generated container, probably need to add a call to the definition of the discovery service itself?

@Nyholm
Copy link
Member Author

Nyholm commented Jul 4, 2016

this makes sense to me. what happens if we have no client explicitly configured? then the HttplugBundle uses discovery itself - do we have a chicken-and-egg problem here?

I believe that is fine as long as we fetch the HttpClient before we add the new strategy. Otherwise we will get problems with the discovery cache.

this is not complete yet, you need to prepend the discovery strategy so that it actually does something, right?

Correct.

do you want to add a container tag for discovery strategies? not sure how you can make this executed in the generated container, probably need to add a call to the definition of the discovery service itself?

Im not sure that will work. The problem is that there is not discovery service. It is a class with static properties that will forget their configuration at each request. We cant really use the dependency injection as you normally would. (As far as I know).

Feel free to make changes and try an idea if you got any. But remember to test the code with a prebuilt container as well.

@Nyholm
Copy link
Member Author

Nyholm commented Jul 13, 2016

This is ready for review and merge. A question that I want you to consider: Are we okey with the new strategy being injected on request and commands like this?

@dbu dbu merged commit 91f885c into master Jul 15, 2016
@dbu dbu deleted the dev-discovery branch July 15, 2016 13:48
@dbu
Copy link
Collaborator

dbu commented Jul 15, 2016

i think this makes sense, yes. thanks tobias!

do we need to document this somewhere? like saying in the bundle doc that the configured client will also be found by discovery?

@Nyholm
Copy link
Member Author

Nyholm commented Jul 15, 2016

I would say that would be pretty standard feature. I as a user do not care if it the client is auto-discovered or not.. What we should mention in the docs though is now we can log all HTTP messages sent by your application. The end developer does not need do to anything special but making sure their third-party libraries support HTTPlug.

".... So if you want a nice web debug toolbar integration for all request .... please send PRs to third party lib to use HTTPlug".

@Nyholm
Copy link
Member Author

Nyholm commented Jul 15, 2016

Thank you for merging BTW!

@sagikazarmark
Copy link
Member

To be honest, I am not sure about this: what if I have two separate client configured with separate authentication details, plugins, etc. What happens then if I call discovery somewhere in the middle of the code? Will it return one of the configured clients?

@dbu
Copy link
Collaborator

dbu commented Jul 15, 2016

as i understood, it will use the "default" client. and i think the doc should mention this. its not that obvious to me - auto discovery is not a feature of the HttplugBundle, so being explicit about it could avoid confusion. (but mention to prefer explicit injection if possible)

@sagikazarmark
Copy link
Member

okay, but let's say the default client in a micro-application is configured to use authentication and there is a base URL too. If I use the discovery in any library, I will get this client instead of a "pure" unconfigured one and that could cause problems. I would say people should use the bundle and the container to get a client and then it will be visible in the profiler. This way any other code (external library, etc) which uses the discovery could receive a non-functional client and could lead to a case which is quite hard to debug.

@sagikazarmark
Copy link
Member

Can we make this configurable? Discovery itself is already magic, and I am a little bit uncomfortable with too much magic. Personally I don't miss a non-configured client from the profiler, if any third party code uses the discovery. That's rather wrong configuration. But if this is always turned on then the scenario outlined above could cause many headaches.

@Nyholm
Copy link
Member Author

Nyholm commented Jul 15, 2016

You are correct @sagikazarmark. I did not think of that. This new Discovery is using the "default" client, ie the first configured client. That is not the same client as you would get if you use the CommonClassesStrategy.

The purpose of this PR is to enable the debug toolbar for auto discovered clients. It is not the purpose to configure clients for auto discovery.

@sagikazarmark
Copy link
Member

It is not the purpose to configure clients for auto discovery.

But this is what actually happens, isn't it? It registers the default client (discovered or manually configured) in the discovery.

@dbu
Copy link
Collaborator

dbu commented Jul 15, 2016

could we emulate normal discovery and then wrap the debug client around it? or otherwise have a configuration option to explicitly activate the feature, at which point the user is aware what client they are using. we could then even allow to specify which client to use...

@Nyholm
Copy link
Member Author

Nyholm commented Jul 15, 2016

But this is what actually happens, isn't it? It registers the default client (discovered or manually configured) in the discovery.

Yes, I'll make sure to update

@sagikazarmark
Copy link
Member

I think we can handle this in the strategy internally: when discovery starts set a static flag to true then call the discovery again. If the flag is already true, do not return candidates and allow the discovery to resolve a candidate, then wrap the client, clear the cache (?) and set the flag to false. Dunno if this could work.

Nyholm added a commit that referenced this pull request Jul 15, 2016
Adds a new discovery strategy to have discovery find the configured client.
@sagikazarmark
Copy link
Member

So what about this one? I would love to tag a new release after #84, but this one is a blocker IMO.

@Nyholm
Copy link
Member Author

Nyholm commented Jul 15, 2016

See https://github.com/php-http/HttplugBundle/tree/dev-conf-discovery

Im currently working on it.

Nyholm added a commit to Nyholm/HttplugBundle that referenced this pull request Jul 18, 2016
Adds a new discovery strategy to have discovery find the configured client.
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.

3 participants