diff options
author | Angus Salkeld <asalkeld@mirantis.com> | 2014-09-16 12:17:53 +1000 |
---|---|---|
committer | Angus Salkeld <asalkeld@mirantis.com> | 2014-09-16 12:17:53 +1000 |
commit | c0585eba4c5f7531fbbfc570adf0adbe5812bc47 (patch) | |
tree | 03a98bd9dc3b2553e1f8c0f8615b15f5e50464a7 /heatclient/shell.py | |
parent | f27a3571b7475620133cb0b314f4fb0d054f01f0 (diff) | |
download | python-heatclient-c0585eba4c5f7531fbbfc570adf0adbe5812bc47.tar.gz |
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
Diffstat (limited to 'heatclient/shell.py')
-rw-r--r-- | heatclient/shell.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/heatclient/shell.py b/heatclient/shell.py index 264a824..f26863c 100644 --- a/heatclient/shell.py +++ b/heatclient/shell.py @@ -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. |