Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-analytics-data-api
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-analytics-data-api
Commits
a7317a7d
Commit
a7317a7d
authored
Feb 18, 2015
by
Clinton Blackburn
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #59 from edx/health-page-fix
Returning HTTP 503 if service is unhealthy
parents
347cce51
c4765efa
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
8 deletions
+12
-8
analyticsdataserver/tests.py
+3
-3
analyticsdataserver/views.py
+9
-5
No files found.
analyticsdataserver/tests.py
View file @
a7317a7d
...
@@ -46,7 +46,7 @@ class OperationalEndpointsTest(TestCaseWithAuthentication):
...
@@ -46,7 +46,7 @@ class OperationalEndpointsTest(TestCaseWithAuthentication):
def
test_health
(
self
):
def
test_health
(
self
):
self
.
assert_database_health
(
'OK'
)
self
.
assert_database_health
(
'OK'
)
def
assert_database_health
(
self
,
status
):
def
assert_database_health
(
self
,
status
,
status_code
=
200
):
response
=
self
.
client
.
get
(
'/health'
,
follow
=
True
)
response
=
self
.
client
.
get
(
'/health'
,
follow
=
True
)
self
.
assertEquals
(
self
.
assertEquals
(
response
.
data
,
response
.
data
,
...
@@ -57,7 +57,7 @@ class OperationalEndpointsTest(TestCaseWithAuthentication):
...
@@ -57,7 +57,7 @@ class OperationalEndpointsTest(TestCaseWithAuthentication):
}
}
}
}
)
)
self
.
assertEquals
(
response
.
status_code
,
200
)
self
.
assertEquals
(
response
.
status_code
,
status_code
)
@staticmethod
@staticmethod
@contextmanager
@contextmanager
...
@@ -71,7 +71,7 @@ class OperationalEndpointsTest(TestCaseWithAuthentication):
...
@@ -71,7 +71,7 @@ class OperationalEndpointsTest(TestCaseWithAuthentication):
databases
[
'reporting'
]
=
{}
databases
[
'reporting'
]
=
{}
with
self
.
override_database_connections
(
databases
):
with
self
.
override_database_connections
(
databases
):
self
.
assert_database_health
(
'UNAVAILABLE'
)
self
.
assert_database_health
(
'UNAVAILABLE'
,
status_code
=
503
)
# Workaround to remove a setting from django settings. It has to be used in override_settings and then deleted.
# Workaround to remove a setting from django settings. It has to be used in override_settings and then deleted.
@override_settings
(
ANALYTICS_DATABASE
=
'reporting'
)
@override_settings
(
ANALYTICS_DATABASE
=
'reporting'
)
...
...
analyticsdataserver/views.py
View file @
a7317a7d
...
@@ -69,8 +69,11 @@ class HealthView(APIView):
...
@@ -69,8 +69,11 @@ class HealthView(APIView):
permission_classes
=
(
permissions
.
AllowAny
,)
permission_classes
=
(
permissions
.
AllowAny
,)
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
# pylint: disable=unused-argument
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
# pylint: disable=unused-argument
overall_status
=
'UNAVAILABLE'
OK
=
'OK'
db_conn_status
=
'UNAVAILABLE'
UNAVAILABLE
=
'UNAVAILABLE'
overall_status
=
UNAVAILABLE
db_conn_status
=
UNAVAILABLE
try
:
try
:
connection_name
=
getattr
(
settings
,
'ANALYTICS_DATABASE'
,
'default'
)
connection_name
=
getattr
(
settings
,
'ANALYTICS_DATABASE'
,
'default'
)
...
@@ -78,8 +81,9 @@ class HealthView(APIView):
...
@@ -78,8 +81,9 @@ class HealthView(APIView):
try
:
try
:
cursor
.
execute
(
"SELECT 1"
)
cursor
.
execute
(
"SELECT 1"
)
cursor
.
fetchone
()
cursor
.
fetchone
()
overall_status
=
'OK'
db_conn_status
=
'OK'
overall_status
=
OK
db_conn_status
=
OK
finally
:
finally
:
cursor
.
close
()
cursor
.
close
()
except
Exception
:
# pylint: disable=broad-except
except
Exception
:
# pylint: disable=broad-except
...
@@ -92,4 +96,4 @@ class HealthView(APIView):
...
@@ -92,4 +96,4 @@ class HealthView(APIView):
}
}
}
}
return
Response
(
response
)
return
Response
(
response
,
status
=
200
if
overall_status
==
OK
else
503
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment