summaryrefslogtreecommitdiff
path: root/cinderclient
diff options
context:
space:
mode:
authorGorka Eguileor <geguileo@redhat.com>2022-02-08 17:51:17 +0100
committerGorka Eguileor <geguileo@redhat.com>2022-02-09 17:37:37 +0100
commitda5ecebb3353618542aa84c2078b03f1a9f6ad83 (patch)
tree285755e585115a9dfec44622a3a2d382559bba0a /cinderclient
parent6afd886cdd25d1c761d80f6c43303a09187349d5 (diff)
downloadpython-cinderclient-da5ecebb3353618542aa84c2078b03f1a9f6ad83.tar.gz
Add support for collect-timing option
When we run "cinder help" we can see that there is a --collect-timing option: --collect-timing Collect per-API call timing information. This is a keystone session option that we are not currently acting on from a user perspective. This patch adds support for this option, and we'll be able to see the timing in a similar way as we do with OSC: $ cinder --collect-timing api-version +------+---------+---------+-------------+ | ID | Status | Version | Min_version | +------+---------+---------+-------------+ | v3.0 | CURRENT | 3.66 | 3.0 | +------+---------+---------+-------------+ +--------+------------------------------------------------+----------+ | method | url | seconds | +--------+------------------------------------------------+----------+ | GET | http://192.168.121.243/identity | 0.003591 | | POST | http://192.168.121.243/identity/v3/auth/tokens | 0.016649 | | GET | http://192.168.121.243/volume/ | 0.004012 | | GET | http://192.168.121.243/volume/ | 0.004543 | +--------+------------------------------------------------+----------+ The patch formats the "elapsed" time attribute into seconds and renames the column to "seconds" to make it more user friendly similar to OSC. If we didn't it would look like 0:00:00.003744 Closes-Bug: #1960337 Change-Id: Ia6b31794bf60a351007cc4476a76b9bcb76bf378
Diffstat (limited to 'cinderclient')
-rw-r--r--cinderclient/shell.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/cinderclient/shell.py b/cinderclient/shell.py
index dc9190a..ad7876c 100644
--- a/cinderclient/shell.py
+++ b/cinderclient/shell.py
@@ -705,6 +705,12 @@ class OpenStackCinderShell(object):
if not auth_session:
auth_session = self._get_keystone_session()
+ # collect_timing is a keystone session option
+ if (not isinstance(auth_session, session.Session)
+ and getattr(args, 'collect_timing', False) is True):
+ raise exc.AuthorizationFailure("Provided auth plugin doesn't "
+ "support collect_timing option")
+
insecure = self.options.insecure
client_args = dict(
@@ -805,6 +811,17 @@ class OpenStackCinderShell(object):
print("To display trace use next command:\n"
"osprofiler trace show --html %s " % trace_id)
+ if getattr(args, 'collect_timing', False) is True:
+ self._print_timings(auth_session)
+
+ def _print_timings(self, session):
+ timings = session.get_timings()
+ utils.print_list(
+ timings,
+ fields=('method', 'url', 'seconds'),
+ sortby_index=None,
+ formatters={'seconds': lambda r: r.elapsed.total_seconds()})
+
def _discover_client(self,
current_client,
os_api_version,