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
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
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'))
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
import webob
import cinder.api.middleware.auth
+from cinder.openstack.common.middleware import request_id
from cinder import test
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)
[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