-
Notifications
You must be signed in to change notification settings - Fork 0
feat: implement django silk for api performance monitoring and profiling #29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -36,6 +36,7 @@ | |||||||||||
|
|
||||||||||||
| DJANGO_SETTINGS_MODULE = "bootstrap_service.settings" | ||||||||||||
| ROOT_URLCONF = "bootstrap_service.urls" | ||||||||||||
| SILK_ENABLED = os.getenv("ENV", "dev").lower() == "dev" | ||||||||||||
|
|
||||||||||||
| DEBUG = True | ||||||||||||
| ALLOWED_HOSTS = ["*"] | ||||||||||||
|
|
@@ -113,6 +114,9 @@ | |||||||||||
| ACCOUNT_USERNAME_REQUIRED = False | ||||||||||||
| ACCOUNT_AUTHENTICATION_METHOD = "email" | ||||||||||||
|
|
||||||||||||
| if SILK_ENABLED: | ||||||||||||
| INSTALLED_APPS.append("silk") | ||||||||||||
|
|
||||||||||||
| # Middleware configuration (required for admin application) | ||||||||||||
| MIDDLEWARE = [ | ||||||||||||
| "django.middleware.security.SecurityMiddleware", | ||||||||||||
|
|
@@ -124,6 +128,23 @@ | |||||||||||
| "django.middleware.clickjacking.XFrameOptionsMiddleware", | ||||||||||||
| ] | ||||||||||||
|
|
||||||||||||
| if SILK_ENABLED: | ||||||||||||
| MIDDLEWARE.insert(2, "silk.middleware.SilkyMiddleware") | ||||||||||||
|
|
||||||||||||
| def silky_intercept_func(request): | ||||||||||||
| return request.path.startswith("/api/") | ||||||||||||
|
|
||||||||||||
| SILKY_INTERCEPT_FUNC = silky_intercept_func | ||||||||||||
| SILKY_AUTHENTICATION = False | ||||||||||||
| SILKY_AUTHORISATION = False | ||||||||||||
|
Comment on lines
+138
to
+139
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Security Risk: Unprotected Silk ConsoleSetting both Even in a development environment, if this service is deployed to a shared or public development/staging server, this exposes sensitive information including:
RecommendationEnable authentication and authorization by default, or make them configurable via environment variables so that only authenticated staff/superusers can access the profiling data.
Suggested change
|
||||||||||||
| SILKY_PYTHON_PROFILER = True | ||||||||||||
| SILKY_PYTHON_PROFILER_BINARY = False | ||||||||||||
| SILKY_MAX_REQUEST_BODY_SIZE = 1024 | ||||||||||||
| SILKY_MAX_RESPONSE_BODY_SIZE = 0 | ||||||||||||
| SILKY_META = True | ||||||||||||
| SILKY_INTERCEPT_PERCENT = 10 | ||||||||||||
| SILKY_MAX_RECORDED_REQUESTS_CHECK_PERCENT = 10 | ||||||||||||
|
Comment on lines
+144
to
+146
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Configuration Conflict & Usability Issue
RecommendationRemove
Suggested change
|
||||||||||||
|
|
||||||||||||
| # Internationalization | ||||||||||||
| # https://docs.djangoproject.com/en/3.2/topics/i18n/ | ||||||||||||
| LANGUAGE_CODE = "en-us" | ||||||||||||
|
|
||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Issue: Silk Enabled During Test Runs
If the test suite is executed (e.g., via
python manage.py test), the environment variableENVwill likely default to"dev", which enables Django Silk.Running Silk during tests has several negative impacts:
Recommendation
Disable Silk when running tests by checking
sys.argv.