From 90d8f9b9c7beb3d7ab1c36b79acc989fcd5692d2 Mon Sep 17 00:00:00 2001 From: Kent Wang Date: Tue, 21 Apr 2015 05:16:37 -0700 Subject: [PATCH] API calls to Registry now maintain Request IDs Previously, glance-api calls to glance-registry did not include the req-UUID request ID in that call. Instead a single call to glance-api used separate request IDs for api and registry, leading to some difficulty in traceback, debugging, and tracking bugs going into glance and into registry. Previous example log in glance-api: 2015-04-21 07:25:10.359 126050 DEBUG glance.registry.client.v1.client [req-f2abec73-7a8c-4c5a-bded-f5eb82d627e4 5fca8fda352e46c7a006d4bf8083ab be 00eb1978c3394438b8988cd8a755f128 - - -] Registry request GET /images/ 05454482-f448-424b-ba9d-49d44a5af9fb HTTP 200 request id req-req-2433213 e-76c2-4ce3-95b6-d0db6cc8bdd0 do_request /opt/stack/glance/glance/ registry/client/v1/client.py:131 Updated example log in glance-api: 2015-04-21 07:27:33.057 126165 DEBUG glance.registry.client.v1.client [req-1787ffe1-0537-4357-a735-18412292434d 5fca8fda352e46c7a006d4bf8083ab be 00eb1978c3394438b8988cd8a755f128 - - -] Registry request GET /images/ 05454482-f448-424b-ba9d-49d44a5af9fb HTTP 200 request id req-req-1787ffe 1-0537-4357-a735-18412292434d do_request /opt/stack/glance/glance/ registry/client/v1/client.py:131 Now, when glance-api calls glance-registry, the api request_id is passed to registry. This helps to maintain the request ID for api and registry when user makes a single call to api. Change-Id: I871c1c17aca9af291598279db1d4057e217b4256 Closes-Bug: #1336958 --- glance/api/middleware/context.py | 1 + glance/registry/client/v1/api.py | 3 +++ glance/registry/client/v1/client.py | 5 +++++ 3 files changed, 9 insertions(+) diff --git a/glance/api/middleware/context.py b/glance/api/middleware/context.py index 3a51e403df..2683f95818 100644 --- a/glance/api/middleware/context.py +++ b/glance/api/middleware/context.py @@ -119,6 +119,7 @@ class ContextMiddleware(BaseContextMiddleware): 'owner_is_tenant': CONF.owner_is_tenant, 'service_catalog': service_catalog, 'policy_enforcer': self.policy_enforcer, + 'request_id': req.headers.get('X-Openstack-Request-ID'), } return glance.context.RequestContext(**kwargs) diff --git a/glance/registry/client/v1/api.py b/glance/registry/client/v1/api.py index a99e412d50..b594391af1 100644 --- a/glance/registry/client/v1/api.py +++ b/glance/registry/client/v1/api.py @@ -138,6 +138,9 @@ def get_registry_client(cxt): 'X-Service-Catalog': jsonutils.dumps(cxt.service_catalog), } kwargs['identity_headers'] = identity_headers + + kwargs['request_id'] = cxt.request_id + return client.RegistryClient(_CLIENT_HOST, _CLIENT_PORT, _METADATA_ENCRYPTION_KEY, **kwargs) diff --git a/glance/registry/client/v1/client.py b/glance/registry/client/v1/client.py index 26d038cc3c..1b73e52a36 100644 --- a/glance/registry/client/v1/client.py +++ b/glance/registry/client/v1/client.py @@ -48,6 +48,8 @@ class RegistryClient(BaseClient): # settings when using keystone. configure_via_auth=False disables # this behaviour to ensure we still send requests to the Registry API self.identity_headers = identity_headers + # store available passed request id for do_request call + self._passed_request_id = kwargs.pop('request_id', None) BaseClient.__init__(self, host, port, configure_via_auth=False, **kwargs) @@ -112,6 +114,9 @@ class RegistryClient(BaseClient): try: kwargs['headers'] = kwargs.get('headers', {}) kwargs['headers'].update(self.identity_headers or {}) + if self._passed_request_id: + kwargs['headers']['X-Openstack-Request-ID'] = \ + self._passed_request_id res = super(RegistryClient, self).do_request(method, action, **kwargs)