Add support for OSprofiler

To be able to create profiling traces for Heat, the client should be
able to send special HTTP header that contains trace info.

Change-Id: I2ff833fac2dfe3bb0fcbd6a31c210db2935b72f1
Closes-bug: #1363782
This commit is contained in:
Angus Salkeld 2014-09-16 12:17:53 +10:00
parent f27a3571b7
commit c0585eba4c
2 changed files with 28 additions and 0 deletions

View File

@ -24,6 +24,7 @@ import six
from six.moves.urllib import parse
from heatclient import exc
from heatclient.openstack.common import importutils
from heatclient.openstack.common import jsonutils
from heatclient.openstack.common import strutils
@ -31,6 +32,7 @@ LOG = logging.getLogger(__name__)
USER_AGENT = 'python-heatclient'
CHUNKSIZE = 1024 * 64 # 64kB
SENSITIVE_HEADERS = ('X-Auth-Token',)
osprofiler_web = importutils.try_import("osprofiler.web")
def get_system_ca_file():
@ -149,6 +151,8 @@ class HTTPClient(object):
kwargs['headers'].setdefault('X-Region-Name', self.region_name)
if self.include_pass and not 'X-Auth-Key' in kwargs['headers']:
kwargs['headers'].update(self.credentials_headers())
if osprofiler_web:
kwargs['headers'].update(osprofiler_web.get_trace_id_headers())
self.log_curl_request(method, url, kwargs)

View File

@ -34,9 +34,11 @@ from heatclient import client as heat_client
from heatclient.common import utils
from heatclient import exc
from heatclient.openstack.common.gettextutils import _
from heatclient.openstack.common import importutils
from heatclient.openstack.common import strutils
logger = logging.getLogger(__name__)
osprofiler_profiler = importutils.try_import("osprofiler.profiler")
class HeatShell(object):
@ -283,6 +285,18 @@ class HeatShell(object):
self._append_global_identity_args(parser)
if osprofiler_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 HMAC key '
'configured in osprofiler middleware in heat, '
'it is specified in the paste configuration '
'(/etc/heat/api-paste.ini). '
'Without the key, profiling will not be '
'triggered even if osprofiler is enabled '
'on server side.')
return parser
def get_subcommand_parser(self, version):
@ -585,8 +599,18 @@ class HeatShell(object):
client = heat_client.Client(api_version, endpoint, **kwargs)
profile = osprofiler_profiler and options.profile
if profile:
osprofiler_profiler.init(options.profile)
args.func(client, args)
if profile:
trace_id = osprofiler_profiler.get().get_base_id()
print("Trace ID: %s" % trace_id)
print("To display trace use next command:\n"
"osprofiler trace show --html %s " % trace_id)
def do_bash_completion(self, args):
"""Prints all of the commands and options to stdout.