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:
Eric Harney 2016-02-10 14:27:49 -05:00
parent c79748c4ac
commit f55db19487
4 changed files with 31 additions and 21 deletions

View File

@ -33,9 +33,10 @@ from oslo_db import exception as db_exc
from oslo_db import options
from oslo_db.sqlalchemy import session as db_session
from oslo_log import log as logging
from oslo_utils import importutils
from oslo_utils import timeutils
from oslo_utils import uuidutils
import osprofiler.sqlalchemy
osprofiler_sqlalchemy = importutils.try_import('osprofiler.sqlalchemy')
import six
import sqlalchemy
from sqlalchemy import MetaData
@ -85,7 +86,7 @@ def _create_facade_lazily():
CONF.import_group("profiler", "cinder.service")
if CONF.profiler.profiler_enabled:
if CONF.profiler.trace_sqlalchemy:
osprofiler.sqlalchemy.add_tracing(sqlalchemy,
osprofiler_sqlalchemy.add_tracing(sqlalchemy,
_FACADE.get_engine(),
"db")

View File

@ -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,6 +124,7 @@ class RequestContextSerializer(messaging.Serializer):
def serialize_context(self, context):
_context = context.to_dict()
if profiler is not None:
prof = profiler.get()
if prof:
trace_info = {
@ -136,6 +138,7 @@ class RequestContextSerializer(messaging.Serializer):
def deserialize_context(self, context):
trace_info = context.pop("trace_info", None)
if trace_info:
if profiler is not None:
profiler.init(**trace_info)
return cinder.context.RequestContext.from_dict(context)

View File

@ -31,9 +31,9 @@ from oslo_service import loopingcall
from oslo_service import service
from oslo_service import wsgi
from oslo_utils import importutils
import osprofiler.notifier
from osprofiler import profiler
import osprofiler.web
osprofiler_notifier = importutils.try_import('osprofiler.notifier')
profiler = importutils.try_import('osprofiler.profiler')
osprofiler_web = importutils.try_import('osprofiler.web')
from cinder import context
from cinder import exception
@ -84,12 +84,18 @@ CONF.register_opts(profiler_opts, group="profiler")
def setup_profiler(binary, host):
if (osprofiler_notifier is None or
profiler is None or
osprofiler_web is None):
LOG.debug('osprofiler is not present')
return
if CONF.profiler.profiler_enabled:
_notifier = osprofiler.notifier.create(
_notifier = osprofiler_notifier.create(
"Messaging", messaging, context.get_admin_context().to_dict(),
rpc.TRANSPORT, "cinder", binary, host)
osprofiler.notifier.set(_notifier)
osprofiler.web.enable(CONF.profiler.hmac_keys)
osprofiler_notifier.set(_notifier)
osprofiler_web.enable(CONF.profiler.hmac_keys)
LOG.warning(
_LW("OSProfiler is enabled.\nIt means that person who knows "
"any of hmac_keys that are specified in "
@ -101,7 +107,7 @@ def setup_profiler(binary, host):
"To disable OSprofiler set in cinder.conf:\n"
"[profiler]\nprofiler_enabled=false"))
else:
osprofiler.web.disable()
osprofiler_web.disable()
class Service(service.Service):

View File

@ -49,7 +49,7 @@ from oslo_utils import importutils
from oslo_utils import timeutils
from oslo_utils import units
from oslo_utils import uuidutils
from osprofiler import profiler
profiler = importutils.try_import('osprofiler.profiler')
import six
from taskflow import exceptions as tfe
@ -238,7 +238,7 @@ class VolumeManager(manager.SchedulerDependentManager):
host=self.host,
is_vol_db_empty=vol_db_empty)
if CONF.profiler.profiler_enabled:
if CONF.profiler.profiler_enabled and profiler is not None:
self.driver = profiler.trace_cls("driver")(self.driver)
try:
self.extra_capabilities = jsonutils.loads(