{"action":"created","comment":{"url":"https://api.github.com/repos/superdesk/web-publisher/pulls/comments/66771278","id":66771278,"diff_hunk":"@@ -0,0 +1,91 @@\n+<?php\n+\n+/**\n+ * This file is part of the Superdesk Web Publisher Template Engine Bundle.\n+ *\n+ * Copyright 2015 Sourcefabric z.ú. and contributors.\n+ *\n+ * For the full copyright and license information, please see the\n+ * AUTHORS and LICENSE files distributed with this source code.\n+ *\n+ * @copyright 2016 Sourcefabric z.ú.\n+ * @license http://www.superdesk.org/license\n+ */\n+namespace SWP\\Bundle\\AnalyticsBundle\\EventListener;\n+\n+use SWP\\Bundle\\AnalyticsBundle\\Model\\RequestMetric;\n+use SWP\\Bundle\\AnalyticsBundle\\Repository\\RequestMetricRepository;\n+use Symfony\\Component\\HttpKernel\\Event\\FilterResponseEvent;\n+use Symfony\\Component\\HttpKernel\\Event\\GetResponseEvent;\n+use Symfony\\Component\\Stopwatch\\Stopwatch;\n+use Symfony\\Component\\Stopwatch\\StopwatchEvent;\n+\n+class KernelListener\n+{\n+    /**\n+     * @var Stopwatch\n+     */\n+    protected $stopwatch;\n+\n+    /**\n+     * @var StopwatchEvent\n+     */\n+    protected $stopwatchEvent;\n+\n+    /**\n+     * @var RequestMetricRepository\n+     */\n+    protected $requestMetricRepository;\n+\n+    public function setRequestMetricRepository(RequestMetricRepository $requestMetricRepository)\n+    {\n+        $this->requestMetricRepository = $requestMetricRepository;\n+    }\n+\n+    public function onKernelRequest(GetResponseEvent $event)\n+    {\n+        if (!$event->isMasterRequest()) {\n+            return;\n+        }\n+\n+        $route = $event->getRequest()->get('_route');\n+\n+        // Todo: check for configured routes\n+        // Ignore web debug toolbar\n+        if (null !== $route && '_wdt' !== $route) {\n+            $this->stopwatch = new Stopwatch();\n+            $this->stopwatch->start($event->getRequest()->getUri());\n+        }\n+    }\n+\n+\n+    public function onKernelResponse(FilterResponseEvent $event)\n+    {\n+        if (null !== $this->stopwatch) {\n+            return;\n+        }\n+\n+        $requestUri = $event->getRequest()->getUri();\n+\n+        // find out if this is a profiler request, if not don't analyze it\n+        try {\n+            $this->stopwatchEvent = $this->stopwatch->stop($requestUri);\n+        } catch (\\LogicException $e) {\n+            // do nothing, we shouldn't be analyzing this controller\n+            return false;\n+        }\n+\n+        $duration = $this->stopwatchEvent->getDuration();\n+        $route = $event->getRequest()->get('_route');\n+\n+        // Route is null here in test environment","path":"src/SWP/Bundle/AnalyticsBundle/EventListener/KernelListener.php","position":81,"original_position":81,"commit_id":"5fbb2cfc7cad6a7bafa68838427244bcec0eb8fa","original_commit_id":"5fbb2cfc7cad6a7bafa68838427244bcec0eb8fa","user":{"login":"djbrd-sourcefabric","id":17853717,"avatar_url":"https://avatars.githubusercontent.com/u/17853717?v=3","gravatar_id":"","url":"https://api.github.com/users/djbrd-sourcefabric","html_url":"https://github.com/djbrd-sourcefabric","followers_url":"https://api.github.com/users/djbrd-sourcefabric/followers","following_url":"https://api.github.com/users/djbrd-sourcefabric/following{/other_user}","gists_url":"https://api.github.com/users/djbrd-sourcefabric/gists{/gist_id}","starred_url":"https://api.github.com/users/djbrd-sourcefabric/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/djbrd-sourcefabric/subscriptions","organizations_url":"https://api.github.com/users/djbrd-sourcefabric/orgs","repos_url":"https://api.github.com/users/djbrd-sourcefabric/repos","events_url":"https://api.github.com/users/djbrd-sourcefabric/events{/privacy}","received_events_url":"https://api.github.com/users/djbrd-sourcefabric/received_events","type":"User","site_admin":false},"body":"This is only a problem in the test environment, as far as I can tell. The\nparameter is then set in the kernel.request event, but not in the\nkernel.response event.\n\nOn Mon, Jun 13, 2016 at 12:28 PM, Paweł Mikołajczuk <\nnotifications@github.com> wrote:\n\n> In src/SWP/Bundle/AnalyticsBundle/EventListener/KernelListener.php\n> <https://github.com/superdesk/web-publisher/pull/78#discussion_r66770282>:\n>\n> > +        }\n> > +\n> > +        $requestUri = $event->getRequest()->getUri();\n> > +\n> > +        // find out if this is a profiler request, if not don't analyze it\n> > +        try {\n> > +            $this->stopwatchEvent = $this->stopwatch->stop($requestUri);\n> > +        } catch (\\LogicException $e) {\n> > +            // do nothing, we shouldn't be analyzing this controller\n> > +            return false;\n> > +        }\n> > +\n> > +        $duration = $this->stopwatchEvent->getDuration();\n> > +        $route = $event->getRequest()->get('_route');\n> > +\n> > +        // Route is null here in test environment\n>\n> Why it's like that? If there can be a request without route then better\n> would be to move that check also to top. There is no point to play with\n> other things when at end you can't save it.\n>\n> —\n> You are receiving this because you authored the thread.\n> Reply to this email directly, view it on GitHub\n> <https://github.com/superdesk/web-publisher/pull/78/files/5fbb2cfc7cad6a7bafa68838427244bcec0eb8fa#r66770282>,\n> or mute the thread\n> <https://github.com/notifications/unsubscribe/ARBtFWTeCXyGi8hekbmNcoGVTYt-nOkkks5qLTDPgaJpZM4Ix7A->\n> .\n>\n","created_at":"2016-06-13T10:36:33Z","updated_at":"2016-06-13T10:36:33Z","html_url":"https://github.com/superdesk/web-publisher/pull/78#discussion_r66771278","pull_request_url":"https://api.github.com/repos/superdesk/web-publisher/pulls/78","_links":{"self":{"href":"https://api.github.com/repos/superdesk/web-publisher/pulls/comments/66771278"},"html":{"href":"https://github.com/superdesk/web-publisher/pull/78#discussion_r66771278"},"pull_request":{"href":"https://api.github.com/repos/superdesk/web-publisher/pulls/78"}}},"pull_request":{"url":"https://api.github.com/repos/superdesk/web-publisher/pulls/78","id":73205280,"html_url":"https://github.com/superdesk/web-publisher/pull/78","diff_url":"https://github.com/superdesk/web-publisher/pull/78.diff","patch_url":"https://github.com/superdesk/web-publisher/pull/78.patch","issue_url":"https://api.github.com/repos/superdesk/web-publisher/issues/78","number":78,"state":"open","locked":false,"title":"Thnkloud9analytics","user":{"login":"djbrd-sourcefabric","id":17853717,"avatar_url":"https://avatars.githubusercontent.com/u/17853717?v=3","gravatar_id":"","url":"https://api.github.com/users/djbrd-sourcefabric","html_url":"https://github.com/djbrd-sourcefabric","followers_url":"https://api.github.com/users/djbrd-sourcefabric/followers","following_url":"https://api.github.com/users/djbrd-sourcefabric/following{/other_user}","gists_url":"https://api.github.com/users/djbrd-sourcefabric/gists{/gist_id}","starred_url":"https://api.github.com/users/djbrd-sourcefabric/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/djbrd-sourcefabric/subscriptions","organizations_url":"https://api.github.com/users/djbrd-sourcefabric/orgs","repos_url":"https://api.github.com/users/djbrd-sourcefabric/repos","events_url":"https://api.github.com/users/djbrd-sourcefabric/events{/privacy}","received_events_url":"https://api.github.com/users/djbrd-sourcefabric/received_events","type":"User","site_admin":false},"body":"Simply starts a stopwatch on the kernel.request event, ends it on the kernel.response event, and saves the result with the name of the route, and the uri, in the db.\r\nI suggest that we configure which routes we want to show with a configuration file, which consists of a list of routes, each with a number representing the percentage of requests to that route we wish to measure. I would not maintain a count of how many times a route has been requested, but just compare the resutlt of rand(0, 100) with the given percentage to decide whether to measure the duration of the current request.  \r\n","created_at":"2016-06-09T12:33:01Z","updated_at":"2016-06-13T10:36:34Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e0ee9d875a0ef5af740cfe382fcf39569a4c2dbc","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/superdesk/web-publisher/pulls/78/commits","review_comments_url":"https://api.github.com/repos/superdesk/web-publisher/pulls/78/comments","review_comment_url":"https://api.github.com/repos/superdesk/web-publisher/pulls/comments{/number}","comments_url":"https://api.github.com/repos/superdesk/web-publisher/issues/78/comments","statuses_url":"https://api.github.com/repos/superdesk/web-publisher/statuses/5fbb2cfc7cad6a7bafa68838427244bcec0eb8fa","head":{"label":"djbrd-sourcefabric:thnkloud9analytics","ref":"thnkloud9analytics","sha":"5fbb2cfc7cad6a7bafa68838427244bcec0eb8fa","user":{"login":"djbrd-sourcefabric","id":17853717,"avatar_url":"https://avatars.githubusercontent.com/u/17853717?v=3","gravatar_id":"","url":"https://api.github.com/users/djbrd-sourcefabric","html_url":"https://github.com/djbrd-sourcefabric","followers_url":"https://api.github.com/users/djbrd-sourcefabric/followers","following_url":"https://api.github.com/users/djbrd-sourcefabric/following{/other_user}","gists_url":"https://api.github.com/users/djbrd-sourcefabric/gists{/gist_id}","starred_url":"https://api.github.com/users/djbrd-sourcefabric/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/djbrd-sourcefabric/subscriptions","organizations_url":"https://api.github.com/users/djbrd-sourcefabric/orgs","repos_url":"https://api.github.com/users/djbrd-sourcefabric/repos","events_url":"https://api.github.com/users/djbrd-sourcefabric/events{/privacy}","received_events_url":"https://api.github.com/users/djbrd-sourcefabric/received_events","type":"User","site_admin":false},"repo":{"id":54628948,"name":"web-publisher","full_name":"djbrd-sourcefabric/web-publisher","owner":{"login":"djbrd-sourcefabric","id":17853717,"avatar_url":"https://avatars.githubusercontent.com/u/17853717?v=3","gravatar_id":"","url":"https://api.github.com/users/djbrd-sourcefabric","html_url":"https://github.com/djbrd-sourcefabric","followers_url":"https://api.github.com/users/djbrd-sourcefabric/followers","following_url":"https://api.github.com/users/djbrd-sourcefabric/following{/other_user}","gists_url":"https://api.github.com/users/djbrd-sourcefabric/gists{/gist_id}","starred_url":"https://api.github.com/users/djbrd-sourcefabric/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/djbrd-sourcefabric/subscriptions","organizations_url":"https://api.github.com/users/djbrd-sourcefabric/orgs","repos_url":"https://api.github.com/users/djbrd-sourcefabric/repos","events_url":"https://api.github.com/users/djbrd-sourcefabric/events{/privacy}","received_events_url":"https://api.github.com/users/djbrd-sourcefabric/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/djbrd-sourcefabric/web-publisher","description":"Superdesk Web Publisher - the next generation publishing platform for journalists and newsrooms.","fork":true,"url":"https://api.github.com/repos/djbrd-sourcefabric/web-publisher","forks_url":"https://api.github.com/repos/djbrd-sourcefabric/web-publisher/forks","keys_url":"https://api.github.com/repos/djbrd-sourcefabric/web-publisher/keys{/key_id}","collaborators_url":"https://api.github.com/repos/djbrd-sourcefabric/web-publisher/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/djbrd-sourcefabric/web-publisher/teams","hooks_url":"https://api.github.com/repos/djbrd-sourcefabric/web-publisher/hooks","issue_events_url":"https://api.github.com/repos/djbrd-sourcefabric/web-publisher/issues/events{/number}","events_url":"https://api.github.com/repos/djbrd-sourcefabric/web-publisher/events","assignees_url":"https://api.github.com/repos/djbrd-sourcefabric/web-publisher/assignees{/user}","branches_url":"https://api.github.com/repos/djbrd-sourcefabric/web-publisher/branches{/branch}","tags_url":"https://api.github.com/repos/djbrd-sourcefabric/web-publisher/tags","blobs_url":"https://api.github.com/repos/djbrd-sourcefabric/web-publisher/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/djbrd-sourcefabric/web-publisher/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/djbrd-sourcefabric/web-publisher/git/refs{/sha}","trees_url":"https://api.github.com/repos/djbrd-sourcefabric/web-publisher/git/trees{/sha}","statuses_url":"https://api.github.com/repos/djbrd-sourcefabric/web-publisher/statuses/{sha}","languages_url":"https://api.github.com/repos/djbrd-sourcefabric/web-publisher/languages","stargazers_url":"https://api.github.com/repos/djbrd-sourcefabric/web-publisher/stargazers","contributors_url":"https://api.github.com/repos/djbrd-sourcefabric/web-publisher/contributors","subscribers_url":"https://api.github.com/repos/djbrd-sourcefabric/web-publisher/subscribers","subscription_url":"https://api.github.com/repos/djbrd-sourcefabric/web-publisher/subscription","commits_url":"https://api.github.com/repos/djbrd-sourcefabric/web-publisher/commits{/sha}","git_commits_url":"https://api.github.com/repos/djbrd-sourcefabric/web-publisher/git/commits{/sha}","comments_url":"https://api.github.com/repos/djbrd-sourcefabric/web-publisher/comments{/number}","issue_comment_url":"https://api.github.com/repos/djbrd-sourcefabric/web-publisher/issues/comments{/number}","contents_url":"https://api.github.com/repos/djbrd-sourcefabric/web-publisher/contents/{+path}","compare_url":"https://api.github.com/repos/djbrd-sourcefabric/web-publisher/compare/{base}...{head}","merges_url":"https://api.github.com/repos/djbrd-sourcefabric/web-publisher/merges","archive_url":"https://api.github.com/repos/djbrd-sourcefabric/web-publisher/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/djbrd-sourcefabric/web-publisher/downloads","issues_url":"https://api.github.com/repos/djbrd-sourcefabric/web-publisher/issues{/number}","pulls_url":"https://api.github.com/repos/djbrd-sourcefabric/web-publisher/pulls{/number}","milestones_url":"https://api.github.com/repos/djbrd-sourcefabric/web-publisher/milestones{/number}","notifications_url":"https://api.github.com/repos/djbrd-sourcefabric/web-publisher/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/djbrd-sourcefabric/web-publisher/labels{/name}","releases_url":"https://api.github.com/repos/djbrd-sourcefabric/web-publisher/releases{/id}","deployments_url":"https://api.github.com/repos/djbrd-sourcefabric/web-publisher/deployments","created_at":"2016-03-24T09:06:13Z","updated_at":"2016-03-24T09:06:13Z","pushed_at":"2016-06-13T10:08:59Z","git_url":"git://github.com/djbrd-sourcefabric/web-publisher.git","ssh_url":"git@github.com:djbrd-sourcefabric/web-publisher.git","clone_url":"https://github.com/djbrd-sourcefabric/web-publisher.git","svn_url":"https://github.com/djbrd-sourcefabric/web-publisher","homepage":"","size":1105,"stargazers_count":0,"watchers_count":0,"language":"PHP","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"superdesk:master","ref":"master","sha":"340fb6d20c13cf18028927af1ce7b6456d95b2c2","user":{"login":"superdesk","id":5527298,"avatar_url":"https://avatars.githubusercontent.com/u/5527298?v=3","gravatar_id":"","url":"https://api.github.com/users/superdesk","html_url":"https://github.com/superdesk","followers_url":"https://api.github.com/users/superdesk/followers","following_url":"https://api.github.com/users/superdesk/following{/other_user}","gists_url":"https://api.github.com/users/superdesk/gists{/gist_id}","starred_url":"https://api.github.com/users/superdesk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/superdesk/subscriptions","organizations_url":"https://api.github.com/users/superdesk/orgs","repos_url":"https://api.github.com/users/superdesk/repos","events_url":"https://api.github.com/users/superdesk/events{/privacy}","received_events_url":"https://api.github.com/users/superdesk/received_events","type":"Organization","site_admin":false},"repo":{"id":36218357,"name":"web-publisher","full_name":"superdesk/web-publisher","owner":{"login":"superdesk","id":5527298,"avatar_url":"https://avatars.githubusercontent.com/u/5527298?v=3","gravatar_id":"","url":"https://api.github.com/users/superdesk","html_url":"https://github.com/superdesk","followers_url":"https://api.github.com/users/superdesk/followers","following_url":"https://api.github.com/users/superdesk/following{/other_user}","gists_url":"https://api.github.com/users/superdesk/gists{/gist_id}","starred_url":"https://api.github.com/users/superdesk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/superdesk/subscriptions","organizations_url":"https://api.github.com/users/superdesk/orgs","repos_url":"https://api.github.com/users/superdesk/repos","events_url":"https://api.github.com/users/superdesk/events{/privacy}","received_events_url":"https://api.github.com/users/superdesk/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/superdesk/web-publisher","description":"Superdesk Web Publisher - the next generation publishing platform for journalists and newsrooms.","fork":false,"url":"https://api.github.com/repos/superdesk/web-publisher","forks_url":"https://api.github.com/repos/superdesk/web-publisher/forks","keys_url":"https://api.github.com/repos/superdesk/web-publisher/keys{/key_id}","collaborators_url":"https://api.github.com/repos/superdesk/web-publisher/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/superdesk/web-publisher/teams","hooks_url":"https://api.github.com/repos/superdesk/web-publisher/hooks","issue_events_url":"https://api.github.com/repos/superdesk/web-publisher/issues/events{/number}","events_url":"https://api.github.com/repos/superdesk/web-publisher/events","assignees_url":"https://api.github.com/repos/superdesk/web-publisher/assignees{/user}","branches_url":"https://api.github.com/repos/superdesk/web-publisher/branches{/branch}","tags_url":"https://api.github.com/repos/superdesk/web-publisher/tags","blobs_url":"https://api.github.com/repos/superdesk/web-publisher/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/superdesk/web-publisher/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/superdesk/web-publisher/git/refs{/sha}","trees_url":"https://api.github.com/repos/superdesk/web-publisher/git/trees{/sha}","statuses_url":"https://api.github.com/repos/superdesk/web-publisher/statuses/{sha}","languages_url":"https://api.github.com/repos/superdesk/web-publisher/languages","stargazers_url":"https://api.github.com/repos/superdesk/web-publisher/stargazers","contributors_url":"https://api.github.com/repos/superdesk/web-publisher/contributors","subscribers_url":"https://api.github.com/repos/superdesk/web-publisher/subscribers","subscription_url":"https://api.github.com/repos/superdesk/web-publisher/subscription","commits_url":"https://api.github.com/repos/superdesk/web-publisher/commits{/sha}","git_commits_url":"https://api.github.com/repos/superdesk/web-publisher/git/commits{/sha}","comments_url":"https://api.github.com/repos/superdesk/web-publisher/comments{/number}","issue_comment_url":"https://api.github.com/repos/superdesk/web-publisher/issues/comments{/number}","contents_url":"https://api.github.com/repos/superdesk/web-publisher/contents/{+path}","compare_url":"https://api.github.com/repos/superdesk/web-publisher/compare/{base}...{head}","merges_url":"https://api.github.com/repos/superdesk/web-publisher/merges","archive_url":"https://api.github.com/repos/superdesk/web-publisher/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/superdesk/web-publisher/downloads","issues_url":"https://api.github.com/repos/superdesk/web-publisher/issues{/number}","pulls_url":"https://api.github.com/repos/superdesk/web-publisher/pulls{/number}","milestones_url":"https://api.github.com/repos/superdesk/web-publisher/milestones{/number}","notifications_url":"https://api.github.com/repos/superdesk/web-publisher/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/superdesk/web-publisher/labels{/name}","releases_url":"https://api.github.com/repos/superdesk/web-publisher/releases{/id}","deployments_url":"https://api.github.com/repos/superdesk/web-publisher/deployments","created_at":"2015-05-25T08:04:59Z","updated_at":"2016-02-22T08:52:09Z","pushed_at":"2016-06-13T10:09:00Z","git_url":"git://github.com/superdesk/web-publisher.git","ssh_url":"git@github.com:superdesk/web-publisher.git","clone_url":"https://github.com/superdesk/web-publisher.git","svn_url":"https://github.com/superdesk/web-publisher","homepage":"","size":1844,"stargazers_count":5,"watchers_count":5,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":9,"mirror_url":null,"open_issues_count":8,"forks":9,"open_issues":8,"watchers":5,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/superdesk/web-publisher/pulls/78"},"html":{"href":"https://github.com/superdesk/web-publisher/pull/78"},"issue":{"href":"https://api.github.com/repos/superdesk/web-publisher/issues/78"},"comments":{"href":"https://api.github.com/repos/superdesk/web-publisher/issues/78/comments"},"review_comments":{"href":"https://api.github.com/repos/superdesk/web-publisher/pulls/78/comments"},"review_comment":{"href":"https://api.github.com/repos/superdesk/web-publisher/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/superdesk/web-publisher/pulls/78/commits"},"statuses":{"href":"https://api.github.com/repos/superdesk/web-publisher/statuses/5fbb2cfc7cad6a7bafa68838427244bcec0eb8fa"}}}}
{"actor":{"display_login":"djbrd-sourcefabric"}}