]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Profiler: make it possible to run without loading osprofiler
authorEric Harney <eharney@redhat.com>
Wed, 10 Feb 2016 19:27:49 +0000 (14:27 -0500)
committerEric Harney <eharney@redhat.com>
Wed, 10 Feb 2016 20:12:30 +0000 (15:12 -0500)
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

cinder/db/sqlalchemy/api.py
cinder/rpc.py
cinder/service.py
cinder/volume/manager.py

index e82edd8900066ae84e5e6d7234e2fd4c11d9e389..2390a46d7407fca86388a0f9d174416f854c55c3 100644 (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")
 
index 9ade49d14d8fb778efd7fcad948deea8ea364afe..a92fc0dd0986eb138e9f8c96b0766d223b2994b9 100644 (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,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)
 
index 08ca100d570b70b629fdae73de18f54d5cb9279d..5d03ee55b7550a3d9ba7b07455a475666f2b1210 100644 (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):
index f78ac4d4476047ebe2f1bf9af91df416a9d97a98..b5b15a658d8ac9affaa7b15267c4f2638eb170b6 100644 (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(