diff --git a/etc/vitrage/api-paste.ini b/etc/vitrage/api-paste.ini index 12212735d..d20d0aadd 100644 --- a/etc/vitrage/api-paste.ini +++ b/etc/vitrage/api-paste.ini @@ -22,10 +22,10 @@ paste.app_factory = vitrage.api.app:app_factory root = vitrage.api.controllers.root.VersionsController [pipeline:vitragev1_keystone_pipeline] -pipeline = cors http_proxy_to_wsgi request_id authtoken vitragev1 +pipeline = cors http_proxy_to_wsgi request_id osprofiler authtoken vitragev1 [pipeline:vitragev1_noauth_pipeline] -pipeline = cors http_proxy_to_wsgi request_id vitragev1 +pipeline = cors http_proxy_to_wsgi request_id osprofiler vitragev1 [app:vitragev1] paste.app_factory = vitrage.api.app:app_factory @@ -45,3 +45,6 @@ oslo_config_project = vitrage [filter:http_proxy_to_wsgi] paste.filter_factory = oslo_middleware.http_proxy_to_wsgi:HTTPProxyToWSGI.factory oslo_config_project = vitrage + +[filter:osprofiler] +paste.filter_factory = osprofiler.web:WsgiMiddleware.factory diff --git a/etc/vitrage/vitrage-config-generator.conf b/etc/vitrage/vitrage-config-generator.conf index 4591d2f3d..9ebc83b99 100644 --- a/etc/vitrage/vitrage-config-generator.conf +++ b/etc/vitrage/vitrage-config-generator.conf @@ -7,4 +7,5 @@ namespace = oslo.middleware.healthcheck namespace = oslo.log namespace = oslo.middleware namespace = oslo.policy -namespace = keystonemiddleware.auth_token \ No newline at end of file +namespace = keystonemiddleware.auth_token +namespace = osprofiler diff --git a/requirements.txt b/requirements.txt index 4be0d324e..61f40e7e3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -28,3 +28,5 @@ stevedore>=1.20.0 # Apache-2.0 voluptuous>=0.8.9 # BSD License sympy>=0.7.6 # BSD pysnmp>=4.2.3 # BSD +osprofiler>=1.4.0 # Apache-2.0 + diff --git a/vitrage/cmd/api.py b/vitrage/cmd/api.py index 55f729a89..935c30e0e 100644 --- a/vitrage/cmd/api.py +++ b/vitrage/cmd/api.py @@ -12,6 +12,8 @@ # License for the specific language governing permissions and limitations # under the License. +import sys + from vitrage.api import app from vitrage import service @@ -19,3 +21,6 @@ from vitrage import service def main(): conf = service.prepare_service() app.build_server(conf) + +if __name__ == "__main__": + sys.exit(main()) diff --git a/vitrage/service.py b/vitrage/service.py index 9b80c1add..5249ae5b1 100644 --- a/vitrage/service.py +++ b/vitrage/service.py @@ -14,11 +14,14 @@ from oslo_config import cfg from oslo_log import log from oslo_policy import opts as policy_opts +from osprofiler import initializer as osprofiler_initializer +from osprofiler import opts as osprofiler_opts from vitrage import keystone_client from vitrage import messaging from vitrage import opts from vitrage.opts import register_opts + LOG = log.getLogger(__name__) @@ -27,6 +30,7 @@ def prepare_service(args=None, conf=None, config_files=None): conf = cfg.ConfigOpts() log.register_options(conf) policy_opts.set_defaults(conf) + osprofiler_opts.set_defaults(conf) for group, options in opts.list_opts(): conf.register_opts(list(options), @@ -35,6 +39,14 @@ def prepare_service(args=None, conf=None, config_files=None): conf(args, project='vitrage', validate_default_values=True, default_config_files=config_files) + if conf.profiler.enabled: + osprofiler_initializer.init_from_conf( + conf=conf, + context=None, + project="vitrage", + service="api", + host=conf.api.host) + for datasource in conf.datasources.types: register_opts(conf, datasource, conf.datasources.path)