Fix a bug in the profiler serializer.
The profiler serializer, which is used if the osprofiler is installed, was initialized with None and therefore did not serialize the context. As a result, the context did not reach the api handler layer and was ignored. The solution: if the serializer is None, return the un-serialized context as is. Change-Id: I2317cff4014db2b4e437b2e9428bd936518d7ba8 Closes-Bug: #1707589
This commit is contained in:
parent
43f7ea634c
commit
99cc705c1b
@ -30,21 +30,22 @@ LOG = log.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
class ProfilerContextSerializer(messaging.Serializer):
|
class ProfilerContextSerializer(messaging.Serializer):
|
||||||
def __init__(self, base):
|
def __init__(self, serializer):
|
||||||
self._base = base
|
self._serializer = serializer
|
||||||
|
|
||||||
def serialize_entity(self, context, entity):
|
def serialize_entity(self, context, entity):
|
||||||
if not self._base:
|
if not self._serializer:
|
||||||
return entity
|
return entity
|
||||||
return self._base.serialize_entity(context, entity)
|
return self._serializer.serialize_entity(context, entity)
|
||||||
|
|
||||||
def deserialize_entity(self, context, entity):
|
def deserialize_entity(self, context, entity):
|
||||||
if not self._base:
|
if not self._serializer:
|
||||||
return entity
|
return entity
|
||||||
return self._base.deserialize_entity(context, entity)
|
return self._serializer.deserialize_entity(context, entity)
|
||||||
|
|
||||||
def serialize_context(self, context):
|
def serialize_context(self, context):
|
||||||
ctx = self._base.serialize_context(context) if self._base else {}
|
ctx = self._serializer.serialize_context(context) \
|
||||||
|
if self._serializer else context
|
||||||
|
|
||||||
pfr = profiler.get()
|
pfr = profiler.get()
|
||||||
|
|
||||||
@ -63,8 +64,8 @@ class ProfilerContextSerializer(messaging.Serializer):
|
|||||||
if trace_info:
|
if trace_info:
|
||||||
profiler.init(**trace_info)
|
profiler.init(**trace_info)
|
||||||
|
|
||||||
return self._base.deserialize_context(context)\
|
return self._serializer.deserialize_context(context)\
|
||||||
if self._base else context
|
if self._serializer else context
|
||||||
|
|
||||||
|
|
||||||
def set_defaults(control_exchange):
|
def set_defaults(control_exchange):
|
||||||
@ -76,7 +77,7 @@ def get_client(transport, target, version_cap=None, serializer=None):
|
|||||||
|
|
||||||
if profiler:
|
if profiler:
|
||||||
LOG.info('profiler enabled for RPC client')
|
LOG.info('profiler enabled for RPC client')
|
||||||
serializer = ProfilerContextSerializer(base=serializer)
|
serializer = ProfilerContextSerializer(serializer=serializer)
|
||||||
|
|
||||||
return messaging.RPCClient(transport,
|
return messaging.RPCClient(transport,
|
||||||
target,
|
target,
|
||||||
@ -89,7 +90,7 @@ def get_server(target, endpoints, transport, serializer=None):
|
|||||||
|
|
||||||
if profiler:
|
if profiler:
|
||||||
LOG.info('profiler enabled for RPC server')
|
LOG.info('profiler enabled for RPC server')
|
||||||
serializer = ProfilerContextSerializer(base=serializer)
|
serializer = ProfilerContextSerializer(serializer=serializer)
|
||||||
|
|
||||||
access_policy = dispatcher.DefaultRPCAccessPolicy
|
access_policy = dispatcher.DefaultRPCAccessPolicy
|
||||||
return messaging.get_rpc_server(transport,
|
return messaging.get_rpc_server(transport,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user