Skip to content

Commit

Permalink
Adds a new 'ping' endpoint
Browse files Browse the repository at this point in the history
The endpoint simply returns the text 'pong' without running all of the checks.
  • Loading branch information
dhoffman34 committed Jan 5, 2018
1 parent cc3c180 commit 6844cd4
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 1 deletion.
1 change: 1 addition & 0 deletions .coverage.dhoffman.local.30529.701057
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!coverage.py: This is a private format, don't read it directly!{"lines":{"/Users/dhoffman/projects/django-watchman/watchman/__init__.py":[1],"/Users/dhoffman/projects/django-watchman/watchman/management/commands/__init__.py":[1],"/Users/dhoffman/projects/django-watchman/watchman/models.py":[1],"/Users/dhoffman/projects/django-watchman/watchman/settings.py":[1,4,5,7,8,9,10,11,12,13,15,16,21,24,27,30],"/Users/dhoffman/projects/django-watchman/watchman/urls.py":[11,9,10,3,5],"/Users/dhoffman/projects/django-watchman/watchman/decorators.py":[1,2,3,5,6,8,11,15,16,17,18,19,20,21,22,26,27,28,29,32,41,52,53,54,56,61,62,63,64,65,66,68,69,70,71,72,74,76,78,79,81,82,84,86,88,96,98,100,101,105,106],"/Users/dhoffman/projects/django-watchman/watchman/management/commands/watchman.py":[1,3,4,6,8,11,13,14,15,16,17,19,20,21,22,23,28,29,31,33,39,40,41,43,44,46,47,49,50,52,53,54,55,58,59],"/Users/dhoffman/projects/django-watchman/watchman/management/__init__.py":[1],"/Users/dhoffman/projects/django-watchman/watchman/utils.py":[3,4,6,49,8,9,43,46,40,50,52,53,54,55,57,58],"/Users/dhoffman/projects/django-watchman/watchman/checks.py":[3,5,6,7,8,9,11,12,13,16,17,20,22,23,25,27,28,29,30,33,34,37,39,40,43,45,46,47,48,49,50,51,52,54,55,58,60,61,62,63,64,65,66,69,70,73,74,77,81,82],"/Users/dhoffman/projects/django-watchman/watchman/views.py":[3,4,6,7,8,9,10,11,12,13,14,17,20,21,22,24,25,26,27,28,30,33,34,35,38,39,40,42,44,45,47,49,50,51,53,54,55,56,57,59,60,61,62,63,64,66,67,69,72,74,76,79,80,82,84,86,88,89,90,92,127,129,130,131,132,133,134,135,138,140,141,142,143,144,145,146,147,150,152,153,154,155,156,158,160,161,162,165,166]}}
1 change: 1 addition & 0 deletions .coverage.dhoffman.local.30543.335716
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!coverage.py: This is a private format, don't read it directly!{"lines":{"/Users/dhoffman/projects/django-watchman/watchman/__init__.py":[1],"/Users/dhoffman/projects/django-watchman/watchman/management/commands/__init__.py":[1],"/Users/dhoffman/projects/django-watchman/watchman/models.py":[1],"/Users/dhoffman/projects/django-watchman/watchman/settings.py":[1,4,5,7,8,9,10,11,12,13,15,16,21,24,27,30],"/Users/dhoffman/projects/django-watchman/watchman/urls.py":[11,9,10,3,5],"/Users/dhoffman/projects/django-watchman/watchman/decorators.py":[1,2,3,5,6,8,11,15,16,17,18,19,20,21,22,26,27,28,29,32,41,52,53,54,56,61,62,63,64,65,66,68,69,70,71,72,74,76,78,79,81,82,84,86,88,96,98,100,101,105,106],"/Users/dhoffman/projects/django-watchman/watchman/management/commands/watchman.py":[1,3,4,6,8,11,13,14,15,16,17,19,20,21,22,23,28,29,31,33,39,40,41,43,44,46,47,49,50,52,53,54,55,58,59],"/Users/dhoffman/projects/django-watchman/watchman/management/__init__.py":[1],"/Users/dhoffman/projects/django-watchman/watchman/utils.py":[3,4,6,49,8,9,43,46,40,50,52,53,54,55,57,58],"/Users/dhoffman/projects/django-watchman/watchman/checks.py":[3,5,6,7,8,9,11,12,13,16,17,20,22,23,25,27,28,29,30,33,34,37,39,40,43,45,46,47,48,49,50,51,52,54,55,58,60,61,62,63,64,65,66,69,70,73,74,77,81,82],"/Users/dhoffman/projects/django-watchman/watchman/views.py":[3,4,6,7,8,9,10,11,12,13,14,17,20,21,22,24,25,26,27,28,30,33,34,35,38,39,40,42,44,45,47,49,50,51,53,54,55,56,57,59,60,61,62,63,64,66,67,69,72,74,76,79,80,82,84,86,88,89,90,92,127,129,130,131,132,133,134,135,138,140,141,142,143,144,145,146,147,150,152,153,154,155,156,158,160,161,162,165,166]}}
1 change: 1 addition & 0 deletions .coverage.dhoffman.local.30562.163971
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!coverage.py: This is a private format, don't read it directly!{"lines":{"/Users/dhoffman/projects/django-watchman/watchman/__init__.py":[1],"/Users/dhoffman/projects/django-watchman/watchman/management/commands/__init__.py":[1],"/Users/dhoffman/projects/django-watchman/watchman/models.py":[1],"/Users/dhoffman/projects/django-watchman/watchman/settings.py":[1,4,5,7,8,9,10,11,12,13,15,16,21,24,27,30],"/Users/dhoffman/projects/django-watchman/watchman/urls.py":[11,9,10,3,5],"/Users/dhoffman/projects/django-watchman/watchman/decorators.py":[1,2,3,5,6,8,11,15,16,17,18,19,20,21,22,26,27,28,29,32,41,52,53,54,56,61,62,63,64,65,66,68,69,70,71,72,74,76,78,79,81,82,84,86,88,96,98,100,101,105,106],"/Users/dhoffman/projects/django-watchman/watchman/management/commands/watchman.py":[1,3,4,6,8,11,13,14,15,16,17,19,20,21,22,23,28,29,31,33,39,40,41,43,44,46,47,49,50,52,53,54,55,58,59],"/Users/dhoffman/projects/django-watchman/watchman/management/__init__.py":[1],"/Users/dhoffman/projects/django-watchman/watchman/utils.py":[3,4,6,49,8,9,43,46,40,50,52,53,54,55,57,58],"/Users/dhoffman/projects/django-watchman/watchman/checks.py":[3,5,6,7,8,9,11,12,13,16,17,20,22,23,25,27,28,29,30,33,34,37,39,40,43,45,46,47,48,49,50,51,52,54,55,58,60,61,62,63,64,65,66,69,70,73,74,77,81,82],"/Users/dhoffman/projects/django-watchman/watchman/views.py":[3,4,6,7,8,9,10,11,12,13,14,17,20,21,22,24,25,26,27,28,30,33,34,35,38,39,40,42,44,45,47,49,50,51,53,54,55,56,57,59,60,61,62,63,64,66,67,69,72,74,76,79,80,82,84,86,88,89,90,92,127,129,130,131,132,133,134,135,138,140,141,142,143,144,145,146,147,150,152,153,154,155,156,158,160,161,162,165,166]}}
1 change: 1 addition & 0 deletions .coverage.dhoffman.local.30602.305476
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!coverage.py: This is a private format, don't read it directly!{"lines":{"/Users/dhoffman/projects/django-watchman/watchman/management/commands/watchman.py":[1,3,4,6,8,11,13,14,15,16,17,19,20,21,22,23,28,29,31,33,39,40,41,43,44,46,47,49,50,52,53,54,55,58,59],"/Users/dhoffman/projects/django-watchman/watchman/views.py":[3,4,6,7,8,9,10,11,12,13,14,17,20,21,22,24,25,26,27,28,30,33,34,35,38,39,40,42,44,45,47,49,50,51,53,54,55,56,57,59,60,61,62,63,64,66,67,69,72,74,76,79,80,82,84,86,88,89,90,92,127,129,130,131,132,133,134,135,138,140,141,142,143,144,145,146,147,150,152,153,154,155,156,158,160,161,162,165,166],"/Users/dhoffman/projects/django-watchman/watchman/checks.py":[3,5,6,7,8,9,11,12,13,16,17,20,22,23,25,27,28,29,30,33,34,37,39,40,43,45,46,47,48,49,50,51,52,54,55,58,60,61,62,63,64,65,66,69,70,73,74,77,81,82],"/Users/dhoffman/projects/django-watchman/watchman/utils.py":[3,4,6,49,8,9,43,46,40,50,52,53,54,55,57,58],"/Users/dhoffman/projects/django-watchman/watchman/__init__.py":[1],"/Users/dhoffman/projects/django-watchman/watchman/decorators.py":[1,2,3,5,6,8,11,15,16,17,18,19,20,21,22,26,27,28,29,32,41,52,53,54,56,61,62,63,64,65,66,68,69,70,71,72,74,76,78,79,81,82,84,86,88,96,98,100,101,105,106],"/Users/dhoffman/projects/django-watchman/watchman/urls.py":[11,9,10,3,5],"/Users/dhoffman/projects/django-watchman/watchman/settings.py":[1,4,5,7,8,9,10,11,12,13,15,16,21,24,27,30],"/Users/dhoffman/projects/django-watchman/watchman/management/commands/__init__.py":[1],"/Users/dhoffman/projects/django-watchman/watchman/models.py":[1],"/Users/dhoffman/projects/django-watchman/watchman/management/__init__.py":[1]}}
1 change: 1 addition & 0 deletions .coverage.dhoffman.local.30617.388925
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!coverage.py: This is a private format, don't read it directly!{"lines":{"/Users/dhoffman/projects/django-watchman/watchman/management/commands/watchman.py":[1,3,4,6,8,11,13,14,15,16,17,19,20,21,22,23,28,29,31,33,39,40,41,43,44,46,47,49,50,52,53,54,55,58,59],"/Users/dhoffman/projects/django-watchman/watchman/views.py":[3,4,6,7,8,9,10,11,12,13,14,17,20,21,22,24,25,26,27,28,30,33,34,35,38,39,40,42,44,45,47,49,50,51,53,54,55,56,57,59,60,61,62,63,64,66,67,69,72,74,76,79,80,82,84,86,88,89,90,92,127,129,130,131,132,133,134,135,138,140,141,142,143,144,145,146,147,150,152,153,154,155,156,158,160,161,162,165,166],"/Users/dhoffman/projects/django-watchman/watchman/checks.py":[3,5,6,7,8,9,11,12,13,16,17,20,22,23,25,27,28,29,30,33,34,37,39,40,43,45,46,47,48,49,50,51,52,54,55,58,60,61,62,63,64,65,66,69,70,73,74,77,81,82],"/Users/dhoffman/projects/django-watchman/watchman/utils.py":[3,4,6,49,8,9,43,46,40,50,52,53,54,55,57,58],"/Users/dhoffman/projects/django-watchman/watchman/__init__.py":[1],"/Users/dhoffman/projects/django-watchman/watchman/decorators.py":[1,2,3,5,6,8,11,15,16,17,18,19,20,21,22,26,27,28,29,32,41,52,53,54,56,61,62,63,64,65,66,68,69,70,71,72,74,76,78,79,81,82,84,86,88,96,98,100,101,105,106],"/Users/dhoffman/projects/django-watchman/watchman/urls.py":[11,9,10,3,5],"/Users/dhoffman/projects/django-watchman/watchman/settings.py":[1,4,5,7,8,9,10,11,12,13,15,16,21,24,27,30],"/Users/dhoffman/projects/django-watchman/watchman/management/commands/__init__.py":[1],"/Users/dhoffman/projects/django-watchman/watchman/models.py":[1],"/Users/dhoffman/projects/django-watchman/watchman/management/__init__.py":[1]}}
11 changes: 11 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,17 @@ watchman may open too many connections as it checks each database or cache.
You can set the ``WATCHMAN_DATABASES`` or ``WATCHMAN_CACHES`` settings in order
to override the default set of databases and caches to be monitored.

Ping
****

If you want to simply check that your application is running and able to handle
requests, you can call ping:

GET http://127.0.0.1:8000/watchman/ping/

It will return the text ``pong`` with a 200 status code. Calling this doesn't
run any of the checks.

Django management command
*************************

Expand Down
13 changes: 13 additions & 0 deletions tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,19 @@ def test_response_version_header(self):
self.assertTrue(response.has_header('X-Watchman-Version'))


class TestPing(unittest.TestCase):
def setUp(self):
# Ensure that every test executes with separate settings
reload_settings()

def test_returns_pong(self):
request = RequestFactory().get('/')
response = views.ping(request)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.content, 'pong')
self.assertEqual(response['Content-Type'], 'text/plain')


class TestEmailCheck(DjangoTestCase):
def setUp(self):
# Ensure that every test executes with separate settings
Expand Down
1 change: 1 addition & 0 deletions watchman/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
urlpatterns = [
url(r'^$', views.status, name="status"),
url(r'^dashboard/$', views.dashboard, name="dashboard"),
url(r'^ping/$', views.ping, name="ping"),
]
9 changes: 8 additions & 1 deletion watchman/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import warnings

from django.db.transaction import non_atomic_requests
from django.http import Http404
from django.http import Http404, HttpResponse
from django.shortcuts import render
from django.utils.translation import ugettext as _
from jsonview.decorators import json_view
Expand Down Expand Up @@ -69,6 +69,13 @@ def status(request):
return response, http_code, {WATCHMAN_VERSION_HEADER: __version__}


@non_atomic_requests
def ping(request):
_deprecation_warnings()

return HttpResponse('pong', content_type='text/plain')


@auth
@non_atomic_requests
def dashboard(request):
Expand Down

0 comments on commit 6844cd4

Please sign in to comment.