Add osprofiler support

OpenStack profiling can be enabled by setting parameter --os-profile.
The feature requires osprofiler library. If library is not present
a warning message is shown.

Change-Id: I2c1b0cbd99450236b3720e19700f99cfdc14e378
Closes-Bug: 1666585
This commit is contained in:
Ilya Shakhat 2017-08-09 14:06:44 +02:00
parent 0609e02559
commit 6fc8d21b3b
8 changed files with 43 additions and 2 deletions

View File

@ -21,6 +21,7 @@ usage: shaker-all-in-one [-h] [--agent-join-timeout AGENT_JOIN_TIMEOUT]
[--nowatch-log-file] [--os-auth-url <auth-url>]
[--os-cacert <auth-cacert>] [--os-insecure]
[--os-password <auth-password>]
[--os-profile <hmac-key>]
[--os-project-name <auth-project-name>]
[--os-region-name <auth-region-name>]
[--os-tenant-name <auth-tenant-name>]
@ -148,6 +149,9 @@ optional arguments:
defaults to env[OS_INSECURE].
--os-password <auth-password>
Authentication password, defaults to env[OS_PASSWORD].
--os-profile <hmac-key>
HMAC key for encrypting profiling context data,
defaults to env[OS_PROFILE].
--os-project-name <auth-project-name>
Authentication project name. This option is mutually
exclusive with --os-tenant-name. Defaults to

View File

@ -10,6 +10,7 @@ usage: shaker-cleanup [-h] [--cleanup] [--cleanup-on-error] [--config-dir DIR]
[--nouse-syslog] [--nowatch-log-file]
[--os-auth-url <auth-url>] [--os-cacert <auth-cacert>]
[--os-insecure] [--os-password <auth-password>]
[--os-profile <hmac-key>]
[--os-project-name <auth-project-name>]
[--os-region-name <auth-region-name>]
[--os-tenant-name <auth-tenant-name>]
@ -86,6 +87,9 @@ optional arguments:
defaults to env[OS_INSECURE].
--os-password <auth-password>
Authentication password, defaults to env[OS_PASSWORD].
--os-profile <hmac-key>
HMAC key for encrypting profiling context data,
defaults to env[OS_PROFILE].
--os-project-name <auth-project-name>
Authentication project name. This option is mutually
exclusive with --os-tenant-name. Defaults to

View File

@ -19,6 +19,7 @@ usage: shaker-image-builder [-h] [--cleanup-on-error] [--config-dir DIR]
[--os-auth-url <auth-url>]
[--os-cacert <auth-cacert>] [--os-insecure]
[--os-password <auth-password>]
[--os-profile <hmac-key>]
[--os-project-name <auth-project-name>]
[--os-region-name <auth-region-name>]
[--os-tenant-name <auth-tenant-name>]
@ -116,6 +117,9 @@ optional arguments:
defaults to env[OS_INSECURE].
--os-password <auth-password>
Authentication password, defaults to env[OS_PASSWORD].
--os-profile <hmac-key>
HMAC key for encrypting profiling context data,
defaults to env[OS_PROFILE].
--os-project-name <auth-project-name>
Authentication project name. This option is mutually
exclusive with --os-tenant-name. Defaults to

View File

@ -11,7 +11,7 @@ usage: shaker [-h] [--agent-join-timeout AGENT_JOIN_TIMEOUT]
[--noos-insecure] [--nouse-journal] [--nouse-syslog]
[--nowatch-log-file] [--os-auth-url <auth-url>]
[--os-cacert <auth-cacert>] [--os-insecure]
[--os-password <auth-password>]
[--os-password <auth-password>] [--os-profile <hmac-key>]
[--os-project-name <auth-project-name>]
[--os-region-name <auth-region-name>]
[--os-tenant-name <auth-tenant-name>]
@ -112,6 +112,9 @@ optional arguments:
defaults to env[OS_INSECURE].
--os-password <auth-password>
Authentication password, defaults to env[OS_PASSWORD].
--os-profile <hmac-key>
HMAC key for encrypting profiling context data,
defaults to env[OS_PROFILE].
--os-project-name <auth-project-name>
Authentication project name. This option is mutually
exclusive with --os-tenant-name. Defaults to

View File

@ -147,6 +147,10 @@
# Authentication region name, defaults to env[OS_REGION_NAME]. (string value)
#os_region_name = RegionOne
# HMAC key for encrypting profiling context data, defaults to env[OS_PROFILE].
# (string value)
#os_profile =
# Name or ID of external network, defaults to env[SHAKER_EXTERNAL_NET]. If no
# value provided then Shaker picks any of available external networks. (string
# value)

View File

@ -115,6 +115,11 @@ OPENSTACK_OPTS = [
default=utils.env('OS_REGION_NAME') or 'RegionOne',
help='Authentication region name, defaults to '
'env[OS_REGION_NAME].'),
cfg.StrOpt('os-profile', metavar='<hmac-key>',
default=utils.env('OS_PROFILE'),
sample_default='',
help='HMAC key for encrypting profiling context data, '
'defaults to env[OS_PROFILE].'),
cfg.StrOpt('external-net',
default=utils.env('SHAKER_EXTERNAL_NET'),

View File

@ -275,6 +275,8 @@ def pack_openstack_params(conf):
params['auth']['tenant_name'] = conf.os_tenant_name
if conf.os_project_name:
params['auth']['project_name'] = conf.os_project_name
if conf.os_profile:
params['os_profile'] = conf.os_profile
return params

View File

@ -15,7 +15,7 @@
import os_client_config
from oslo_log import log as logging
from oslo_utils import importutils
LOG = logging.getLogger(__name__)
@ -24,10 +24,25 @@ class OpenStackClientException(Exception):
pass
def init_profiling(os_profile):
if os_profile:
osprofiler_profiler = importutils.try_import("osprofiler.profiler")
if osprofiler_profiler: # lib is present
osprofiler_profiler.init(os_profile)
trace_id = osprofiler_profiler.get().get_base_id()
LOG.info('Profiling is enabled, trace id: %s', trace_id)
else: # param is set, but lib is not present
LOG.warning('Profiling could not be enabled. To enable profiling '
'please install "osprofiler" library')
class OpenStackClient(object):
def __init__(self, openstack_params):
LOG.debug('Establishing connection to OpenStack')
init_profiling(openstack_params.get('os_profile'))
config = os_client_config.OpenStackConfig()
cloud_config = config.get_one_cloud(**openstack_params)
if openstack_params['os_insecure']: