From e531b7babea5738b375d0dc59ef6f61a46fe543d Mon Sep 17 00:00:00 2001 From: Michal Arbet Date: Fri, 11 Jan 2019 17:55:40 +0100 Subject: [PATCH] Fix osprofiler support in horizon This patch is fixing usage of osprofiler in horizon. It has been merged once, but after merge to master, manage.py compress starts to fail with python2.7. This fail was caused by "TypeError: 'encoding' is an invalid keyword argument for this function" which is now fixed by using six library. Change-Id: I21aa8d49833bef9e7673958d15674faec82a0925 Closes-Bug: #1814028 Related-Bug: #1811261 --- horizon/templatetags/angular.py | 11 +++++++++-- openstack_dashboard/contrib/developer/profiler/api.py | 9 ++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/horizon/templatetags/angular.py b/horizon/templatetags/angular.py index 34bb435960..946173d24e 100644 --- a/horizon/templatetags/angular.py +++ b/horizon/templatetags/angular.py @@ -19,6 +19,7 @@ from django.core.cache import caches from django.core.cache.utils import make_template_fragment_key from django.dispatch import receiver from django import template +import six register = template.Library() @@ -112,8 +113,14 @@ def angular_templates(context): result.extend(finder.find(relative_path, True)) path = result[-1] try: - with open(path) as template_file: - angular_templates[template_static_path] = template_file.read() + if six.PY3: + with open(path, encoding='utf-8') as template_file: + angular_templates[template_static_path] = template_file.\ + read() + else: + with open(path) as template_file: + angular_templates[template_static_path] = template_file.\ + read() except (OSError, IOError): # Failed to read template, leave the template dictionary blank # If the caller is using this dictionary to pre-populate a cache diff --git a/openstack_dashboard/contrib/developer/profiler/api.py b/openstack_dashboard/contrib/developer/profiler/api.py index 3d1bcdb9e0..44c22d8f3b 100644 --- a/openstack_dashboard/contrib/developer/profiler/api.py +++ b/openstack_dashboard/contrib/developer/profiler/api.py @@ -22,6 +22,7 @@ from osprofiler.drivers.base import get_driver as profiler_get_driver from osprofiler import notifier from osprofiler import profiler from osprofiler import web +import six from six.moves.urllib.parse import urlparse @@ -78,9 +79,8 @@ def _get_engine(request): def list_traces(request): engine = _get_engine(request) - query = {"info.user_id": request.user.id} - fields = ['base_id', 'timestamp', 'info.request.path'] - traces = engine.list_traces(query, fields) + fields = ['base_id', 'timestamp', 'info.request.path', 'info'] + traces = engine.list_traces(fields) return [{'id': trace['base_id'], 'timestamp': trace['timestamp'], 'origin': trace['info']['request']['path']} for trace in traces] @@ -118,6 +118,9 @@ def update_trace_headers(keys, **kwargs): trace_info.update(kwargs) p = profiler.get() trace_data = utils.signed_pack(trace_info, p.hmac_key) + if six.PY3: + trace_data = [key.decode() if isinstance(key, six.binary_type) + else key for key in trace_data] return json.dumps({web.X_TRACE_INFO: trace_data[0], web.X_TRACE_HMAC: trace_data[1]})