Skip to content

Commit

Permalink
Merge pull request #177 from praekeltfoundation/feature/fix-rabbitmq-…
Browse files Browse the repository at this point in the history
…health-check

Fix rabbitmq health check
  • Loading branch information
erikh360 committed Apr 17, 2020
2 parents c4e9912 + 7003e87 commit a271120
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ _trial_temp
.cache/
.coverage
ve/
.vscode
3 changes: 2 additions & 1 deletion junebug/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,8 @@ def return_queue_results(results):
'name': queue['name'],
'stuck': False,
'messages': queue.get('messages'),
'rate': queue['messages_details']['rate']
'rate':
queue['messages_stats']['ack_details']['rate']
}
if (details['messages'] > 0 and details['rate'] == 0):
stuck = True
Expand Down
24 changes: 10 additions & 14 deletions junebug/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def assert_response(self, response, code, description, result, ignore=[]):

self.assertEqual(data, {
'status': code,
'code': http.RESPONSES[code],
'code': http.RESPONSES.get(code, code),
'description': description,
'result': result,
})
Expand All @@ -88,12 +88,12 @@ def test_http_error(self):
resp = yield self.get('/foobar')
yield self.assert_response(
resp, http.NOT_FOUND,
'The requested URL was not found on the server. If you entered '
'The requested URL was not found on the server. If you entered '
'the URL manually please check your spelling and try again.', {
'errors': [{
'code': 404,
'message': ('404 Not Found: The requested URL was not '
'found on the server. If you entered the URL'
'found on the server. If you entered the URL'
' manually please check your spelling and try'
' again.'),
'type': 'Not Found',
Expand All @@ -103,20 +103,16 @@ def test_http_error(self):
@inlineCallbacks
def test_redirect_http_error(self):
resp = yield self.get('/channels')
[redirect] = resp.history()
yield self.assert_response(
redirect, http.MOVED_PERMANENTLY,
resp, 308,
None, {
'errors': [{
'code': 301,
'message': '301 Moved Permanently: None',
'code': 308,
'message': '308 Permanent Redirect: None',
'new_url': '%s/channels/' % self.url,
'type': 'Moved Permanently',
'type': 'Permanent Redirect',
}],
})
yield self.assert_response(
resp, http.OK,
'channels listed', [])

@inlineCallbacks
def test_invalid_json_handling(self):
Expand Down Expand Up @@ -1048,7 +1044,7 @@ def test_get_channels_health_check(self):
request_list.append(
((b'get', url, mock.ANY, mock.ANY, mock.ANY),
(http.OK, {b'Content-Type': b'application/json'},
b'{"messages": 1256, "messages_details": {"rate": 1.25}, "name": "%s"}' % queue_name))) # noqa
b'{"messages": 1256, "messages_stats": {"ack_details": {"rate": 1.25}}, "name": "%s"}' % queue_name))) # noqa

async_failures = []
sequence_stubs = RequestSequence(request_list, async_failures.append)
Expand Down Expand Up @@ -1112,7 +1108,7 @@ def test_get_channels_and_destinations_health_check(self):
request_list.append(
((b'get', url, mock.ANY, mock.ANY, mock.ANY),
(http.OK, {b'Content-Type': b'application/json'},
b'{"messages": 1256, "messages_details": {"rate": 1.25}, "name": "%s"}' % queue_name))) # noqa
b'{"messages": 1256, "messages_stats": {"ack_details": {"rate": 1.25}}, "name": "%s"}' % queue_name))) # noqa

response.append({
'messages': 1256,
Expand Down Expand Up @@ -1154,7 +1150,7 @@ def test_get_channels_health_check_stuck(self):
request_list.append(
((b'get', url, mock.ANY, mock.ANY, mock.ANY),
(http.OK, {b'Content-Type': b'application/json'},
b'{"messages": 1256, "messages_details": {"rate": 0}, "name": "%s"}' % queue_name))) # noqa
b'{"messages": 1256, "messages_stats": {"ack_details": {"rate": 0.0}}, "name": "%s"}' % queue_name))) # noqa

async_failures = []
sequence_stubs = RequestSequence(request_list, async_failures.append)
Expand Down
2 changes: 1 addition & 1 deletion junebug/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def response(req, description, data, code=http.OK):

return json.dumps({
'status': code,
'code': http.RESPONSES[code],
'code': http.RESPONSES.get(code, code),
'description': description,
'result': data,
}, cls=JSONMessageEncoder)
Expand Down

0 comments on commit a271120

Please sign in to comment.