summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDolph Mathews <dolph.mathews@gmail.com>2015-04-24 20:05:35 +0000
committerDolph Mathews <dolph.mathews@gmail.com>2015-07-14 18:34:14 +0000
commit20fd5af10d1551721b9c95f51fbc166977c016ae (patch)
treec3e457aa6edb478729b6449a116a7df1e8a8229f
parent8125a8913d233f3da0eaacd09aa8e0b794ea98cb (diff)
downloadkeystone-20fd5af10d1551721b9c95f51fbc166977c016ae.tar.gz
Fix WSGI request logging
This is a backport of two patches that must be carried together. The first patch, which is a desirable backport, revealed a problem with middleware's handling of SCRIPT_NAME values, and so they must be backported together to avoid introducing a regression in a stable branch. The original commit messages are below. --- Allow wsgiref to reconstruct URIs per the WSGI spec Instead of reimplementing URL reconstruction for logging purposes, and getting it wrong over and over and over, let's just use wsgiref.util. Change-Id: Ib64877c35ad856bdef8f64f6df44a054eaa2321b Closes-Bug: 1448286 (cherry picked from commit f2a75866319c249e8ebdfb393172ab5ca8816b22) --- Fix req.environ[SCRIPT_NAME] value. The computation done inside /usr/local/lib/python2.7/dist-packages/routes/middleware.py was leaving req.environ[SCRIPT_NAME] with a wrong value with a repeated text block. No code in keystone seems to use the value of this variable, hence it has escaped detection until https://review.openstack.org/#/c/177427/ which logs req URLs by using SCRIPT_NAME in the url construction (via wsgiref.util.request_uri()). I backtraced the execution flow to the middleware.py file from the keystone middleware components. Prepending a '/' to the mapper path used in the ExtensionsRouter seems harmless as well as seems to fix the problem. See log files before and after, from sample Jenkins runs. BEFORE: http://goo.gl/YI89e4 AFTER (for this review): http://goo.gl/I1qVaI Closes-Bug:#1454968 Change-Id: Ia9bf1e1644c996e5aa71ac4e634ead3c4de7edcf (cherry picked from commit f7385b70b7556c703c96d86223d73d7e9beabd6b)
-rw-r--r--keystone/common/wsgi.py17
1 files changed, 8 insertions, 9 deletions
diff --git a/keystone/common/wsgi.py b/keystone/common/wsgi.py
index bbe3fc1d5..c0958f8ae 100644
--- a/keystone/common/wsgi.py
+++ b/keystone/common/wsgi.py
@@ -20,7 +20,7 @@
import copy
import itertools
-import urllib
+import wsgiref.util
from oslo_config import cfg
import oslo_i18n
@@ -227,11 +227,10 @@ class Application(BaseApplication):
# NOTE(morganfainberg): use the request method to normalize the
# response code between GET and HEAD requests. The HTTP status should
# be the same.
- req_method = req.environ['REQUEST_METHOD'].upper()
- LOG.info('%(req_method)s %(path)s?%(params)s', {
- 'req_method': req_method,
- 'path': context['path'],
- 'params': urllib.urlencode(req.params)})
+ LOG.info('%(req_method)s %(uri)s', {
+ 'req_method': req.environ['REQUEST_METHOD'].upper(),
+ 'uri': wsgiref.util.request_uri(req.environ),
+ })
params = self._normalize_dict(params)
@@ -270,7 +269,7 @@ class Application(BaseApplication):
response_code = self._get_response_code(req)
return render_response(body=result, status=response_code,
- method=req_method)
+ method=req.environ['REQUEST_METHOD'])
def _get_response_code(self, req):
req_method = req.environ['REQUEST_METHOD']
@@ -603,7 +602,7 @@ class ExtensionRouter(Router):
mapper = routes.Mapper()
self.application = application
self.add_routes(mapper)
- mapper.connect('{path_info:.*}', controller=self.application)
+ mapper.connect('/{path_info:.*}', controller=self.application)
super(ExtensionRouter, self).__init__(mapper)
def add_routes(self, mapper):
@@ -768,7 +767,7 @@ def render_response(body=None, status=None, headers=None, method=None):
status='%s %s' % status,
headerlist=headers)
- if method == 'HEAD':
+ if method and method.upper() == 'HEAD':
# NOTE(morganfainberg): HEAD requests should return the same status
# as a GET request and same headers (including content-type and
# content-length). The webob.Response object automatically changes