diff --git a/placement/deploy.py b/placement/deploy.py index e7faa9703..5e3ac373f 100644 --- a/placement/deploy.py +++ b/placement/deploy.py @@ -15,6 +15,7 @@ import os from microversion_parse import middleware as mp_middleware import oslo_middleware +from oslo_utils import importutils from placement import auth from placement.db.sqlalchemy import migration @@ -30,6 +31,10 @@ from placement import resource_class_cache as rc_cache from placement import util +os_profiler = importutils.try_import('osprofiler.profiler') +os_profiler_web = importutils.try_import('osprofiler.web') + + PROFILER_OUTPUT = os.environ.get('OS_WSGI_PROFILER') if PROFILER_OUTPUT: # If werkzeug is not available this raises ImportError and the @@ -63,6 +68,12 @@ def deploy(conf): fault_middleware = fault_wrap.FaultWrapper request_log = requestlog.RequestLog + if os_profiler_web and 'profiler' in conf and conf.profiler.enabled: + osprofiler_middleware = os_profiler_web.WsgiMiddleware.factory( + {}, **conf.profiler) + else: + osprofiler_middleware = None + application = handler.PlacementHandler(config=conf) # If PROFILER_OUTPUT is set, generate per request profile reports @@ -90,6 +101,7 @@ def deploy(conf): auth_middleware, cors_middleware, req_id_middleware, + osprofiler_middleware, ): if middleware: application = middleware(application) diff --git a/placement/wsgi.py b/placement/wsgi.py index 6d347d86e..655b79eb2 100644 --- a/placement/wsgi.py +++ b/placement/wsgi.py @@ -30,6 +30,8 @@ from placement import db_api from placement import deploy +osprofiler = importutils.try_import('osprofiler') +osprofiler_initializer = importutils.try_import('osprofiler.initializer') profiler = importutils.try_import('osprofiler.opts') @@ -86,6 +88,16 @@ def _parse_args(config, argv, default_config_files): default_config_files=default_config_files) +def setup_profiler(config): + if osprofiler and config.profiler.enabled: + osprofiler.initializer.init_from_conf( + conf=config, + context={}, + project="placement", + service="placement", + host="??") + + def _set_middleware_defaults(): """Update default configuration options for oslo.middleware.""" cors.set_defaults( @@ -134,5 +146,7 @@ def init_application(): logging.getLogger(__name__), logging.DEBUG) + setup_profiler(config) + # build and return our WSGI app return deploy.loadapp(config) diff --git a/releasenotes/notes/fix-osprofiler-support-78b34a92c32fd30f.yaml b/releasenotes/notes/fix-osprofiler-support-78b34a92c32fd30f.yaml new file mode 100644 index 000000000..e2ef273db --- /dev/null +++ b/releasenotes/notes/fix-osprofiler-support-78b34a92c32fd30f.yaml @@ -0,0 +1,7 @@ +--- +fixes: + - | + By fixing bug `story/2005842`_ the OSProfiler support works again in the + placement WSGI. + + .. _story/2005842: https://storyboard.openstack.org/#!/story/2005842