summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStuart Grace <stuart.grace@bbc.co.uk>2018-06-27 12:26:55 +0100
committerStuart Grace <stuart.grace@bbc.co.uk>2018-06-27 12:26:55 +0100
commitdba75673afda7df630314dd151f84add9a471e8c (patch)
tree1bb17e3b3b17a61b807eb502d615704719fc796e
parent4bec736b1893e800ef27a0e457d2e227af3c56ae (diff)
downloadosprofiler-dba75673afda7df630314dd151f84add9a471e8c.tar.gz
Make profiler.clean() public method
Horizon dashboard has a profiler plugin which calls profiler.init method at openstack_dashboard/contrib/developer/profiler/middleware.py line 64. This creates a profiler and picks a new base_id. The only way to remove this profiler and stop using this base_id is to call profiler._clean() method. So this patch changes _clean() to clean() so it becomes a public method. Change-Id: Idec7ee240bc7f508aeebcba374a9673652b1cc72 Related-Bug: #1777486
-rw-r--r--osprofiler/profiler.py2
-rw-r--r--osprofiler/tests/unit/test_profiler.py6
-rw-r--r--osprofiler/tests/unit/test_web.py8
-rw-r--r--osprofiler/web.py2
4 files changed, 9 insertions, 9 deletions
diff --git a/osprofiler/profiler.py b/osprofiler/profiler.py
index fcbbc38..1290f51 100644
--- a/osprofiler/profiler.py
+++ b/osprofiler/profiler.py
@@ -31,7 +31,7 @@ from osprofiler import notifier
__local_ctx = threading.local()
-def _clean():
+def clean():
__local_ctx.profiler = None
diff --git a/osprofiler/tests/unit/test_profiler.py b/osprofiler/tests/unit/test_profiler.py
index 96f0654..1bd4b3f 100644
--- a/osprofiler/tests/unit/test_profiler.py
+++ b/osprofiler/tests/unit/test_profiler.py
@@ -28,7 +28,7 @@ from osprofiler.tests import test
class ProfilerGlobMethodsTestCase(test.TestCase):
def test_get_profiler_not_inited(self):
- profiler._clean()
+ profiler.clean()
self.assertIsNone(profiler.get())
def test_get_profiler_and_init(self):
@@ -40,7 +40,7 @@ class ProfilerGlobMethodsTestCase(test.TestCase):
self.assertEqual(p.get_id(), "2")
def test_start_not_inited(self):
- profiler._clean()
+ profiler.clean()
profiler.start("name")
def test_start(self):
@@ -50,7 +50,7 @@ class ProfilerGlobMethodsTestCase(test.TestCase):
p.start.assert_called_once_with("name", info="info")
def test_stop_not_inited(self):
- profiler._clean()
+ profiler.clean()
profiler.stop()
def test_stop(self):
diff --git a/osprofiler/tests/unit/test_web.py b/osprofiler/tests/unit/test_web.py
index 24b3906..61015cb 100644
--- a/osprofiler/tests/unit/test_web.py
+++ b/osprofiler/tests/unit/test_web.py
@@ -31,8 +31,8 @@ class WebTestCase(test.TestCase):
def setUp(self):
super(WebTestCase, self).setUp()
- profiler._clean()
- self.addCleanup(profiler._clean)
+ profiler.clean()
+ self.addCleanup(profiler.clean)
def test_get_trace_id_headers_no_hmac(self):
profiler.init(None, base_id="y", parent_id="z")
@@ -61,10 +61,10 @@ class WebTestCase(test.TestCase):
class WebMiddlewareTestCase(test.TestCase):
def setUp(self):
super(WebMiddlewareTestCase, self).setUp()
- profiler._clean()
+ profiler.clean()
# it's default state of _ENABLED param, so let's set it here
web._ENABLED = None
- self.addCleanup(profiler._clean)
+ self.addCleanup(profiler.clean)
def tearDown(self):
web.enable()
diff --git a/osprofiler/web.py b/osprofiler/web.py
index 2c9fc53..8443ca5 100644
--- a/osprofiler/web.py
+++ b/osprofiler/web.py
@@ -131,4 +131,4 @@ class WsgiMiddleware(object):
with profiler.Trace(self.name, info=info):
return request.get_response(self.application)
finally:
- profiler._clean()
+ profiler.clean()