Skip to content

Added duration header #3

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
wants to merge 1 commit into from
Closed

Added duration header #3

wants to merge 1 commit into from

Conversation

chr-hertel
Copy link

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Related tickets -
Documentation -
License MIT

What's in this PR?

Extended stopwatch plugin for bundle PR

}, function (Exception $exception) use ($eventName) {
$this->stopwatch->stop($eventName, self::CATEGORY);
$this->stopwatch->stop($eventName);
Copy link
Contributor

Choose a reason for hiding this comment

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

indeed, the category parameter seems unneeded according to https://github.com/symfony/stopwatch/blob/master/Stopwatch.php


return $response;
return $response->withHeader(self::HEADER, $event->getDuration());
Copy link
Contributor

Choose a reason for hiding this comment

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

i wonder if there is a more elegant way than modifying the response with an additional header.

Copy link
Member

Choose a reason for hiding this comment

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

AFAIK the stopwatch is supposed to be accessed from the outside as well so you can directly get event information from it. Isn't it what we do in HttplugBundle?

Copy link
Author

Choose a reason for hiding this comment

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

yep, same here, but i didn't find a better one. i think getting the information out of stopwatch in collector is not good option. i could introduce some kind of request registry which is used by stopwatch plugin and collector, but i think it would harden the coupling, which might not be the best idea as well. so i decided to go with a header and i think if a plugin manipulates the response with an additional header that's not such a weird behavior, but i clearly get your point. did i miss a good option to avoid the header?

Copy link
Member

Choose a reason for hiding this comment

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

Hm, so the problem is that we cannot map a request to a specific stopwatch event, right?

Because my idea was to use the stopwatch class and get the event based on something: http://api.symfony.com/3.2/Symfony/Component/Stopwatch/Stopwatch.html#method_getEvent

Maybe we could introduce an internal Request/Response ID header and use that in the event name, but that still feels hacky.

@dbu
Copy link
Contributor

dbu commented Mar 19, 2017 via email

@fbourigault
Copy link

fbourigault commented Mar 20, 2017

What about using decorators like I did in php-http/HttplugBundle#128? For this purpose, we explicitly excluded the header from possible tracking solutions.

EDIT: after a little more reading about the details of this PR, I would suggest to add to the stopwatch Symfony component the ability to use the event dispatcher and then by listening to stopwatch events, you will be able to write the request time into the collector current stack.

EDIT2: if doing so, you have to go fast with the stopwatch component as the 3.3 feature freeze less than 2 weeks away!

@chr-hertel
Copy link
Author

@fbourigault but in that case we would depend on symfony 3.3+ only, right?

@fbourigault
Copy link

The bundle will depends on symfony/stopwatch 3.3+. The bundle could ship a compatibility layer only used when symfony/stopwatch < 3.3 is installed.

@sagikazarmark
Copy link
Member

I haven't interfered to much with the bundle, but last time I checked it was >=3.0. Is it a good idea to drop support for <3.3?

@dbu
Copy link
Contributor

dbu commented Mar 22, 2017

i don't think we can bump all the way to symfony 3.3, unless stopwatch 3.3 can be installed together with symfony/symfony 3.1. i think that does not work, as symfony/symfony would contain stopwatch 3.1 and php is no table to handle multiple versions of the same dep afaik.

lets find a way that works with older versions (the header if we find nothing better) and keep this idea for a version 2 of the bundle. (would still require to work on the stopwatch pull request now to get it into symfony 3.3 so we actually can use it in version 2 of this bundle)

@fbourigault
Copy link

@dbu I posted an other proposal in the bundle PR.

@chr-hertel
Copy link
Author

Not needed anymore to solve php-http/HttplugBundle#135

@chr-hertel chr-hertel closed this Mar 22, 2017
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.

4 participants