##// END OF EJS Templates
moved time measure of request to separate middleware for better results (the last one in stack)
marcink -
r3489:d997a314 beta
parent child Browse files
Show More
@@ -0,0 +1,47 b''
1 # -*- coding: utf-8 -*-
2 """
3 rhodecode.lib.middleware.wrapper
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5
6 request time mesuring app
7
8 :created_on: May 23, 2013
9 :author: marcink
10 :copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com>
11 :license: GPLv3, see COPYING for more details.
12 """
13 # This program is free software: you can redistribute it and/or modify
14 # it under the terms of the GNU General Public License as published by
15 # the Free Software Foundation, either version 3 of the License, or
16 # (at your option) any later version.
17 #
18 # This program is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU General Public License for more details.
22 #
23 # You should have received a copy of the GNU General Public License
24 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25 import time
26 import logging
27 from rhodecode.lib.base import _get_ip_addr, _get_access_path
28 from rhodecode.lib.utils2 import safe_unicode
29
30
31 class RequestWrapper(object):
32
33 def __init__(self, app, config):
34 self.application = app
35 self.config = config
36
37 def __call__(self, environ, start_response):
38 start = time.time()
39 try:
40 return self.application(environ, start_response)
41 finally:
42 log = logging.getLogger('rhodecode.' + self.__class__.__name__)
43 log.info('IP: %s Request to %s time: %.3fs' % (
44 _get_ip_addr(environ),
45 safe_unicode(_get_access_path(environ)), time.time() - start)
46 )
47
@@ -15,6 +15,7 b' from rhodecode.lib.middleware.simplehg i'
15 from rhodecode.lib.middleware.simplegit import SimpleGit
15 from rhodecode.lib.middleware.simplegit import SimpleGit
16 from rhodecode.lib.middleware.https_fixup import HttpsFixup
16 from rhodecode.lib.middleware.https_fixup import HttpsFixup
17 from rhodecode.config.environment import load_environment
17 from rhodecode.config.environment import load_environment
18 from rhodecode.lib.middleware.wrapper import RequestWrapper
18
19
19
20
20 def make_app(global_conf, full_stack=True, static_files=True, **app_conf):
21 def make_app(global_conf, full_stack=True, static_files=True, **app_conf):
@@ -67,7 +68,7 b' def make_app(global_conf, full_stack=Tru'
67 # need any pylons stack middleware in them
68 # need any pylons stack middleware in them
68 app = SimpleHg(app, config)
69 app = SimpleHg(app, config)
69 app = SimpleGit(app, config)
70 app = SimpleGit(app, config)
70
71 app = RequestWrapper(app, config)
71 # Display error documents for 401, 403, 404 status codes (and
72 # Display error documents for 401, 403, 404 status codes (and
72 # 500 when debug is disabled)
73 # 500 when debug is disabled)
73 if asbool(config['debug']):
74 if asbool(config['debug']):
@@ -279,7 +279,6 b' class BaseController(WSGIController):'
279 # WSGIController.__call__ dispatches to the Controller method
279 # WSGIController.__call__ dispatches to the Controller method
280 # the request is routed to. This routing information is
280 # the request is routed to. This routing information is
281 # available in environ['pylons.routes_dict']
281 # available in environ['pylons.routes_dict']
282 start = time.time()
283 try:
282 try:
284 self.ip_addr = _get_ip_addr(environ)
283 self.ip_addr = _get_ip_addr(environ)
285 # make sure that we update permissions each time we call controller
284 # make sure that we update permissions each time we call controller
@@ -300,10 +299,6 b' class BaseController(WSGIController):'
300 )
299 )
301 return WSGIController.__call__(self, environ, start_response)
300 return WSGIController.__call__(self, environ, start_response)
302 finally:
301 finally:
303 log.info('IP: %s Request to %s time: %.3fs' % (
304 _get_ip_addr(environ),
305 safe_unicode(_get_access_path(environ)), time.time() - start)
306 )
307 meta.Session.remove()
302 meta.Session.remove()
308
303
309
304
General Comments 0
You need to be logged in to leave comments. Login now