summaryrefslogtreecommitdiff
path: root/trove/common/profile.py
diff options
context:
space:
mode:
authorZhi Yan Liu <zhiyanl@cn.ibm.com>2014-08-25 23:13:21 +0800
committerPeter Stachowski <peter@tesora.com>2015-02-14 13:08:43 -0500
commitfe2542262802508d45f3babf8282f74992b1acb8 (patch)
tree56519c97f144fc0c7e052f40ef38679b2e8bec2b /trove/common/profile.py
parent2ed02b5331eec97bd0cc460fedc6df233eb9e6ef (diff)
downloadtrove-fe2542262802508d45f3babf8282f74992b1acb8.tar.gz
Integrate OSprofiler and Trove
*) Add osprofiler wsgi middleware This middleware is used for 2 things: 1) It checks that the person who wants to trace is trusted and knows the secret HMAC key. 2) It start tracing in case of proper trace headers and adds the first wsgi trace point, with info about the HTTP request. *) Add initialization of osprofiler at start of service Initialize osprofiler with oslo.messaging notifier which is used to send notifications to Ceilometer. *) Use profile enabled context in services rpc interaction Change context serializer to pass profile context to service; rpc server will use trace info to initialize their profile context to continue the profiling for the request as a transaction. *) Add tracing on service manager and sqlalchemy db engine object NOTE to test this: You should put to localrc: CEILOMETER_NOTIFICATION_TOPICS=notifications,profiler ENABLED_SERVICES+=,ceilometer-acompute,ceilometer-acentral ENABLED_SERVICES+=,ceilometer-anotification,ceilometer-collector ENABLED_SERVICES+=,ceilometer-alarm-evaluator,ceilometer-alarm-notifier ENABLED_SERVICES+=,ceilometer-api Run any command with --profile <SECRET_KEY> $ trove --profile <SECRET_KEY> list # it will print <Trace ID> Get pretty HTML with traces: $ osprofiler trace show --html <Trace ID> Note: Trace showing can be executed with the admin account only. The change to enable Trove exchange in ceilometer has been merged: Idce1c327c6d21a767c612c13c1ad52a794017d71 . The change to enable profile in python-troveclient has been merged: I5a76e11d428c63d33f6d2c2021426090ebf8340c We prepared a common BP in oslo-spec as the integration change is similar in all projects: I95dccdc9f274661767d2659c18b96da169891f30 Currently there are 2 other projects are using osprofiler: Glance & Cinder, and some others are a work in progress. Change-Id: I580cce8d2b3c4ec9ce625ac09de6f14e1249f6f5 Signed-off-by: Zhi Yan Liu <zhiyanl@cn.ibm.com>
Diffstat (limited to 'trove/common/profile.py')
-rw-r--r--trove/common/profile.py48
1 files changed, 48 insertions, 0 deletions
diff --git a/trove/common/profile.py b/trove/common/profile.py
new file mode 100644
index 00000000..8f6c1c5d
--- /dev/null
+++ b/trove/common/profile.py
@@ -0,0 +1,48 @@
+# Copyright 2015 IBM Corp.
+# All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+from oslo import messaging
+from osprofiler import notifier
+from osprofiler import web
+
+from trove.common import cfg
+from trove.common import i18n
+from trove.openstack.common import context
+from trove.openstack.common import log as logging
+from trove import rpc
+
+
+_LW = i18n._LW
+LOG = logging.getLogger(__name__)
+CONF = cfg.CONF
+
+
+def setup_profiler(binary, host):
+ if CONF.profiler.enabled:
+ _notifier = notifier.create(
+ "Messaging", messaging, context.get_admin_context().to_dict(),
+ rpc.TRANSPORT, "trove", binary, host)
+ notifier.set(_notifier)
+ LOG.warn(_LW("The OpenStack Profiler is enabled. Using one of the "
+ "hmac_keys specified in the api-paste.ini file "
+ "(typically in /etc/trove), a trace can be made of all "
+ "requests. Only an admin user can retrieve the trace "
+ "information, however.\n"
+ "To disable the profiler, add the following to the "
+ "configuration file:\n"
+ "[profiler]\n"
+ "enabled=false"))
+ else:
+ web.disable()