Skip to content

Commit 78963ec

Browse files
committed
Added request profiler and a management command to purge profiler records.
- Legacy-Id: 17648
1 parent 1b94e10 commit 78963ec

6 files changed

Lines changed: 44 additions & 1 deletion

File tree

bin/daily

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,5 @@ $DTDIR/ietf/manage.py fetch_meeting_attendance --latest 2
6060
# Send reminders originating from the review app
6161
$DTDIR/ietf/bin/send-review-reminders
6262

63+
# Purge old request_profiler records
64+
$DTDIR/ietf/manage.py purge_request_profiler_records

ietf/settings.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,9 @@ def skip_unreadable_post(record):
357357

358358

359359
MIDDLEWARE = [
360+
# Must be first to measure correct request timing
361+
'request_profiler.middleware.ProfilingMiddleware',
362+
#
360363
'django.middleware.csrf.CsrfViewMiddleware',
361364
'corsheaders.middleware.CorsMiddleware', # see docs on CORS_REPLACE_HTTPS_REFERER before using it
362365
'django.middleware.common.CommonMiddleware',
@@ -405,6 +408,7 @@ def skip_unreadable_post(record):
405408
'django_password_strength',
406409
'djangobwr',
407410
'form_utils',
411+
'request_profiler',
408412
'simple_history',
409413
'tastypie',
410414
'widget_tweaks',
@@ -1118,9 +1122,10 @@ def skip_unreadable_post(record):
11181122

11191123
CACHES = {
11201124
'default': {
1125+
'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
11211126
#'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
11221127
#'LOCATION': '127.0.0.1:11211',
1123-
'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
1128+
#'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
11241129
'VERSION': __version__,
11251130
'KEY_PREFIX': 'ietf:dt',
11261131
},

ietf/settings_releasetest.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,6 @@ def __getitem__(self, item):
3434

3535
if TEST_CODE_COVERAGE_CHECKER and not TEST_CODE_COVERAGE_CHECKER._started: # pyflakes:ignore
3636
TEST_CODE_COVERAGE_CHECKER.start() # pyflakes:ignore
37+
38+
REQUEST_PROFILE_STORE_ANONYMOUS_SESSIONS = False
39+

ietf/settings_sqlitetest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,5 @@ def __getitem__(self, item):
5151
MIDDLEWARE = [ c for c in MIDDLEWARE if not c in DEV_MIDDLEWARE ] # pyflakes:ignore
5252

5353
TEMPLATES[0]['OPTIONS']['context_processors'] = [ p for p in TEMPLATES[0]['OPTIONS']['context_processors'] if not p in DEV_TEMPLATE_CONTEXT_PROCESSORS ] # pyflakes:ignore
54+
55+
REQUEST_PROFILE_STORE_ANONYMOUS_SESSIONS = False
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Copyright The IETF Trust 2020, All Rights Reserved
2+
# -*- coding: utf-8 -*-
3+
4+
import datetime
5+
6+
from textwrap import dedent
7+
8+
from django.core.management.base import BaseCommand
9+
10+
import debug # pyflakes:ignore
11+
12+
from request_profiler.models import ProfilingRecord
13+
14+
class Command(BaseCommand):
15+
"""
16+
Purge information older than a given number of days (default 30) from the
17+
profiling records table
18+
"""
19+
20+
help = dedent(__doc__).strip()
21+
22+
23+
def add_arguments(self, parser):
24+
parser.add_argument('-d', '--days', dest='days', type=int, default=30,
25+
help='Purge records older than this (default %(default)s days).')
26+
27+
def handle(self, *filenames, **options):
28+
start = datetime.datetime.now() - datetime.timedelta(days=int(options['days']))
29+
deleted = ProfilingRecord.objects.filter(start_ts__lt=start).delete()
30+
self.stdout.write('deleted: %s' % str(deleted))

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ django-formtools>=1.0 # instead of django.contrib.formtools in 1.8
1919
django-markup>=1.1
2020
django-password-strength>=1.2.1
2121
django-referrer-policy>=1.0
22+
django-request-profiler==0.14 # 0.15 and above requires Django 2.x
2223
django-simple-history>=2.3.0
2324
django-stubs==1.3.0
2425
django-tastypie>=0.13.2

0 commit comments

Comments
 (0)