summaryrefslogtreecommitdiff
path: root/cinderclient/shell.py
diff options
context:
space:
mode:
authorBoris Pavlovic <boris@pavlovic.me>2014-06-24 23:05:53 +0400
committerBoris Pavlovic <boris@pavlovic.me>2014-10-08 19:30:10 +0400
commit6f5fd37ee95cb2b5ecca1fdb90dbad85e0f76655 (patch)
tree0ffb8f58c3ce860050bc2313ff0d248fa134cbb5 /cinderclient/shell.py
parent892b739f4a50f34bc669b1be30503e823310f7f1 (diff)
downloadpython-cinderclient-6f5fd37ee95cb2b5ecca1fdb90dbad85e0f76655.tar.gz
Add profiling support to cinderclient
To be able to create profiling traces for Cinder, client should be able to send special HTTP header that contains trace info. This patch is as well important to be able to make cross project traces. (Typical case nova calls cinder via python client, if profiler is initialized in nova, cinder client will add extra header, that will be parsed by special osprofiler middleware in cinder api) Don't worry no security issue here, trace information is signed by HMAC key that is setted in api-paste.ini. So only person that knows HMAC key is able to send proper header. Main patch (in Cinder) is: https://review.openstack.org/#/c/103415/ Change-Id: I53bb1b92e62841a02f941bdafaed7f8ed5db7ce1
Diffstat (limited to 'cinderclient/shell.py')
-rw-r--r--cinderclient/shell.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/cinderclient/shell.py b/cinderclient/shell.py
index 04dfe71..df5f62c 100644
--- a/cinderclient/shell.py
+++ b/cinderclient/shell.py
@@ -36,6 +36,7 @@ from cinderclient import exceptions as exc
from cinderclient import utils
import cinderclient.auth_plugin
import cinderclient.extension
+from cinderclient.openstack.common import importutils
from cinderclient.openstack.common import strutils
from cinderclient.openstack.common.gettextutils import _
from cinderclient.v1 import shell as shell_v1
@@ -48,6 +49,7 @@ from keystoneclient.auth.identity import v3 as v3_auth
from keystoneclient.exceptions import DiscoveryFailure
import six.moves.urllib.parse as urlparse
+osprofiler_profiler = importutils.try_import("osprofiler.profiler")
DEFAULT_OS_VOLUME_API_VERSION = "1"
DEFAULT_CINDER_ENDPOINT_TYPE = 'publicURL'
@@ -186,6 +188,17 @@ class OpenStackCinderShell(object):
default=0,
help='Number of retries.')
+ 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 needs to match the one configured '
+ 'on the cinder api server. '
+ 'Without key the profiling will not be '
+ 'triggered even if osprofiler is enabled '
+ 'on server side.')
+
self._append_global_identity_args(parser)
# The auth-system-plugins might require some extra options
@@ -671,8 +684,18 @@ class OpenStackCinderShell(object):
"to the default API version: %s" %
endpoint_api_version)
+ profile = osprofiler_profiler and options.profile
+ if profile:
+ osprofiler_profiler.init(options.profile)
+
args.func(self.cs, 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 _run_extension_hooks(self, hook_type, *args, **kwargs):
"""Runs hooks for all registered extensions."""
for extension in self.extensions: