Skip to content

Commit

Permalink
add a test and changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
jensens committed May 10, 2021
1 parent 6743490 commit a8ff5f0
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
1 change: 1 addition & 0 deletions news/129.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add repoze.profile profiling middleware support [jensens]
6 changes: 5 additions & 1 deletion src/plone/recipe/zope2instance/recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
54 changes: 52 additions & 2 deletions src/plone/recipe/zope2instance/tests/wsgi.rst
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ The buildout has updated our INI file:
level = INFO
event_level = ERROR
ignorelist =
<BLANKLINE>
...
[pipeline:main]
pipeline =
translogger
Expand Down Expand Up @@ -522,7 +522,7 @@ The buildout has updated our INI file:
level = DEBUG
event_level = WARNING
ignorelist = waitress.queue foo
<BLANKLINE>
...
[pipeline:main]
pipeline =
translogger
Expand Down Expand Up @@ -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
<BLANKLINE>
[pipeline:main]
pipeline =
translogger
egg:Zope#httpexceptions
profile
zope
<BLANKLINE>
[loggers]
...


# END OF TEST

0 comments on commit a8ff5f0

Please sign in to comment.