From da5ecebb3353618542aa84c2078b03f1a9f6ad83 Mon Sep 17 00:00:00 2001 From: Gorka Eguileor Date: Tue, 8 Feb 2022 17:51:17 +0100 Subject: 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 --- cinderclient/shell.py | 17 +++++++++++++++++ releasenotes/notes/collect-timing-ce6d521d40d422fb.yaml | 6 ++++++ 2 files changed, 23 insertions(+) create mode 100644 releasenotes/notes/collect-timing-ce6d521d40d422fb.yaml 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, diff --git a/releasenotes/notes/collect-timing-ce6d521d40d422fb.yaml b/releasenotes/notes/collect-timing-ce6d521d40d422fb.yaml new file mode 100644 index 0000000..aa22517 --- /dev/null +++ b/releasenotes/notes/collect-timing-ce6d521d40d422fb.yaml @@ -0,0 +1,6 @@ +--- +features: + - | + `Bug #1960337 `_: Added + support for ``collect-timing`` parameter to see the timings of REST API + requests from the client when using Keystone authentication. -- cgit v1.2.1