Merge "Add support for osprofiler in wsgi"
This commit is contained in:
commit
e214ef3734
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue