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

View File

@ -30,7 +30,8 @@ from oslo_config import cfg
from oslo_log import log as logging from oslo_log import log as logging
import oslo_messaging as messaging import oslo_messaging as messaging
from oslo_serialization import jsonutils 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.context
import cinder.exception import cinder.exception
@ -123,20 +124,22 @@ class RequestContextSerializer(messaging.Serializer):
def serialize_context(self, context): def serialize_context(self, context):
_context = context.to_dict() _context = context.to_dict()
prof = profiler.get() if profiler is not None:
if prof: prof = profiler.get()
trace_info = { if prof:
"hmac_key": prof.hmac_key, trace_info = {
"base_id": prof.get_base_id(), "hmac_key": prof.hmac_key,
"parent_id": prof.get_id() "base_id": prof.get_base_id(),
} "parent_id": prof.get_id()
_context.update({"trace_info": trace_info}) }
_context.update({"trace_info": trace_info})
return _context return _context
def deserialize_context(self, context): def deserialize_context(self, context):
trace_info = context.pop("trace_info", None) trace_info = context.pop("trace_info", None)
if trace_info: if trace_info:
profiler.init(**trace_info) if profiler is not None:
profiler.init(**trace_info)
return cinder.context.RequestContext.from_dict(context) 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 service
from oslo_service import wsgi from oslo_service import wsgi
from oslo_utils import importutils from oslo_utils import importutils
import osprofiler.notifier osprofiler_notifier = importutils.try_import('osprofiler.notifier')
from osprofiler import profiler profiler = importutils.try_import('osprofiler.profiler')
import osprofiler.web osprofiler_web = importutils.try_import('osprofiler.web')
from cinder import context from cinder import context
from cinder import exception from cinder import exception
@ -84,12 +84,18 @@ CONF.register_opts(profiler_opts, group="profiler")
def setup_profiler(binary, host): 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: if CONF.profiler.profiler_enabled:
_notifier = osprofiler.notifier.create( _notifier = osprofiler_notifier.create(
"Messaging", messaging, context.get_admin_context().to_dict(), "Messaging", messaging, context.get_admin_context().to_dict(),
rpc.TRANSPORT, "cinder", binary, host) rpc.TRANSPORT, "cinder", binary, host)
osprofiler.notifier.set(_notifier) osprofiler_notifier.set(_notifier)
osprofiler.web.enable(CONF.profiler.hmac_keys) osprofiler_web.enable(CONF.profiler.hmac_keys)
LOG.warning( LOG.warning(
_LW("OSProfiler is enabled.\nIt means that person who knows " _LW("OSProfiler is enabled.\nIt means that person who knows "
"any of hmac_keys that are specified in " "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" "To disable OSprofiler set in cinder.conf:\n"
"[profiler]\nprofiler_enabled=false")) "[profiler]\nprofiler_enabled=false"))
else: else:
osprofiler.web.disable() osprofiler_web.disable()
class Service(service.Service): class Service(service.Service):

View File

@ -49,7 +49,7 @@ from oslo_utils import importutils
from oslo_utils import timeutils from oslo_utils import timeutils
from oslo_utils import units from oslo_utils import units
from oslo_utils import uuidutils from oslo_utils import uuidutils
from osprofiler import profiler profiler = importutils.try_import('osprofiler.profiler')
import six import six
from taskflow import exceptions as tfe from taskflow import exceptions as tfe
@ -238,7 +238,7 @@ class VolumeManager(manager.SchedulerDependentManager):
host=self.host, host=self.host,
is_vol_db_empty=vol_db_empty) 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) self.driver = profiler.trace_cls("driver")(self.driver)
try: try:
self.extra_capabilities = jsonutils.loads( self.extra_capabilities = jsonutils.loads(