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
This commit is contained in:
Stuart Grace 2018-06-27 12:26:55 +01:00
parent 4bec736b18
commit dba75673af
4 changed files with 9 additions and 9 deletions

View File

@ -31,7 +31,7 @@ from osprofiler import notifier
__local_ctx = threading.local()
def _clean():
def clean():
__local_ctx.profiler = None

View File

@ -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):

View File

@ -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()

View File

@ -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()