Skip to content
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

Upgrade Middleware for Production #3131

Merged
merged 2 commits into from Jul 26, 2019
Merged

Upgrade Middleware for Production #3131

merged 2 commits into from Jul 26, 2019

Conversation

@rajadain
Copy link
Member

rajadain commented Jul 26, 2019

Overview

This was missed in 3a73743, and has caused Staging and Production deploys to fail. Also fixes the health-check endpoint which was failing.

Connects #3130

Demo

http://civicci01.internal.azavea.com/view/mmw/job/model-my-watershed-packer-app-and-worker/1165/console

and

> http --print HhBb :8000/health-check/
GET /health-check/ HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Host: localhost:8000
User-Agent: HTTPie/1.0.2



HTTP/1.1 200 OK
Connection: keep-alive
Content-Encoding: gzip
Content-Type: application/json
Date: Fri, 26 Jul 2019 18:19:44 GMT
Server: nginx
Transfer-Encoding: chunked
Vary: Accept-Encoding

{
    "caches": [
        {
            "default": {
                "ok": true
            }
        }
    ],
    "databases": [
        {
            "default": {
                "ok": true
            }
        }
    ]
}

Testing Instructions

  • Check out this branch
  • Go to :8000/health-check/
    • Ensure it works correctly
  • Go to :8000/health-check (no trailing slash)
    • Ensure you get a ConnectionError, indicating that the middlewares are being skipped correctly (otherwise there is one that appends the trailing slash)
This was missed in 3a73743, and has caused Staging
and Production deploys to fail.
@rajadain rajadain added the WPF label Jul 26, 2019
Copy link
Contributor

jwalgran left a comment

Looks good to me

This was updated for the new style middleware in 3a73743
but was not a complete migration. As of Django 1.10
django/django@05c888f, we need to use _get_response().
@rajadain rajadain force-pushed the tt/upgrade-django-followup branch from d5a02e2 to 7d2f25f Jul 26, 2019
@rajadain rajadain requested a review from rbreslow Jul 26, 2019
Copy link
Member

rbreslow left a comment

I get a 301 when I http --print HhBb :8000/health-check, but this looks good. 👍

@rajadain

This comment has been minimized.

Copy link
Member Author

rajadain commented Jul 26, 2019

Hmm, so do I actually. The 301 redirects to:

Location: http://localhost/health-check/

so it drops the port and adds a slash. I think that is happening because CommonMIddleware (which adds the trailing slash) preceeds BypassMiddleware, so that still runs.

# MIDDLEWARE CONFIGURATION
# See: https://docs.djangoproject.com/en/1.11/topics/http/middleware/
MIDDLEWARE = (
# Default Django middleware.
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
'mmw.middleware.BypassMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'apps.user.middleware.ItsiAuthenticationMiddleware',
)
# END MIDDLEWARE CONFIGURATION

But the health check is working correctly, which is the main issue. So I'll take that approval and run with it.

@rajadain rajadain merged commit 27da1c5 into develop Jul 26, 2019
2 checks passed
2 checks passed
default Build finished.
Details
model-my-watershed-pull-requests Build #4073 succeeded in 9 min 19 sec
Details
@rajadain rajadain deleted the tt/upgrade-django-followup branch Jul 26, 2019
@rajadain rajadain assigned rajadain and unassigned rbreslow Jul 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.