Support new osprofiler API

Add connection_string config option that allows to specify the address
of the notifier's storage engine.

Co-Authored-By: Tovin Seven <vinhnt@vn.fujitsu.com>

Change-Id: Ifdfe2649020c610c76b318351e9448ad777352d5
Depends-On: I77d0d3b5e9e725507916724dcd28d5fbc6f7f5c7
This commit is contained in:
Alexey Yelistratov 2016-05-12 19:55:08 +03:00 committed by Tovin Seven
parent 0f1a2202c9
commit d48e967027
3 changed files with 69 additions and 12 deletions

View File

@ -31,9 +31,8 @@ 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
osprofiler_notifier = importutils.try_import('osprofiler.notifier') osprofiler_initializer = importutils.try_import('osprofiler.initializer')
profiler = importutils.try_import('osprofiler.profiler') profiler = importutils.try_import('osprofiler.profiler')
osprofiler_web = importutils.try_import('osprofiler.web')
profiler_opts = importutils.try_import('osprofiler.opts') profiler_opts = importutils.try_import('osprofiler.opts')
@ -87,19 +86,20 @@ if profiler_opts:
def setup_profiler(binary, host): def setup_profiler(binary, host):
if (osprofiler_notifier is None or if (osprofiler_initializer is None or
profiler is None or profiler is None or
osprofiler_web is None or
profiler_opts is None): profiler_opts is None):
LOG.debug('osprofiler is not present') LOG.debug('osprofiler is not present')
return return
if CONF.profiler.enabled: if CONF.profiler.enabled:
_notifier = osprofiler_notifier.create( osprofiler_initializer.init_from_conf(
"Messaging", messaging, context.get_admin_context().to_dict(), conf=CONF,
rpc.TRANSPORT, "cinder", binary, host) context=context.get_admin_context().to_dict(),
osprofiler_notifier.set(_notifier) project="cinder",
osprofiler_web.enable(CONF.profiler.hmac_keys) service=binary,
host=host
)
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 "
@ -108,10 +108,8 @@ def setup_profiler(binary, host):
"is no security issue. Note that even if person can " "is no security issue. Note that even if person can "
"trigger profiler, only admin user can retrieve trace " "trigger profiler, only admin user can retrieve trace "
"information.\n" "information.\n"
"To disable OSprofiler set in cinder.conf:\n" "To disable OSProfiler set in cinder.conf:\n"
"[profiler]\nenabled=false")) "[profiler]\nenabled=false"))
else:
osprofiler_web.disable()
class Service(service.Service): class Service(service.Service):

View File

@ -0,0 +1,52 @@
# Copyright 2016 Mirantis Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import mock
from cinder import service
from cinder import test
class SetupProfilerTestCase(test.TestCase):
def setUp(self):
super(SetupProfilerTestCase, self).setUp()
service.osprofiler_initializer = mock.MagicMock()
service.profiler = mock.MagicMock()
service.profiler_opts = mock.MagicMock()
service.osprofiler_initializer.init_from_conf = mock.MagicMock()
def test_profiler_not_present(self):
service.profiler = None
service.LOG.debug = mock.MagicMock()
service.setup_profiler("cinder-volume", "localhost")
service.LOG.debug.assert_called_once_with("osprofiler is not present")
@mock.patch("cinder.service.context")
def test_profiler_enabled(self, context):
service.CONF.profiler.enabled = True
return_value = {"Meaning Of Life": 42}
context.get_admin_context().to_dict.return_value = return_value
service.setup_profiler("cinder-volume", "localhost")
service.osprofiler_initializer.init_from_conf.assert_called_once_with(
conf=service.CONF,
context=return_value,
project="cinder",
service="cinder-volume",
host="localhost")
def test_profiler_disabled(self):
service.CONF.profiler.enabled = False
service.setup_profiler("cinder-volume", "localhost")
service.osprofiler_initializer.init_from_conf.assert_not_called()

View File

@ -0,0 +1,7 @@
---
upgrade:
- New config option added. ``"connection_string"`` in [profiler]
section is used to specify OSProfiler driver connection
string, for example,
``"connection_string = messaging://"``,
``"connection_string = mongodb://localhost:27017"``