]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Add x-openstack-request-id to cinder responses
authorChris Buccella <buccella@linux.vnet.ibm.com>
Fri, 14 Feb 2014 23:29:28 +0000 (23:29 +0000)
committerChris Buccella <buccella@linux.vnet.ibm.com>
Wed, 19 Feb 2014 17:09:23 +0000 (17:09 +0000)
x-openstack-request-id is the common header name for request ID going forward.
Currently, only glance and neutron return this header. Using the request_id
middleware is a convenient way to ensure this header is in the response. We will
also be using the middleware to generate the request ID.

The ID will be generated by the middleware and is inserted into the request
environment. The current code generates the request ID in the constructor of
RequestConext; with this change, the ID is generated beforehand and passed in to
the RequestContext constructor. Not much different here: a request ID is
generated and is available for use in the handling of the request.

On the response end, the middleware is again used, this time to attach the
x-openstack-request-id header, using the value of the generated request ID. The
current code attaches the x-compute-request-id header.

This change is a necessary step toward logging the mapping of request IDs across
OpenStack services.

UpgradeImpact: api-paste.ini is modified

Change-Id: I30c4e5efa77f9ebffb485d2ea6a6c3f78eb1573f
Implements: blueprint add-standard-req-id-header

cinder/api/middleware/auth.py
cinder/tests/api/middleware/test_auth.py
etc/cinder/api-paste.ini

index b1b4c999fffe2a6f228661a92f577b2724aeb5f5..8572949cfe4125a29ab771a5747624efdba312a0 100644 (file)
@@ -28,6 +28,7 @@ from cinder.api.openstack import wsgi
 from cinder import context
 from cinder.openstack.common import jsonutils
 from cinder.openstack.common import log as logging
+from cinder.openstack.common.middleware import request_id
 from cinder import wsgi as base_wsgi
 
 
@@ -91,6 +92,9 @@ class CinderKeystoneContext(base_wsgi.Middleware):
             project_id = req.headers['X_TENANT']
 
         project_name = req.headers.get('X_TENANT_NAME')
+
+        req_id = req.environ.get(request_id.ENV_REQUEST_ID)
+
         # Get the auth token
         auth_token = req.headers.get('X_AUTH_TOKEN',
                                      req.headers.get('X_STORAGE_TOKEN'))
@@ -115,7 +119,8 @@ class CinderKeystoneContext(base_wsgi.Middleware):
                                      roles=roles,
                                      auth_token=auth_token,
                                      remote_address=remote_address,
-                                     service_catalog=service_catalog)
+                                     service_catalog=service_catalog,
+                                     request_id=req_id)
 
         req.environ['cinder.context'] = ctx
         return self.application
index 600fed80de9f231c285ef0c6e64cec43ff5ad74d..bf602d7d4c9548e5f160eac31a0a00d57cc5e466 100644 (file)
@@ -15,6 +15,7 @@
 import webob
 
 import cinder.api.middleware.auth
+from cinder.openstack.common.middleware import request_id
 from cinder import test
 
 
@@ -65,3 +66,11 @@ class TestCinderKeystoneContextMiddleware(test.TestCase):
         self.assertEqual(response.status, '200 OK')
         self.assertEqual(self.context.project_id, 'testtenantid')
         self.assertEqual(self.context.project_name, 'testtenantname')
+
+    def test_request_id_extracted_from_env(self):
+        req_id = 'dummy-request-id'
+        self.request.headers['X_PROJECT_ID'] = 'testtenantid'
+        self.request.headers['X_USER_ID'] = 'testuserid'
+        self.request.environ[request_id.ENV_REQUEST_ID] = req_id
+        self.request.get_response(self.middleware)
+        self.assertEqual(req_id, self.context.request_id)
index 5bfd73822e2b1cf887e0c2f26d2baf386227e660..6829edbf665a14c0eb4aa87dc2927ebc5adf7b09 100644 (file)
@@ -10,15 +10,18 @@ use = call:cinder.api:root_app_factory
 
 [composite:openstack_volume_api_v1]
 use = call:cinder.api.middleware.auth:pipeline_factory
-noauth = faultwrap sizelimit noauth apiv1
-keystone = faultwrap sizelimit authtoken keystonecontext apiv1
-keystone_nolimit = faultwrap sizelimit authtoken keystonecontext apiv1
+noauth = request_id faultwrap sizelimit noauth apiv1
+keystone = request_id faultwrap sizelimit authtoken keystonecontext apiv1
+keystone_nolimit = request_id faultwrap sizelimit authtoken keystonecontext apiv1
 
 [composite:openstack_volume_api_v2]
 use = call:cinder.api.middleware.auth:pipeline_factory
-noauth = faultwrap sizelimit noauth apiv2
-keystone = faultwrap sizelimit authtoken keystonecontext apiv2
-keystone_nolimit = faultwrap sizelimit authtoken keystonecontext apiv2
+noauth = request_id faultwrap sizelimit noauth apiv2
+keystone = request_id faultwrap sizelimit authtoken keystonecontext apiv2
+keystone_nolimit = request_id faultwrap sizelimit authtoken keystonecontext apiv2
+
+[filter:request_id]
+paste.filter_factory = cinder.openstack.common.middleware.request_id:RequestIdMiddleware.factory
 
 [filter:faultwrap]
 paste.filter_factory = cinder.api.middleware.fault:FaultWrapper.factory