Skip to content

Commit

Permalink
Added tracing to nova types
Browse files Browse the repository at this point in the history
  • Loading branch information
EmreAtes committed May 21, 2020
1 parent 52e2858 commit 56246df
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
20 changes: 20 additions & 0 deletions novaclient/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import argparse
import logging
import re
import socket
import sys

from keystoneauth1 import loading
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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'
Expand Down
7 changes: 7 additions & 0 deletions novaclient/v2/usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import oslo_utils

from osprofiler import profiler

from novaclient import api_versions
from novaclient import base

Expand All @@ -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.
Expand Down Expand Up @@ -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')
Expand All @@ -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')
Expand All @@ -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')
Expand All @@ -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')

0 comments on commit 56246df

Please sign in to comment.