Skip to content

Commit

Permalink
Make profiler.clean() public method
Browse files Browse the repository at this point in the history
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
  • Loading branch information
stuartgrace-bbc committed Jun 27, 2018
1 parent 4bec736 commit dba7567
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion osprofiler/profiler.py
Expand Up @@ -31,7 +31,7 @@
__local_ctx = threading.local()


def _clean():
def clean():
__local_ctx.profiler = None


Expand Down
6 changes: 3 additions & 3 deletions osprofiler/tests/unit/test_profiler.py
Expand Up @@ -28,7 +28,7 @@
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):
Expand All @@ -40,7 +40,7 @@ def test_get_profiler_and_init(self):
self.assertEqual(p.get_id(), "2")

def test_start_not_inited(self):
profiler._clean()
profiler.clean()
profiler.start("name")

def test_start(self):
Expand All @@ -50,7 +50,7 @@ def test_start(self):
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):
Expand Down
8 changes: 4 additions & 4 deletions osprofiler/tests/unit/test_web.py
Expand Up @@ -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")
Expand Down Expand Up @@ -61,10 +61,10 @@ def test_get_trace_id_headers_no_profiler(self, mock_get_profiler):
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()
Expand Down
2 changes: 1 addition & 1 deletion osprofiler/web.py
Expand Up @@ -131,4 +131,4 @@ def __call__(self, request):
with profiler.Trace(self.name, info=info):
return request.get_response(self.application)
finally:
profiler._clean()
profiler.clean()

0 comments on commit dba7567

Please sign in to comment.