Skip to content

Commit

Permalink
Continue check execution when only a few hosts are unhealthy (#6954)
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianVeaux authored Jun 24, 2020
1 parent 07781dd commit c83b4c1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
7 changes: 6 additions & 1 deletion rabbitmq/datadog_checks/rabbitmq/rabbitmq.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,12 @@ def _check_aliveness(self, base_url, vhosts, custom_tags):
# We need to urlencode the vhost because it can be '/'.
path = u'aliveness-test/{}'.format(quote_plus(vhost))
aliveness_url = urljoin(base_url, path)
aliveness_response = self._get_data(aliveness_url)
aliveness_response = {}
try:
aliveness_response = self._get_data(aliveness_url)
except Exception as e:
self.log.debug("Couldn't get aliveness status from vhost, %s: %s", vhost, e)

message = u"Response from aliveness API: {}".format(aliveness_response)

if aliveness_response.get('status') == 'ok':
Expand Down
8 changes: 4 additions & 4 deletions rabbitmq/tests/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ def test__check_aliveness(check, aggregator):
check._get_data = mock.MagicMock()

# only one vhost should be OK
check._get_data.side_effect = [{"status": "ok"}, {}]
check._check_aliveness('', vhosts=['foo', 'bar'], custom_tags=[])
check._get_data.side_effect = [{"status": "ok"}, {}, {"status": "not_ok"}, Exception("foo")]
check._check_aliveness('', vhosts=['foo', 'bar', 'baz', 'xyz'], custom_tags=[])
sc = aggregator.service_checks('rabbitmq.aliveness')
assert len(sc) == 2
assert len(sc) == 4
aggregator.assert_service_check('rabbitmq.aliveness', status=RabbitMQ.OK)
aggregator.assert_service_check('rabbitmq.aliveness', status=RabbitMQ.CRITICAL)
aggregator.assert_service_check('rabbitmq.aliveness', status=RabbitMQ.CRITICAL, count=3)

# in case of connection errors, this check should stay silent
check._get_data.side_effect = RabbitMQException
Expand Down

0 comments on commit c83b4c1

Please sign in to comment.