Skip to content

Configure Gunicorn #18

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

Merged
merged 1 commit into from
Apr 28, 2025
Merged

Configure Gunicorn #18

merged 1 commit into from
Apr 28, 2025

Conversation

covracer
Copy link
Collaborator

@covracer covracer commented Apr 17, 2025

Background and Links

  • Gunicorn's default configuration
    • Makes searching for specific status codes hard
    • Doesn't surface the x-forwarded-for IP address, which is more likely to be the real client when load balancing is involved
    • Hides timed-out requests

Changes and Testing

  • Log in a abbr=value format that's easy to search while somewhat concise
  • Include some additional information
  • Try to log details of timed out requests

Questions and Followup

  • Better documentation of the log format
    • st STatus
    • lb Load Balancer IP address
    • ip x-forwarded-for IP address
    • rt Response Time
    • us USer
    • rf ReFerrer
  • Right now, us for USer is only populated for Basic Auth; putting the Cloudflare user there would be great (doing that efficiently might involve transitioning to REMOTE_USER)

@covracer covracer changed the title Gunicorn Configure Gunicorn Apr 17, 2025
@covracer covracer force-pushed the gunicorn branch 2 times, most recently from beaae66 to e6f57fe Compare April 26, 2025 12:20
@covracer covracer requested a review from Copilot April 26, 2025 12:21
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR configures Gunicorn for the project by updating dependency management, adjusting server configuration in manage.py and docker-compose, and adding custom logging and a new endpoint for simulating delayed responses.

  • Added Gunicorn dependency in pyproject.toml
  • Introduced gunicorn.conf.py with custom log formatting and request hooks
  • Updated manage.py and docker-compose to reference Gunicorn, and added a sleepy endpoint in views.py with a corresponding route in urls.py

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
pyproject.toml Added Gunicorn to project dependencies.
manage.py Updated port comment to mention gunicorn.conf.py for consistency.
gunicorn.conf.py Introduced custom log format and request lifecycle hooks, including a handler for timeouts.
docker-compose.yaml Changed command to run Gunicorn and updated port comments to align with configuration files.
demodj/views.py Added a sleepy_view to simulate delayed responses and updated the import for serializers.
demodj/urls.py Added a new URL route for the sleepy_view endpoint.
Comments suppressed due to low confidence (2)

demodj/views.py:7

  • [nitpick] Consider using a relative import (e.g. 'from .serializers import GroupSerializer, UserSerializer') for consistency within the package, unless the absolute import is intentional.
from demodj.serializers import GroupSerializer, UserSerializer

demodj/views.py:10

  • Consider adding tests for this new endpoint to ensure its behavior under simulated delay conditions.
def sleepy_view(request):

@covracer covracer merged commit a8f77db into main Apr 28, 2025
3 checks passed
@covracer covracer deleted the gunicorn branch April 28, 2025 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant