From 0b9b8981f2802f21999325e028605157f0b1f11d Mon Sep 17 00:00:00 2001 From: Chris Dent Date: Thu, 22 Sep 2016 13:47:49 +0000 Subject: [PATCH] [placement] reorder middleware to correct logging context The initial bug was that the initial 'Starting' log provided by requestlog had a different request id from the rest of the log messages for the same request. The initial assumption was that this was because a request id was not initially available, causing one to be generated for the first log entry that later was replaced by the request id middleware. In the process of debugging that it became clear that the id was in fact the request id of the previous request because the context was being reused under the covers in oslo_log and olso_context. Therefore the auth, context and request id middlewares are now changed to be active in the middleware stack before the request log middleware. The unfortunate side effect of this is that the Starting message and final request logging is no longer actually bounding the full request: it misses three critical middlewares. Change-Id: Ifa412973037193e4e67a0c9d2c71c7a4847980a9 Closes-Bug: #1626493 --- nova/api/openstack/placement/deploy.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/nova/api/openstack/placement/deploy.py b/nova/api/openstack/placement/deploy.py index 9d9ee30be3e8..269a974ee1b8 100644 --- a/nova/api/openstack/placement/deploy.py +++ b/nova/api/openstack/placement/deploy.py @@ -49,12 +49,20 @@ def deploy(conf, project_name): application = handler.PlacementHandler() - for middleware in (context_middleware, - auth_middleware, - microversion_middleware, + # NOTE(cdent): The ordering here is important. The list is ordered + # from the inside out. For a single request req_id_middleware is called + # first and microversion_middleware last. Then the request is finally + # passed to the application (the PlacementHandler). At that point + # the response ascends the middleware in the reverse of the + # order the request went in. This order ensures that log messages + # all see the same contextual information including request id and + # authentication information. + for middleware in (microversion_middleware, fault_wrap, - req_id_middleware, request_log, + context_middleware, + auth_middleware, + req_id_middleware, ): application = middleware(application)