From 56246dfac488946f84783a828508ae32b7ddea85 Mon Sep 17 00:00:00 2001 From: Emre Ates Date: Wed, 20 May 2020 19:58:52 -0600 Subject: [PATCH] Added tracing to nova types --- novaclient/shell.py | 20 ++++++++++++++++++++ novaclient/v2/usage.py | 7 +++++++ 2 files changed, 27 insertions(+) diff --git a/novaclient/shell.py b/novaclient/shell.py index a81db89a8..c8e09e118 100644 --- a/novaclient/shell.py +++ b/novaclient/shell.py @@ -20,6 +20,8 @@ import argparse import logging +import re +import socket import sys from keystoneauth1 import loading @@ -36,6 +38,8 @@ from novaclient import utils osprofiler_profiler = importutils.try_import("osprofiler.profiler") +import osprofiler.initializer +from oslo_config import cfg DEFAULT_MAJOR_OS_COMPUTE_API_VERSION = "2.0" # The default behaviour of nova client CLI is that CLI negotiates with server @@ -244,6 +248,7 @@ class OpenStackComputeShell(object): def __init__(self): self.client_logger = None + def _append_global_identity_args(self, parser, argv): # Register the CLI arguments that have moved to the session object. loading.register_session_argparse_arguments(parser) @@ -508,6 +513,21 @@ def main(self, argv): parser = self.get_base_parser(argv) (args, args_list) = parser.parse_known_args(argv) + with open('/etc/nova/nova.conf', 'r') as f: + regex = re.compile(r'^connection_string = ([a-zA-Z0-9:/\.]+)') + for line in f: + res = regex.match(line) + if res: + cfg.CONF.profiler.connection_string = res.group(1) + cfg.CONF.profiler.hmac_keys = 'Devstack1' + osprofiler.initializer.init_from_conf( + cfg.CONF, + {}, # supposed to be context + 'novaclient', + 'novaclient', + socket.gethostname() + ) + self.setup_debugging(args.debug) self.extensions = [] do_help = args.help or not args_list or args_list[0] == 'help' diff --git a/novaclient/v2/usage.py b/novaclient/v2/usage.py index 32fc55085..57b64ddcf 100644 --- a/novaclient/v2/usage.py +++ b/novaclient/v2/usage.py @@ -17,6 +17,8 @@ import oslo_utils +from osprofiler import profiler + from novaclient import api_versions from novaclient import base @@ -42,6 +44,7 @@ def get(self): self.append_request_ids(new.request_ids) +@profiler.trace_cls("nova_usage") class UsageManager(base.ManagerWithFind): """ Manage :class:`Usage` resources. @@ -70,6 +73,7 @@ def list(self, start, end, detailed=False): instance whose usage is part of the report :rtype: list of :class:`Usage`. """ + profiler.set_request_type("UsageList") query_string = self._usage_query(start, end, detailed=detailed) url = '/%s%s' % (self.usage_prefix, query_string) return self._list(url, 'tenant_usages') @@ -92,6 +96,7 @@ def list(self, start, end, detailed=False, marker=None, limit=None): is larger than default, the default limit will be used. :rtype: list of :class:`Usage`. """ + profiler.set_request_type("UsageList") query_string = self._usage_query(start, end, marker, limit, detailed) url = '/%s%s' % (self.usage_prefix, query_string) return self._list(url, 'tenant_usages') @@ -106,6 +111,7 @@ def get(self, tenant_id, start, end): :param end: :class:`datetime.datetime` End date in UTC :rtype: :class:`Usage` """ + profiler.set_request_type("UsageGet") query_string = self._usage_query(start, end) url = '/%s/%s%s' % (self.usage_prefix, tenant_id, query_string) return self._get(url, 'tenant_usage') @@ -127,6 +133,7 @@ def get(self, tenant_id, start, end, marker=None, limit=None): is larger than default, the default limit will be used. :rtype: :class:`Usage` """ + profiler.set_request_type("UsageGet") query_string = self._usage_query(start, end, marker, limit) url = '/%s/%s%s' % (self.usage_prefix, tenant_id, query_string) return self._get(url, 'tenant_usage')