Log request ids
We collect request ids from the cloud if they're there. Then, the current approach is to attach them to the object - but they're ephemeral and not actually a quality of the object - they're useful for debugging. Instead of making an object property, log them. That way they can be used where they're useful - ops logs for after the fact debugging. The logger is named so that it can be explicitly controlled in a logging config. Change-Id: Ie5532cdc316cb00d5f15cae8b2a2f8674ae9da40
This commit is contained in:
parent
dd4bd63893
commit
1ad8c92d0a
5
releasenotes/notes/log-request-ids-37507cb6eed9a7da.yaml
Normal file
5
releasenotes/notes/log-request-ids-37507cb6eed9a7da.yaml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
other:
|
||||||
|
- The contents of x-openstack-request-id are no longer
|
||||||
|
added to object returned. Instead, they are logged to
|
||||||
|
a logger named 'shade.request_ids'.
|
@ -17,6 +17,7 @@ import munch
|
|||||||
import ipaddress
|
import ipaddress
|
||||||
import six
|
import six
|
||||||
|
|
||||||
|
from shade import _log
|
||||||
from shade import exc
|
from shade import exc
|
||||||
|
|
||||||
|
|
||||||
@ -394,9 +395,23 @@ def get_hostvars_from_server(cloud, server, mounts=None):
|
|||||||
return server_vars
|
return server_vars
|
||||||
|
|
||||||
|
|
||||||
def _add_request_id(obj, request_id):
|
def _log_request_id(obj, request_id):
|
||||||
|
# Add it, if passed in, even though we're going to pop in a second,
|
||||||
|
# just to make the logic simpler
|
||||||
if request_id is not None:
|
if request_id is not None:
|
||||||
obj['x_openstack_request_ids'] = [request_id]
|
obj['x_openstack_request_ids'] = [request_id]
|
||||||
|
|
||||||
|
request_id = None
|
||||||
|
request_ids = obj.pop('x_openstack_request_ids', None)
|
||||||
|
if request_ids:
|
||||||
|
request_id = request_ids[0]
|
||||||
|
if request_id:
|
||||||
|
log = _log.setup_logging('shade.request_ids')
|
||||||
|
# Log the request id and object id in a specific logger. This way
|
||||||
|
# someone can turn it on if they're interested in this kind of tracing.
|
||||||
|
log.debug("Retreived object {id}. Request ID {request_id}".format(
|
||||||
|
id=obj.get('id', obj.get('uuid')), request_id=request_id))
|
||||||
|
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
|
|
||||||
@ -417,7 +432,7 @@ def obj_to_dict(obj, request_id=None):
|
|||||||
return obj
|
return obj
|
||||||
elif hasattr(obj, 'schema') and hasattr(obj, 'validate'):
|
elif hasattr(obj, 'schema') and hasattr(obj, 'validate'):
|
||||||
# It's a warlock
|
# It's a warlock
|
||||||
return _add_request_id(warlock_to_dict(obj), request_id)
|
return _log_request_id(warlock_to_dict(obj), request_id)
|
||||||
elif isinstance(obj, dict):
|
elif isinstance(obj, dict):
|
||||||
# The new request-id tracking spec:
|
# The new request-id tracking spec:
|
||||||
# https://specs.openstack.org/openstack/nova-specs/specs/juno/approved/log-request-id-mappings.html
|
# https://specs.openstack.org/openstack/nova-specs/specs/juno/approved/log-request-id-mappings.html
|
||||||
@ -440,7 +455,7 @@ def obj_to_dict(obj, request_id=None):
|
|||||||
continue
|
continue
|
||||||
if isinstance(value, NON_CALLABLES) and not key.startswith('_'):
|
if isinstance(value, NON_CALLABLES) and not key.startswith('_'):
|
||||||
instance[key] = value
|
instance[key] = value
|
||||||
return _add_request_id(instance, request_id)
|
return _log_request_id(instance, request_id)
|
||||||
|
|
||||||
|
|
||||||
def obj_list_to_dict(obj_list, request_id=None):
|
def obj_list_to_dict(obj_list, request_id=None):
|
||||||
|
@ -288,9 +288,7 @@ class TestMemoryCache(base.TestCase):
|
|||||||
mock_compute.get.return_value = mock_response
|
mock_compute.get.return_value = mock_response
|
||||||
self.assertEqual([], self.cloud.list_flavors())
|
self.assertEqual([], self.cloud.list_flavors())
|
||||||
|
|
||||||
fake_flavor = fakes.FakeFlavor(
|
fake_flavor = fakes.FakeFlavor('555', 'vanilla', 100)
|
||||||
'555', 'vanilla', 100, dict(
|
|
||||||
x_openstack_request_ids=['request-id']))
|
|
||||||
fake_flavor_dict = _utils.normalize_flavors(
|
fake_flavor_dict = _utils.normalize_flavors(
|
||||||
[meta.obj_to_dict(fake_flavor)]
|
[meta.obj_to_dict(fake_flavor)]
|
||||||
)[0]
|
)[0]
|
||||||
|
Loading…
Reference in New Issue
Block a user