Integrate OSProfiler and Nova
* Add osprofiler wsgi middleware. This middleware is used for 2 things: 1) It checks that person who want to trace is trusted and knows secret HMAC key. 2) It starts tracing in case of proper trace headers and adds the first wsgi trace point with info about the HTTP request * Add initialization of osprofiler on start of a service Currently that includes oslo.messaging notifier instance creation to send Ceilometer backend notifications. oslo-spec: https://review.openstack.org/#/c/103825/ python-novaclient change: https://review.openstack.org/#/c/254699/ based on: https://review.openstack.org/#/c/105096/ Co-Authored-By: Boris Pavlovic <boris@pavlovic.me> Co-Authored-By: Munoz, Obed N <obed.n.munoz@intel.com> Co-Authored-By: Roman Podoliaka <rpodolyaka@mirantis.com> Co-Authored-By: Tovin Seven <vinhnt@vn.fujitsu.com> Implements: blueprint osprofiler-support-in-nova Change-Id: I82d2badc8c1fcec27c3fce7c3c20e0f3b76414f1
This commit is contained in:
44
nova/rpc.py
44
nova/rpc.py
@@ -32,6 +32,7 @@ from oslo_log import log as logging
|
||||
import oslo_messaging as messaging
|
||||
from oslo_serialization import jsonutils
|
||||
from oslo_service import periodic_task
|
||||
from oslo_utils import importutils
|
||||
from oslo_utils import timeutils
|
||||
|
||||
import nova.conf
|
||||
@@ -40,6 +41,8 @@ import nova.exception
|
||||
from nova.i18n import _
|
||||
from nova import objects
|
||||
|
||||
profiler = importutils.try_import("osprofiler.profiler")
|
||||
|
||||
|
||||
CONF = nova.conf.CONF
|
||||
|
||||
@@ -150,13 +153,45 @@ class RequestContextSerializer(messaging.Serializer):
|
||||
return nova.context.RequestContext.from_dict(context)
|
||||
|
||||
|
||||
class ProfilerRequestContextSerializer(RequestContextSerializer):
|
||||
def serialize_context(self, context):
|
||||
_context = super(ProfilerRequestContextSerializer,
|
||||
self).serialize_context(context)
|
||||
|
||||
prof = profiler.get()
|
||||
if prof:
|
||||
# FIXME(DinaBelova): we'll add profiler.get_info() method
|
||||
# to extract this info -> we'll need to update these lines
|
||||
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)
|
||||
|
||||
return super(ProfilerRequestContextSerializer,
|
||||
self).deserialize_context(context)
|
||||
|
||||
|
||||
def get_transport_url(url_str=None):
|
||||
return messaging.TransportURL.parse(CONF, url_str, TRANSPORT_ALIASES)
|
||||
|
||||
|
||||
def get_client(target, version_cap=None, serializer=None):
|
||||
assert TRANSPORT is not None
|
||||
serializer = RequestContextSerializer(serializer)
|
||||
|
||||
if profiler:
|
||||
serializer = ProfilerRequestContextSerializer(serializer)
|
||||
else:
|
||||
serializer = RequestContextSerializer(serializer)
|
||||
|
||||
return messaging.RPCClient(TRANSPORT,
|
||||
target,
|
||||
version_cap=version_cap,
|
||||
@@ -165,7 +200,12 @@ def get_client(target, version_cap=None, serializer=None):
|
||||
|
||||
def get_server(target, endpoints, serializer=None):
|
||||
assert TRANSPORT is not None
|
||||
serializer = RequestContextSerializer(serializer)
|
||||
|
||||
if profiler:
|
||||
serializer = ProfilerRequestContextSerializer(serializer)
|
||||
else:
|
||||
serializer = RequestContextSerializer(serializer)
|
||||
|
||||
return messaging.get_rpc_server(TRANSPORT,
|
||||
target,
|
||||
endpoints,
|
||||
|
Reference in New Issue
Block a user