From a8ff5f0b85b7fc91e8b91ac1fb8d32605b86c7b9 Mon Sep 17 00:00:00 2001 From: "Jens W. Klein" Date: Mon, 10 May 2021 17:55:40 +0200 Subject: [PATCH] add a test and changelog --- news/129.feature | 1 + src/plone/recipe/zope2instance/recipe.py | 6 ++- src/plone/recipe/zope2instance/tests/wsgi.rst | 54 ++++++++++++++++++- 3 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 news/129.feature diff --git a/news/129.feature b/news/129.feature new file mode 100644 index 0000000..b9e13d6 --- /dev/null +++ b/news/129.feature @@ -0,0 +1 @@ +Add repoze.profile profiling middleware support [jensens] \ No newline at end of file diff --git a/src/plone/recipe/zope2instance/recipe.py b/src/plone/recipe/zope2instance/recipe.py index c4a257c..2c1e89b 100644 --- a/src/plone/recipe/zope2instance/recipe.py +++ b/src/plone/recipe/zope2instance/recipe.py @@ -798,9 +798,13 @@ def build_wsgi_ini(self): sentry_level = options.get('sentry_level', 'INFO') sentry_event_level = options.get('sentry_event_level', 'ERROR') sentry_ignore = options.get('sentry_ignore', '') + profile = options.get('profile', '').strip() == 'on' if profile: - pipeline.append('profile') + if "zope" in pipeline: + pipeline.insert(pipeline.index("zope"), 'profile') + else: + pipeline.append('profile') default_profile_log_filename = os.path.sep.join( [ var_dir, diff --git a/src/plone/recipe/zope2instance/tests/wsgi.rst b/src/plone/recipe/zope2instance/tests/wsgi.rst index 192e08b..63c39e2 100644 --- a/src/plone/recipe/zope2instance/tests/wsgi.rst +++ b/src/plone/recipe/zope2instance/tests/wsgi.rst @@ -469,7 +469,7 @@ The buildout has updated our INI file: level = INFO event_level = ERROR ignorelist = - + ... [pipeline:main] pipeline = translogger @@ -522,7 +522,7 @@ The buildout has updated our INI file: level = DEBUG event_level = WARNING ignorelist = waitress.queue foo - + ... [pipeline:main] pipeline = translogger @@ -576,4 +576,54 @@ The buildout has updated our INI file and we can see that we have a custom pipel ... +With repoze.profile middleware +============================== + +The recipe can configure custom pipelines in the ``wsgi.ini``:: + + >>> write('buildout.cfg', + ... ''' + ... [buildout] + ... parts = instance + ... find-links = %(sample_buildout)s/eggs + ... + ... [instance] + ... recipe = plone.recipe.zope2instance + ... eggs = + ... user = me:me + ... profile = on + ... ''' % options) + +Let's run it:: + + >>> print(system(join('bin', 'buildout'))), + Uninstalling instance. + Installing instance. + ... + +The buildout has updated our INI file and we can see that we have a custom pipeline:: + + >>> wsgi_ini = open(os.path.join(instance, 'etc', 'wsgi.ini')).read() + >>> print(wsgi_ini) + [server:main] + ... + [filter:profile] + use = egg:repoze.profile + ... + discard_first_request = true + path = /__profile__ + flush_at_shutdown = true + unwind = false + + [pipeline:main] + pipeline = + translogger + egg:Zope#httpexceptions + profile + zope + + [loggers] + ... + + # END OF TEST \ No newline at end of file