From 99c690f57e92c9e157113b58ccb85d6b1f0f70f5 Mon Sep 17 00:00:00 2001 From: Sean Dague Date: Thu, 25 May 2017 07:08:16 -0400 Subject: [PATCH] Migrate to oslo request_id middleware - mv 2.46 In order to support cross project request_id tracking, we need to be on oslo.middleware for request_id. This makes that change now that oslo middleware can support compat headers. api-ref is not updated yet because x-compute-request-id was apparently never documented there, and the timing on landing this is narrow because the moment a requirements update happens we'll have this new behavior. Part of bp:oslo-middleware-request-id Change-Id: I4d9f91b01de12cd0a676fc649953f98473b6b416 --- .../versions/v21-version-get-resp.json | 2 +- .../versions/versions-get-resp.json | 2 +- nova/api/compute_req_id.py | 30 +++++++------------ nova/api/openstack/api_version_request.py | 3 +- .../compute/rest_api_version_history.rst | 9 ++++++ nova/tests/unit/api/test_compute_req_id.py | 7 +++-- ...openstack-request-id-95f7bc7e960344a4.yaml | 10 +++++++ requirements.txt | 2 +- 8 files changed, 40 insertions(+), 25 deletions(-) create mode 100644 releasenotes/notes/openstack-request-id-95f7bc7e960344a4.yaml diff --git a/doc/api_samples/versions/v21-version-get-resp.json b/doc/api_samples/versions/v21-version-get-resp.json index f935867d3e8d..c52f282a993d 100644 --- a/doc/api_samples/versions/v21-version-get-resp.json +++ b/doc/api_samples/versions/v21-version-get-resp.json @@ -19,7 +19,7 @@ } ], "status": "CURRENT", - "version": "2.45", + "version": "2.46", "min_version": "2.1", "updated": "2013-07-23T11:33:21Z" } diff --git a/doc/api_samples/versions/versions-get-resp.json b/doc/api_samples/versions/versions-get-resp.json index e00ea77b5ca1..257f11a156fd 100644 --- a/doc/api_samples/versions/versions-get-resp.json +++ b/doc/api_samples/versions/versions-get-resp.json @@ -22,7 +22,7 @@ } ], "status": "CURRENT", - "version": "2.45", + "version": "2.46", "min_version": "2.1", "updated": "2013-07-23T11:33:21Z" } diff --git a/nova/api/compute_req_id.py b/nova/api/compute_req_id.py index 21985807c338..0b9301b51788 100644 --- a/nova/api/compute_req_id.py +++ b/nova/api/compute_req_id.py @@ -15,30 +15,22 @@ """Middleware that ensures x-compute-request-id -Using this middleware provides a convenient way to attach the -x-compute-request-id to only v2 responses. Previously, this header was set in -api/openstack/wsgi.py +Nova's notion of request-id tracking predates any common idea, so the +original version of this header in OpenStack was +x-compute-request-id. Eventually we got oslo, and all other projects +implemented this with x-openstack-request-id. + +However, x-compute-request-id was always part of our contract. The +following migrates us to use x-openstack-request-id as well, by using +the common middleware. -Responses for v2.1 API are taken care of by the request_id middleware provided -in oslo. """ -from oslo_context import context -from oslo_middleware import base -import webob.dec +from oslo_middleware import request_id -ENV_REQUEST_ID = 'openstack.request_id' HTTP_RESP_HEADER_REQUEST_ID = 'x-compute-request-id' -class ComputeReqIdMiddleware(base.Middleware): - - @webob.dec.wsgify - def __call__(self, req): - req_id = context.generate_request_id() - req.environ[ENV_REQUEST_ID] = req_id - response = req.get_response(self.application) - if HTTP_RESP_HEADER_REQUEST_ID not in response.headers: - response.headers.add(HTTP_RESP_HEADER_REQUEST_ID, req_id) - return response +class ComputeReqIdMiddleware(request_id.RequestId): + compat_headers = [HTTP_RESP_HEADER_REQUEST_ID] diff --git a/nova/api/openstack/api_version_request.py b/nova/api/openstack/api_version_request.py index a9b58d887f29..604374a4e7fd 100644 --- a/nova/api/openstack/api_version_request.py +++ b/nova/api/openstack/api_version_request.py @@ -109,6 +109,7 @@ REST_API_VERSION_HISTORY = """REST API Version History: header in the response for the snapshot image, they now return a json dict in the response body with an image_id key and uuid value. + * 2.46 - Return ``X-OpenStack-Request-ID`` header on requests. """ # The minimum and maximum versions of the API supported @@ -117,7 +118,7 @@ REST_API_VERSION_HISTORY = """REST API Version History: # Note(cyeoh): This only applies for the v2.1 API once microversions # support is fully merged. It does not affect the V2 API. _MIN_API_VERSION = "2.1" -_MAX_API_VERSION = "2.45" +_MAX_API_VERSION = "2.46" DEFAULT_API_VERSION = _MIN_API_VERSION # Almost all proxy APIs which related to network, images and baremetal diff --git a/nova/api/openstack/compute/rest_api_version_history.rst b/nova/api/openstack/compute/rest_api_version_history.rst index f2055bbea89f..1e28cf499cf2 100644 --- a/nova/api/openstack/compute/rest_api_version_history.rst +++ b/nova/api/openstack/compute/rest_api_version_history.rst @@ -536,3 +536,12 @@ user documentation. The ``createImage`` and ``createBackup`` server action APIs no longer return a ``Location`` header in the response for the snapshot image, they now return a json dict in the response body with an ``image_id`` key and uuid value. + +2.46 +---- + + The request_id created for every inbound request is now returned in + ``X-OpenStack-Request-ID`` in addition to ``X-Compute-Request-ID`` + to be consistent with the rest of OpenStack. This is a signaling + only microversion, as these header settings happen well before + microversion processing. diff --git a/nova/tests/unit/api/test_compute_req_id.py b/nova/tests/unit/api/test_compute_req_id.py index 473efefcef42..69fd111136ca 100644 --- a/nova/tests/unit/api/test_compute_req_id.py +++ b/nova/tests/unit/api/test_compute_req_id.py @@ -23,16 +23,19 @@ from nova.api import compute_req_id from nova import test +ENV_REQUEST_ID = 'openstack.request_id' + + class RequestIdTest(test.NoDBTestCase): def test_generate_request_id(self): @webob.dec.wsgify def application(req): - return req.environ[compute_req_id.ENV_REQUEST_ID] + return req.environ[ENV_REQUEST_ID] app = compute_req_id.ComputeReqIdMiddleware(application) req = webob.Request.blank('/test') req_id = context.generate_request_id() - req.environ[compute_req_id.ENV_REQUEST_ID] = req_id + req.environ[ENV_REQUEST_ID] = req_id res = req.get_response(app) res_id = res.headers.get(compute_req_id.HTTP_RESP_HEADER_REQUEST_ID) diff --git a/releasenotes/notes/openstack-request-id-95f7bc7e960344a4.yaml b/releasenotes/notes/openstack-request-id-95f7bc7e960344a4.yaml new file mode 100644 index 000000000000..1a007e8a03f1 --- /dev/null +++ b/releasenotes/notes/openstack-request-id-95f7bc7e960344a4.yaml @@ -0,0 +1,10 @@ +--- +features: + - | + Nova now uses oslo.middleware for request_id processing. This + means that there is now a new ``X-OpenStack-Request-ID`` header + returned on every request which mirrors the content of the + existing ``X-Compute-Request-ID``. The expected existence of this + header is signaled by Microversion 2.46. If server version >= 2.46, you + can expect to see this header in your results (regardless of + microversion requested). diff --git a/requirements.txt b/requirements.txt index 8e068926bc0b..f584b0b7936e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -49,7 +49,7 @@ oslo.privsep!=1.17.0,>=1.9.0 # Apache-2.0 oslo.i18n!=3.15.2,>=2.1.0 # Apache-2.0 oslo.service>=1.10.0 # Apache-2.0 rfc3986>=0.3.1 # Apache-2.0 -oslo.middleware>=3.10.0 # Apache-2.0 +oslo.middleware>=3.27.0 # Apache-2.0 psutil>=3.2.2 # BSD oslo.versionedobjects>=1.17.0 # Apache-2.0 os-brick>=1.13.0 # Apache-2.0