From dba75673afda7df630314dd151f84add9a471e8c Mon Sep 17 00:00:00 2001 From: Stuart Grace Date: Wed, 27 Jun 2018 12:26:55 +0100 Subject: [PATCH] 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 --- osprofiler/profiler.py | 2 +- osprofiler/tests/unit/test_profiler.py | 6 +++--- osprofiler/tests/unit/test_web.py | 8 ++++---- osprofiler/web.py | 2 +- 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()