diff --git a/releasenotes/notes/request-id-fdfe63effd88be78.yaml b/releasenotes/notes/request-id-fdfe63effd88be78.yaml new file mode 100644 index 000000000..0303a3d54 --- /dev/null +++ b/releasenotes/notes/request-id-fdfe63effd88be78.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - | + Now request id is returned by Watcher API in the `X-OpenStack-Request-ID` + response header. diff --git a/requirements.txt b/requirements.txt index 5d69fcc72..88e461d62 100644 --- a/requirements.txt +++ b/requirements.txt @@ -19,6 +19,7 @@ oslo.db>=4.44.0 # Apache-2.0 oslo.i18n>=3.20.0 # Apache-2.0 oslo.log>=3.37.0 # Apache-2.0 oslo.messaging>=14.1.0 # Apache-2.0 +oslo.middleware>=3.31.0 # Apache-2.0 oslo.policy>=4.5.0 # Apache-2.0 oslo.reports>=1.27.0 # Apache-2.0 oslo.serialization>=2.25.0 # Apache-2.0 diff --git a/watcher/api/app.py b/watcher/api/app.py index 66e798fcc..9d67066fe 100644 --- a/watcher/api/app.py +++ b/watcher/api/app.py @@ -17,6 +17,7 @@ # under the License. +from oslo_middleware import request_id import pecan from watcher.api import acl @@ -42,13 +43,22 @@ def setup_app(config=None): app_conf.pop('root'), logging=getattr(config, 'logging', {}), debug=CONF.debug, - wrap_app=parsable_error.ParsableErrorMiddleware, + wrap_app=_wrap_app, **app_conf ) return acl.install(app, CONF, config.app.acl_public_routes) +def _wrap_app(app): + """Wraps wsgi app with additional middlewares.""" + app = parsable_error.ParsableErrorMiddleware(app) + + app = request_id.RequestId(app) + + return app + + class VersionSelectorApplication(object): def __init__(self): pc = get_pecan_config() diff --git a/watcher/tests/api/test_root.py b/watcher/tests/api/test_root.py index 4da3b92c1..e95defd1d 100644 --- a/watcher/tests/api/test_root.py +++ b/watcher/tests/api/test_root.py @@ -24,6 +24,12 @@ class TestRoot(base.FunctionalTest): # Check fields are not empty [self.assertNotIn(f, ['', []]) for f in data.keys()] + # NOTE(tkajinam): Request ID should be present in any request so we verify + # it only at the root path. + def test_request_id(self): + resp = self.get_json('/', path_prefix='', return_json=False) + self.assertIn('X-OpenStack-Request-Id', resp.headers) + class TestV1Root(base.FunctionalTest):