Profiler: make it possible to run without loading osprofiler
This makes it possible to run Cinder without having osprofiler installed. This is primarily to make it easier to debug issues and ensure that osprofiler is not introducing problems when debugging CI failures. Note that this requires disabling osprofiler in api-paste.ini as well. Related-Bug: #1541996 Change-Id: If00451524b87b949a2d5888a1157184f64cd0d59
This commit is contained in:
@@ -30,7 +30,8 @@ from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
import oslo_messaging as messaging
|
||||
from oslo_serialization import jsonutils
|
||||
from osprofiler import profiler
|
||||
from oslo_utils import importutils
|
||||
profiler = importutils.try_import('osprofiler.profiler')
|
||||
|
||||
import cinder.context
|
||||
import cinder.exception
|
||||
@@ -123,20 +124,22 @@ class RequestContextSerializer(messaging.Serializer):
|
||||
|
||||
def serialize_context(self, context):
|
||||
_context = context.to_dict()
|
||||
prof = profiler.get()
|
||||
if prof:
|
||||
trace_info = {
|
||||
"hmac_key": prof.hmac_key,
|
||||
"base_id": prof.get_base_id(),
|
||||
"parent_id": prof.get_id()
|
||||
}
|
||||
_context.update({"trace_info": trace_info})
|
||||
if profiler is not None:
|
||||
prof = profiler.get()
|
||||
if prof:
|
||||
trace_info = {
|
||||
"hmac_key": prof.hmac_key,
|
||||
"base_id": prof.get_base_id(),
|
||||
"parent_id": prof.get_id()
|
||||
}
|
||||
_context.update({"trace_info": trace_info})
|
||||
return _context
|
||||
|
||||
def deserialize_context(self, context):
|
||||
trace_info = context.pop("trace_info", None)
|
||||
if trace_info:
|
||||
profiler.init(**trace_info)
|
||||
if profiler is not None:
|
||||
profiler.init(**trace_info)
|
||||
|
||||
return cinder.context.RequestContext.from_dict(context)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user