Integrate OSprofiler in Magnum Client
Add OSprofiler support in Magnum Client Co-Authored-By: Hieu LE <hieulq@vn.fujitsu.com> Change-Id: I85f766f636f754fc6ad8e28e3df2793cd02a618e Depends-On: I7d68995aab81d365433950aada078ef1fcd5469b Implements: blueprint osprofiler-support-in-magnum
This commit is contained in:
parent
af7e5f605a
commit
1c2385ca55
@ -23,11 +23,13 @@ import socket
|
|||||||
import ssl
|
import ssl
|
||||||
|
|
||||||
from keystoneauth1 import adapter
|
from keystoneauth1 import adapter
|
||||||
|
from oslo_utils import importutils
|
||||||
import six
|
import six
|
||||||
import six.moves.urllib.parse as urlparse
|
import six.moves.urllib.parse as urlparse
|
||||||
|
|
||||||
from magnumclient import exceptions
|
from magnumclient import exceptions
|
||||||
|
|
||||||
|
osprofiler_web = importutils.try_import("osprofiler.web")
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
USER_AGENT = 'python-magnumclient'
|
USER_AGENT = 'python-magnumclient'
|
||||||
@ -330,6 +332,10 @@ class SessionClient(adapter.LegacyJsonAdapter):
|
|||||||
# Copy the kwargs so we can reuse the original in case of redirects
|
# Copy the kwargs so we can reuse the original in case of redirects
|
||||||
kwargs['headers'] = copy.deepcopy(kwargs.get('headers', {}))
|
kwargs['headers'] = copy.deepcopy(kwargs.get('headers', {}))
|
||||||
kwargs['headers'].setdefault('User-Agent', self.user_agent)
|
kwargs['headers'].setdefault('User-Agent', self.user_agent)
|
||||||
|
# NOTE(tovin07): osprofiler_web.get_trace_id_headers does not add any
|
||||||
|
# headers in case if osprofiler is not initialized.
|
||||||
|
if osprofiler_web:
|
||||||
|
kwargs['headers'].update(osprofiler_web.get_trace_id_headers())
|
||||||
if self.api_version:
|
if self.api_version:
|
||||||
version_string = 'container-infra %s' % self.api_version
|
version_string = 'container-infra %s' % self.api_version
|
||||||
kwargs['headers'].setdefault(
|
kwargs['headers'].setdefault(
|
||||||
|
@ -30,9 +30,12 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
from oslo_utils import encodeutils
|
from oslo_utils import encodeutils
|
||||||
|
from oslo_utils import importutils
|
||||||
from oslo_utils import strutils
|
from oslo_utils import strutils
|
||||||
import six
|
import six
|
||||||
|
|
||||||
|
profiler = importutils.try_import("osprofiler.profiler")
|
||||||
|
|
||||||
HAS_KEYRING = False
|
HAS_KEYRING = False
|
||||||
all_errors = ValueError
|
all_errors = ValueError
|
||||||
try:
|
try:
|
||||||
@ -422,6 +425,19 @@ class OpenStackMagnumShell(object):
|
|||||||
action='store_true',
|
action='store_true',
|
||||||
help=_("Do not verify https connections"))
|
help=_("Do not verify https connections"))
|
||||||
|
|
||||||
|
if profiler:
|
||||||
|
parser.add_argument('--profile',
|
||||||
|
metavar='HMAC_KEY',
|
||||||
|
help='HMAC key to use for encrypting context '
|
||||||
|
'data for performance profiling of operation. '
|
||||||
|
'This key should be the value of the HMAC key '
|
||||||
|
'configured for the OSprofiler middleware in '
|
||||||
|
'nova; it is specified in the Nova '
|
||||||
|
'configuration file at "/etc/nova/nova.conf". '
|
||||||
|
'Without the key, profiling will not be '
|
||||||
|
'triggered even if OSprofiler is enabled on '
|
||||||
|
'the server side.')
|
||||||
|
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def get_subcommand_parser(self, version):
|
def get_subcommand_parser(self, version):
|
||||||
@ -619,6 +635,10 @@ class OpenStackMagnumShell(object):
|
|||||||
if args.os_interface.endswith('URL'):
|
if args.os_interface.endswith('URL'):
|
||||||
args.os_interface = args.os_interface[:-3]
|
args.os_interface = args.os_interface[:-3]
|
||||||
|
|
||||||
|
kwargs = {}
|
||||||
|
if profiler:
|
||||||
|
kwargs["profile"] = args.profile
|
||||||
|
|
||||||
self.cs = client.Client(
|
self.cs = client.Client(
|
||||||
cloud=args.os_cloud,
|
cloud=args.os_cloud,
|
||||||
user_id=args.os_user_id,
|
user_id=args.os_user_id,
|
||||||
@ -638,11 +658,17 @@ class OpenStackMagnumShell(object):
|
|||||||
interface=args.os_interface,
|
interface=args.os_interface,
|
||||||
insecure=args.insecure,
|
insecure=args.insecure,
|
||||||
api_version=args.magnum_api_version,
|
api_version=args.magnum_api_version,
|
||||||
|
**kwargs
|
||||||
)
|
)
|
||||||
|
|
||||||
self._check_deprecation(args.func, argv)
|
self._check_deprecation(args.func, argv)
|
||||||
args.func(self.cs, args)
|
args.func(self.cs, args)
|
||||||
|
|
||||||
|
if profiler and args.profile:
|
||||||
|
trace_id = profiler.get().get_base_id()
|
||||||
|
print("To display trace use the command:\n\n"
|
||||||
|
" osprofiler trace show --html %s " % trace_id)
|
||||||
|
|
||||||
def _check_deprecation(self, func, argv):
|
def _check_deprecation(self, func, argv):
|
||||||
if not hasattr(func, 'deprecated_groups'):
|
if not hasattr(func, 'deprecated_groups'):
|
||||||
return
|
return
|
||||||
|
@ -215,7 +215,7 @@ class ShellTest(utils.TestCase):
|
|||||||
def _expected_client_kwargs(self):
|
def _expected_client_kwargs(self):
|
||||||
return {
|
return {
|
||||||
'password': 'password', 'auth_token': None,
|
'password': 'password', 'auth_token': None,
|
||||||
'auth_url': self.AUTH_URL,
|
'auth_url': self.AUTH_URL, 'profile': None,
|
||||||
'cloud': None, 'interface': 'public',
|
'cloud': None, 'interface': 'public',
|
||||||
'insecure': False, 'magnum_url': None,
|
'insecure': False, 'magnum_url': None,
|
||||||
'project_id': None, 'project_name': 'project_name',
|
'project_id': None, 'project_name': 'project_name',
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
from keystoneauth1.exceptions import catalog
|
from keystoneauth1.exceptions import catalog
|
||||||
from keystoneauth1 import session as ksa_session
|
from keystoneauth1 import session as ksa_session
|
||||||
import os_client_config
|
import os_client_config
|
||||||
|
from oslo_utils import importutils
|
||||||
|
|
||||||
from magnumclient.common import httpclient
|
from magnumclient.common import httpclient
|
||||||
from magnumclient.v1 import baymodels
|
from magnumclient.v1 import baymodels
|
||||||
@ -25,6 +26,8 @@ from magnumclient.v1 import cluster_templates
|
|||||||
from magnumclient.v1 import clusters
|
from magnumclient.v1 import clusters
|
||||||
from magnumclient.v1 import mservices
|
from magnumclient.v1 import mservices
|
||||||
|
|
||||||
|
profiler = importutils.try_import("osprofiler.profiler")
|
||||||
|
|
||||||
|
|
||||||
DEFAULT_SERVICE_TYPE = 'container-infra'
|
DEFAULT_SERVICE_TYPE = 'container-infra'
|
||||||
LEGACY_DEFAULT_SERVICE_TYPE = 'container'
|
LEGACY_DEFAULT_SERVICE_TYPE = 'container'
|
||||||
@ -198,3 +201,13 @@ class Client(object):
|
|||||||
self.cluster_templates = \
|
self.cluster_templates = \
|
||||||
cluster_templates.ClusterTemplateManager(self.http_client)
|
cluster_templates.ClusterTemplateManager(self.http_client)
|
||||||
self.mservices = mservices.MServiceManager(self.http_client)
|
self.mservices = mservices.MServiceManager(self.http_client)
|
||||||
|
|
||||||
|
profile = kwargs.pop("profile", None)
|
||||||
|
if profiler and profile:
|
||||||
|
# Initialize the root of the future trace: the created trace ID
|
||||||
|
# will be used as the very first parent to which all related
|
||||||
|
# traces will be bound to. The given HMAC key must correspond to
|
||||||
|
# the one set in magnum-api magnum.conf, otherwise the latter
|
||||||
|
# will fail to check the request signature and will skip
|
||||||
|
# initialization of osprofiler on the server side.
|
||||||
|
profiler.init(profile)
|
||||||
|
@ -10,6 +10,7 @@ python-subunit>=0.0.18 # Apache-2.0/BSD
|
|||||||
sphinx!=1.3b1,<1.4,>=1.2.1 # BSD
|
sphinx!=1.3b1,<1.4,>=1.2.1 # BSD
|
||||||
oslosphinx>=4.7.0 # Apache-2.0
|
oslosphinx>=4.7.0 # Apache-2.0
|
||||||
oslotest>=1.10.0 # Apache-2.0
|
oslotest>=1.10.0 # Apache-2.0
|
||||||
|
osprofiler>=1.4.0 # Apache-2.0
|
||||||
testrepository>=0.0.18 # Apache-2.0/BSD
|
testrepository>=0.0.18 # Apache-2.0/BSD
|
||||||
testscenarios>=0.4 # Apache-2.0/BSD
|
testscenarios>=0.4 # Apache-2.0/BSD
|
||||||
testtools>=1.4.0 # MIT
|
testtools>=1.4.0 # MIT
|
||||||
|
Loading…
Reference in New Issue
Block a user