diff --git a/docs/manual_testing/general_notes/index.rst b/docs/manual_testing/general_notes/index.rst index 7040bfe88db..4ce6b23b67c 100644 --- a/docs/manual_testing/general_notes/index.rst +++ b/docs/manual_testing/general_notes/index.rst @@ -76,16 +76,16 @@ Within the Chrome Dev Tools, navigate to the Network panel. Select a connection For Kolibri, our target audience's network condition can be mimicked by setting connectivity to Regular 3G (100ms, 750kb/s, 250 kb/s). -Performance testing with Django Debug Panel -------------------------------------------- +Performance testing with Django Debug Toolbar +--------------------------------------------- -We have built in support for Django Debug Panel (a Chrome extension that allows tracking of AJAX requests to Django). +We have built in support for Django Debug Toolbar, a Django application that provides a set of panels to display various debug information about the current request/response. It is particularly useful for performance testing. -To use this, ensure that you have development dependencies installed, and install the `Django Debug Panel Chrome Extension `__. You can then run the development or production servers with the following environment variable set:: +To use this, ensure that you have development dependencies installed. You can then run the development or production servers with the following environment variable set:: - DJANGO_SETTINGS_MODULE=kolibri.deployment.default.settings.debug_panel + DJANGO_SETTINGS_MODULE=kolibri.deployment.default.settings.debug_toolbar -This will activate the debug panel, and will display in the Dev tools panel of Chrome. This panel will track all page loads and API requests. However, all data bootstrapping into the template will be disabled, as our data bootstrapping prevents the page load request from being profiled, and also does not profile the bootstrapped API requests. +This will activate the debug toolbar, and will display in the HTML page of the site as an overlay. It is most useful when looking at individual API requests using the browsable API. The simplest way to see it for an API request is to go to that API request in the Network tab in the browser developer tools and open the URL in a new tab. Generating user data diff --git a/kolibri/deployment/default/dev_urls.py b/kolibri/deployment/default/dev_urls.py index 3504eda9b5b..bf53649eed0 100644 --- a/kolibri/deployment/default/dev_urls.py +++ b/kolibri/deployment/default/dev_urls.py @@ -1,6 +1,6 @@ -from django.conf import settings from django.http.response import HttpResponseRedirect from django.urls import include +from django.urls import path from django.urls import re_path from drf_yasg import openapi from drf_yasg.views import get_schema_view @@ -48,10 +48,5 @@ def webpack_redirect_view(request): name="schema-redoc", ), re_path(r"^api-auth/", include("rest_framework.urls", namespace="rest_framework")), + path("__debug__/", include("debug_toolbar.urls")), ] - -if getattr(settings, "DEBUG_PANEL_ACTIVE", False): - - import debug_toolbar - - urlpatterns = [re_path(r"^__debug__/", include(debug_toolbar.urls))] + urlpatterns diff --git a/kolibri/deployment/default/renderers.py b/kolibri/deployment/default/renderers.py new file mode 100644 index 00000000000..7bc4eccc0a6 --- /dev/null +++ b/kolibri/deployment/default/renderers.py @@ -0,0 +1,35 @@ +from rest_framework.renderers import BrowsableAPIRenderer + + +class LightBrowsableAPIRenderer(BrowsableAPIRenderer): + """ + Custom browsable API renderer that removes filtering and POST forms + for better performance with Django Debug Toolbar. + """ + + def get_filter_form(self, data, view, request): + """ + Don't render the filter form. + """ + return None + + def get_rendered_html_form(self, data, view, method, request): + """ + Don't render the HTML form. + """ + return None + + def get_context(self, data, accepted_media_type, renderer_context): + """ + Modify context to remove unnecessary components. + """ + context = super().get_context(data, accepted_media_type, renderer_context) + + # Remove form-related context + context["display_edit_forms"] = False + context["raw_data_post_form"] = None + context["raw_data_put_form"] = None + context["raw_data_patch_form"] = None + context["raw_data_put_or_patch_form"] = None + + return context diff --git a/kolibri/deployment/default/settings/debug_panel.py b/kolibri/deployment/default/settings/debug_panel.py deleted file mode 100644 index 1287d059999..00000000000 --- a/kolibri/deployment/default/settings/debug_panel.py +++ /dev/null @@ -1,18 +0,0 @@ -from .dev import * # noqa - -INTERNAL_IPS = ["127.0.0.1"] - -DEBUG_TOOLBAR_CONFIG = {"SHOW_TOOLBAR_CALLBACK": lambda x: True} - -MIDDLEWARE.append("debug_panel.middleware.DebugPanelMiddleware") # noqa - -INSTALLED_APPS += ["debug_toolbar", "debug_panel"] # noqa - -DEBUG_PANEL_ACTIVE = True - -CACHES["debug-panel"] = { # noqa - "BACKEND": "django.core.cache.backends.filebased.FileBasedCache", - "LOCATION": "/var/tmp/debug-panel-cache", - "TIMEOUT": 300, - "OPTIONS": {"MAX_ENTRIES": 200}, -} diff --git a/kolibri/deployment/default/settings/debug_toolbar.py b/kolibri/deployment/default/settings/debug_toolbar.py new file mode 100644 index 00000000000..c03ff09439c --- /dev/null +++ b/kolibri/deployment/default/settings/debug_toolbar.py @@ -0,0 +1,12 @@ +from .dev import * # noqa + +INTERNAL_IPS = ["127.0.0.1"] + +INSTALLED_APPS += ["debug_toolbar"] # noqa + +MIDDLEWARE += ["debug_toolbar.middleware.DebugToolbarMiddleware"] # noqa + +CACHES["default"]["TIMEOUT"] = 0 # noqa + +if "process_cache" in CACHES: # noqa + CACHES["process_cache"]["TIMEOUT"] = 0 # noqa diff --git a/kolibri/deployment/default/settings/dev.py b/kolibri/deployment/default/settings/dev.py index 5be1fa72634..ed27042bb35 100644 --- a/kolibri/deployment/default/settings/dev.py +++ b/kolibri/deployment/default/settings/dev.py @@ -34,7 +34,7 @@ ], "DEFAULT_RENDERER_CLASSES": ( "rest_framework.renderers.JSONRenderer", - "rest_framework.renderers.BrowsableAPIRenderer", + "kolibri.deployment.default.renderers.LightBrowsableAPIRenderer", ), "EXCEPTION_HANDLER": "kolibri.core.utils.exception_handler.custom_exception_handler", } diff --git a/requirements/dev.txt b/requirements/dev.txt index 78211f3d22f..22a2c4da9a9 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -5,9 +5,7 @@ flake8==3.8.3 flake8-print==5.0.0 pre-commit==3.8.0 tox==3.1.3 -django-debug-panel==0.8.3 -django-debug-toolbar==1.9.1 -ruamel.yaml.clib==0.2.2; python_version < "3" +django-debug-toolbar==4.3.0 drf-yasg==1.21.7 coreapi==2.3.3 nodeenv==1.3.3